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.

Filter by
Sorted by
Tagged with
1
vote
1answer
11 views

Set CoC nodejs path dynamically

Currently for CoC I am setting the nodejs path like this: let g:coc_node_path = '/usr/local/.nvm/versions/node/v12.4.0/bin/node' But I want this variable to be set to the output of which node. How ...
0
votes
0answers
23 views

Lose hlsearch when using with vim-fuzzysearch

I'm using this plugin: vim-fuzzysearch. When I have long file (I need to press ctrl-f/ctrl-b to scroll) Steps to produces: 1. Turn on `hlsearch` + vim-fuzzysearch and search for a keyword 2. ...
0
votes
1answer
61 views

How can I decide whether a file can be opened in VIm or not?

I want to make a script with FZF (Fuzzy Finder) and I want to show only those file which can be opened with VIM. So, I don't want to list mp4, jpg, pdf etc files in FZF. So, is there any way to ...
2
votes
2answers
58 views

Do not delay mapped keys with common prefix

What I want to do is have two mappings. One mapped to <s-k>, and one mapped to <s-k><s-k>. What happens right now is that if I press <s-k> vim delays for timeoutlenms, and if ...
1
vote
1answer
25 views

How to turn on airline theme's background in vim?

I just started using vim and I installed tpope/vim-pathogen and then vim-airline/vim-airline-themes plugin to use these themes. Then I changed my .vimrc to set up the papercolor theme, powerline fonts ...
1
vote
1answer
30 views

Catch the “search hit BOTTOM, continuing at TOP” when cycle through the badly spelled words

Can anyone show me how to catch the last badly spelled word when vim says ...hit BOTTOM? I tried to do it like this: while 1 try " Jump to the next silent keepjumps normal! ]s ...
1
vote
2answers
88 views

Why does matchlist() return empty strings at the end of the result?

From the Vim's help: echo matchlist('acd', '\v(a)?(b)?(c)?(.*)') Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] I understand why the 3rd element is an empty string: 'b' is not present in ...
3
votes
1answer
16 views

Use mapped shortcut without timeout

I have these in my .vimrc: set notimeout nnoremap <leader>n :set rnu!<CR> nnoremap <leader>h :<C-u>call Toggle_colorcolumn()<CR> <leader>n works instantly; <...
0
votes
2answers
167 views

get string from cursor to end of <CWORD>

