Questions tagged [vimscript]
A scripting language embedded into Vim. It can be used to customize Vim to suit your needs and to create plugins. Also called VimL.
1,618 questions
1
vote
0
answers
21
views
List channels / handles
Is there a way to get a list of channels (channel/handle)?
For jobs one can use job_info() without argument to list all, but can not find a way to get a lost handle for channels.
1
vote
2
answers
65
views
Syntax Highlighting - highlight command not working as expected
I created a new custom file type called foo:
$ cat ~/.vim/ftdetect/foo.vim
au BufRead,BufNewFile *.foo set filetype=foo
I created a new syntax group:
$ cat ~/.vim/after/syntax/foo.vim
syntax keyword ...
1
vote
1
answer
105
views
Change settings when using vimdiff
I have a function that changes settings for diff mode (usually activated by using vimdiff).
Manually calling this function works as expected.
However, I would like this function to be called ...
2
votes
2
answers
115
views
Replace the text between several boundary symbols
Suppose, we have the text inside the default register:
": new_name
And we have the following Perl code in the buffer:
$hash{old_name} = "value";
▲
cursor position
I ...
0
votes
2
answers
74
views
Grep for a word at the point without defining a function
This code is intended to be portable between Vim and Neovim.
In cases where I don't have a LSP configured, I like to use the following to grep for a word.
This thing is also a working vimrc or init....
1
vote
1
answer
160
views
How to convert autocmd VimLeave from VimScript to lua?
I have a file that is in mail.vim and has the following executable commands:
augroup autocom
autocmd!
"executes the command on quit
"autocmd VimLeave /tmp/mutt-* !/usr/bin/email-...
0
votes
1
answer
55
views
Plugin-scoped Constants/Variables
I'm running Neovim on Windows, and I'm trying to use what I call "autoload variables" to implement a plugin-scoped constant for my plugin. Having read :help autoload, I think I've found the ...
0
votes
3
answers
61
views
Can a Vim syntax file choose a colorscheme?
So a new Vim syntax file was created and placed into ~/.vim/syntax directory.
An accompanied Vim colors file was created and placed into ~/.vim/colors directory.
What's the best way for the syntax ...
2
votes
1
answer
228
views
Using a lambda inside foreach()
I can use the foreach() function with a string, like so:
:call foreach([37,73], 'echo v:val')
37
73
or with a Funcref:
function Foobar(key,val)
echo a:val
endfunction
:call foreach([37,73], ...
0
votes
2
answers
114
views
How can I substitute over visual selection in script?
I have a script.vim file in which I'm trying to replace certain string matches.
E.g. I have in .html file a number of lines like:
<a
href="foundry-illustration/foundry-illustration.html"&...
0
votes
1
answer
79
views
Usual navigation motions in a popup window?
I'd like to write a file-tree/file-browsing plugin that uses popup windows.
In popup_create I can set a filter to capture keys. For instance,
popup_create('hello world', {filter: 'popup_filter_menu'})
...
0
votes
1
answer
80
views
How to convert vimscript to Neovim Lua with help of spliting line key and function?
How to convert this vimscript code into Lazyvim Lua code?
function! BreakHere()
s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6
call histdel("/", -1)
...
1
vote
1
answer
74
views
How to auto-complete the different command with multiple options from dict?
I am trying to achieve a function that can auto-complete the command with options in dict.
For example: there's two commands
create_clock and set_voltage, two options -wave and -period with ...
1
vote
2
answers
96
views
How can I test the result of execute saveas?
I have a function that renames a file by saving it to the new location then deleting the old:
execute "saveas" fnameescape(l:new_path)
call delete(l:old_path)
I ran into a problem with this ...
0
votes
2
answers
129
views
I can't get rid off ^M with a custom function for putting in WSL
I am trying to write a function for putting copied text from Windows to WSL, but in-spite of my attempts, I cannot get rid of the ^M.
Here is my attempt:
vim9script
def WslPut(above: bool = false)...
1
vote
2
answers
139
views
How to add a third argument to a popup_menu() callback function?
So far, I know that you can pass only two arguments to popup callback functions. I am wondering if there is any way to pass a third argument? Shall I rely on some sort of closure or use some "...
0
votes
3
answers
143
views
Multiple nesting in syntax highlighting
I've got a EBNF that needs to be Vim-syntaxed:
header :== 'header' ( '{' 'header1' ( '{ 'header2' nest_3? 'trailer2' '}' )? 'trailer1' '}' )? 'trailer'
Railroad diagram gets me:
And I'm struggling ...
0
votes
1
answer
52
views
Is it possible to redirect the content of a wildmenu to a variable?
Say that I type :cd <tab>. I get displayed a menu with all the directories in pwd. I am wondering if I can store the content of such a menu into a variable.
For example, if :cd <tab> ...
0
votes
0
answers
54
views
How to bind [limit] textyankpost to '*' special register [clipboard]
I've tried a lot of things, but basically event.regname is `` for "*y
autocmd textyankpost *
if v:event.regname =~ '[8+*]'
call system('win32yank.exe -i --crlf', @")
endif
In ...
-1
votes
2
answers
94
views
How to insert multiple lines from function?
From https://vi.stackexchange.com/a/28026/47188 I know that by defining in vimrc:
" Insert text at the current cursor position.
function! InsertText(text)
let cur_line_num = line('.')
let ...
1
vote
3
answers
81
views
How to get the last non-blank line of a terminal buffer running a specific program?
As per text. I have a terminal buffer running ipython and I want capture the last non-blank line.
I tried the following:
var bufnr = bufnr('IPYTHON')
term_getline(bufnr, line('$'))
term_getline(bufnr, ...
0
votes
3
answers
399
views
Recommended way of scripting: Ex commands or vimscript functions?
While scripting I could achieve the same result both through Ex commands and vimscript functions, for example:
var filename = "foo.txt"
exe "new" filename # Ex ...
2
votes
0
answers
69
views
Modify ALE coloring for style errors
I am using neovim with ALE and I want to change the coloring of style errors in general for any language and particularly in python using flake8, in the following code of my configuration file I try ...
0
votes
0
answers
41
views
Is there an equivalent of system() for capturing commands outputs or programs running in terminal buffers?
I am aware that system() capture the output of shell commands.
I am wondering if there is a similar command for capturing the output of commands sent to other type of interpreters running in terminal ...
1
vote
1
answer
108
views
How to make an user-defined command that is repeatable with . operator
I've been trying to make a dot-repeatable (.) command that should work in both visual and normal mode. The command in question searches for a [] on a line and turns it into a [x], and vise versa.
It ...