In vimL, how to get a string from cursor to end of <cWORD>. I know expand('<cWORD>', but don't known how to keep only right part of cursor. Example given text pre abc-xyz.xxx:123 post, ...
2
votes
1answer
52 views

Is it possible to set a timer task in vim7

As we know, we can set a highlight color while searching a keyword. I'm wondering if I can set a timer task to clear the highlight color after a few seconds. For now, I have to type :noh<CR> ...
0
votes
1answer
57 views

How do I tell vim to detect when a new file was created and do some action? [closed]

What I want to achieve is simply set up some auto command that will detect anytime I create a new file and based on the name of the file I want to insert a couple of lines of text in that file. So if ...
4
votes
3answers
229 views

Is it possible to create a snippet to “expand” struct members to fill?

In the type of c programming that I do day to day, I often have to "fill" struct members in order to pass them to an API. For example: struct measurement { double start_time; double end_time; double ...
2
votes
1answer
37 views

Expand `pwd` inside a vim command

I have a variable that I would set to the current result I get from :pwd. I tried the following, which obviously doesn't work: :let b:projectroot = expand("pwd") But this is essentially what I want ...
3
votes
2answers
62 views

`system()` can't get output of shell command in vimrc

I want to enable some configurations only when the distribution is Fedora. Here is my code. let s:os = system("sed -n 's/^NAME=\(.*\)/\1/p' /etc/os-release") echo s:os if s:os == "Fedora" " ...
1
vote
1answer
44 views

Binding toggle comment to <C-/>

I installed NERDCommenter plugin and its default bindings unfortunately conflict with my own. For instance I use <Leader>-c and <Leader>-v to emulate CTRL-c and CTRL-v. And since IDEs ...
1
vote
1answer
44 views

how do i open a new window with a new buffer, containing a variable?

I'm trying to write a plugin: I have a variable with some text. I want to: create a new buffer place the contents of that variable in the new buffer open a new split that displays the new buffer ...
0
votes
1answer
55 views

How to convert register contents to something readable similar to :register command?

Let's assume there is a macro stored in register 'r' I can obtain the contents of this register by executing getreg('r'), but if I print this then it can often be unreadable. I noticed though that ...
1
vote
1answer
31 views

Why does :! open -a terminal or :! start cmd create totally new “applications”?

Edit: on Windows, looks like it's opening in sysWOW64 instead of system32. Any ideas why? Title. Basically, both of these commands are supposed to open a new console, the former on my mac and the ...
2
votes
1answer
95 views

Making terminal buffer unlisted

I'm configuring my scripts to work with terminal in VIM and have a question regarding :h special-buffers. Among mentioned kinds there were the following: unlisted The buffer is not in the buffer ...
0
votes
3answers
49 views

“Hard-include” in vim script

I want to: let s:asciiart = ["", "", s:hardinclude(system("command params")), "", ""] where command returns one string with: "art-line-1", "art-line-2", "art-line-3" so I end up with: s:asciiart =...
2
votes
1answer
80 views

Custom command to go to file whose name matches the current word under cursor?

Let's say I'm editing this text in vim: People are helpful. and I am in normal mode, with my cursor currently on the h letter of the helpful word. How could I built a custom command that when run ...
0
votes
0answers
28 views

Vim terminal job prevents from exiting

I'm writing a function which is supposed to create a terminal buffer once for the entire Vim session and which would not prevent it from exiting. Here is how it looks like: let s:term_buf_nr = -1 ...
1
vote
3answers
82 views

Guard packadd to not load an optional non-existent package

I have an "optional" plugin that depends on python (pack/habamax/opt/myplugin) in my settings I have the following: if has('python') || has('python3') do some setup packadd myplugin endif ...
1
vote
2answers
41 views

Write buffer list to file

I would like to have a file that contains all files that I opened with vim in the past. I know that there is the viminfo file but I want to have just a file with the filenames. For this I would like ...
4
votes
1answer
236 views

tell vim to add default extention to word under my cursor before opening file

Lets say I have text This is result file output_20DeC. Let's say my cursor is on o. When I use the command gf, it should open output_20Dec.txt file. So how do I tell vim to add a default extension to ...
8
votes
1answer
3k views

What's the difference between `/x` and `:/x`

Assume buffer content: aa bb yy xx aa bb What's the different between /xx and :/xx?
2
votes
1answer
49 views

How to comment List item?

There are times I want to comment List items: let test_data = [ \ " description in comment \ complicated_data0 \ \ " description in comment \ complicated_data1 ... ...
1
vote
2answers
54 views

Make a buffer active by its number

I'm configuring a terminal buffer and now I have the following problem. I have only one terminal buffer and I need to make it active by its number to avoid lots of CTRL-w j/k/l clicks. Here is what ...
0
votes
1answer
44 views

function variable scoping and arg types problems

I'm trying to make a small extension/bug fix to a plugin I rely on (referenced as Plugin in the code snips), therefore I'm constrained by its existing API. I've got the functionality I want somewhat ...
3
votes
1answer
85 views

How to create command with -register and <reg>?

I have never used :h :command-register and :h <reg> , trying to find an example, but failed to grep \-register from my installed plugins, The built in :h :delete support a count and an optional ...
1
vote
1answer
47 views

Toggle terminal buffer vimscript function

I'm new to vimscript and writing a function to toggle a terminal buffer. Here is what I tried: let g:toggle_term = "<C-j>" let g:term_buf_nr = -1 function! ToggleTerminal() if g:...
0
votes
1answer
45 views

Can I use feedkeys() inside of a keyloop implemented by getchar()

I implemented a fuzzy filter, which accept a list argument, open a window with a scratch buffer whose content set to the list, then waiting for use input and do filtering. Here is why I ask this ...
4
votes
2answers
142 views

Is it necessary to always add ! to function and command

I can't remember start from when and why, i always add ! to function and command: function! .. ... endfunction command! ... But :h E122 says: When a function by this name already ...
1
vote
1answer
33 views

Autoreload vimrc when writing to vimscript files

I wanted to have my vimrc automatically update when I write to a .vim file using this autocmd: autocmd BufWritePost *.vim,$MYVIMRC source $MYVIMRC But for some reason when I have this enabled and ...
1
vote
2answers
48 views

Move cursor and screen together

I am implementing a smooth scrolling function for <C-u> and <C-d>, which just sleeps for a few milliseconds and then moves the screen up (<C-y>) or down (<C-e>) one line: ...
1
vote
2answers
223 views

How to insert text from a variable at current cursor position?

I am writing a vim script, and I need to insert the contents of a string variable at the current cursor position. What is an appropriate way to do this? let text = "Lorem ipsum sit dolor amet ..." " ...
2
votes
3answers
113 views

How can substitute() operate on a whole buffer?

In normal usage :%s/A/B/g is a simple way to substitute a pattern across the entire buffer. However the command mode implementation of :substitute is subject to many user configurable variables and as ...
3
votes
1answer
143 views

VimL/Vimscript: how to access local variable of outer function from its inner function?

I posted this question on stackoverflow already, but realized afterwards that it's probably better to ask here. So I have a function of the following form: function! s:my_function(dict_arg) let ...
1
vote
1answer
35 views

call omnicompletion from vimscript

I'd like to automatically call the omnicompletion (that is triggered manually by <Ctrl-X><Ctrl-O>) from within a vimscript function. I played around a bit with execute 'normal! …' and ...
1
vote
1answer
43 views

vim expression unusual behavior

While playing with map() I get an error, which I cannot understand. In essense, pu=map(getcompletion('*','event'), '"h" . v:val') pu=map(getcompletion('*','event'), "'h' . v:val") pu=map(...
0
votes
1answer
32 views

Make autocmd fire in a macro

These are the two lines of code responsible for inserting matching characters in my matching plugin let s:cur_split = [s:cur_split[0], s:match[press] . s:cur_split[1]] cal setline(".", join(s:...
0
votes
2answers
41 views

Get number of commas in a line using Vimscript

This question may have an obvious answer that I'm missing, but how can I easily tell how many of a character, in this case " , " are in a line, or a specified string using vimscript?
0
votes
0answers
49 views

Send keystrokes and string to gdb terminal

I started debugging a c program inside vim with: :packadd termdebug :Termdebug with vim 8 and and gdb > 8.3 installed. In order to set a breakpoint, I would like to send the following string while ...
0
votes
0answers
47 views

Find out last used text object

I'm trying to figure out a way to make a repeatable operator insert. To do so I'm trying to make use of tpope/repeat. My idea is to set a repeatable call that repeats the last operation, repeating the ...
0
votes
0answers
40 views

Is there a SafeState equivalent in neovim?

I have the following function that I'm porting to neovim: " --------------- " Auto record visual mode " --------------- " Allows executing operators with a different syntax. " First we go to visual ...
2
votes
0answers
94 views

What happens when error occurs during cdo?

:h :cdo says: When an error is detected execution stops. The last buffer (or where an error occurred) becomes the current buffer. Let's see what really happens: ...
1
vote
1answer
84 views

Detect that user pressed ESC in getchar()

It looks like quite a simple question, but I cannot find an answer. Is there a way to detect that the user pressed ESC key while waiting for user input in vimscript? I would like an intuitive way to ...
0
votes
3answers
85 views

Redirect output of vim command to external program

I would like to filter the output of vim commands with fzf. The idea is for example, if I use vim unimpaired plugin and I don't exactly remember which map was to navigate to the next git conflict but ...
0
votes
2answers
61 views

Is it possible to reverse an existing highlighting group?

Is it possible to automatically create a highlight which is the reverse of an existing highlight? Example highlight Search guifg=Black guibg=Yellow, becomes highlight CustomHighlight guifg=Yellow ...
3
votes
2answers
273 views

What is the proper way to allow the user of a plugin to modify settings?

So I have a plugin that I am writing which should allow the user to set whether they want to enable a feature. I want the feature to be disabled by default, and allow the user to change it by adding ...