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
25 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
0answers
26 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 ...
3
votes
2answers
101 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
24 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
27 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
158 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
89 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
62 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
25 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
34 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
26 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
34 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
34 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
36 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 ...
1
vote
0answers
72 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
38 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
62 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
47 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
266 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 ...
0
votes
1answer
22 views

Why doesn't i<Ctrl-R>=expandcmd('se shm') work?

I'm trying to do i<Ctrl-R>=expandcmd('se shm') and more generally i<Ctrl-R>=expandcmd({expr}) but I'm just getting the literal {expr} inserted. When I type :se shm<CR> I get the ...
0
votes
0answers
27 views

Neovim highlight syntax region inside typescript tagged template literal

I am having trouble fixing a syntax plugin for Vim. I've found a bug in a plugin that has not been touched in a fair amount of time. I want to address it myself but I believe I am lacking in a lot of ...
0
votes
0answers
15 views

Spell check operator

Is there a way to run the spell checking for a single text object instead of the entire file? I would like to do something like: gsip (go spell in paragraph) I've found a gammar check operator: ...
0
votes
1answer
21 views

Calling a function when timeoutlen expires and retrieving the input command

This might be quite challenging, but I would like to achieve the following behavior. Imagine that I have two mappings that overlap: dcb := delete comment block := delete comment block (all adjacent ...
0
votes
1answer
14 views

How to fix incorrect highlighting from 'matchpairs' caused by setline()

when using setline() to insert brackets, matchpairs does not do its job correctly. Using these commands fu Test() cal setline(".", "()") endf au TextChangedI * cal Test() set up the text ( ) ...
1
vote
1answer
27 views

Calling g@ from a a vimscript function

I want to call g@ from a function. Given an operation: " Taken from :help g@ function! CountSpaces(type, ...) let sel_save = &selection let &selection = "inclusive" let reg_save = @@ ...
1
vote
1answer
25 views

Error With Simple Function Using setline()

I'm trying to start writing some Vim Script, and I've come across this issue. fu Test() call setline(1, getline(".")) endf autocmd InsertCharPre * call Test() This is in my .vimrc. When I type ...
1
vote
2answers
69 views

Send keys to a terminal buffer

I want to map a keyboard shortcut to execute the last command in a terminal buffer that I have open. I've made some progress: I am storing the buffer's channel id correctly but when I try to send ...
1
vote
0answers
35 views

How to use actual window size to control vim settings?

Background: neovim with tagbar plugin installed Goal: when starting nvim, if current window size is larger than 100, open tagbar and set auto-open for new buffers. Currently I use the settings below ...
0
votes
1answer
79 views

How to automatically execute a command every time visual mode is entered and every time normal mode is entered

I would like to execute a command every single time I enter visual mode and another command every time I leave visual mode. Is there a way to achieve this? My objective is to automatically record ...
0
votes
0answers
35 views

Is it possible to replace tildes representing empty lines with another character?

I'm writing a plugin which needs to replace the empty line tildes with with a '.' character in a single window split. Is this possible to do with Vimscript?
2
votes
2answers
37 views

Two consecutive identical calls to echo have different output

Question reposted on StackOverflow, where it's receiving more attention. Given the following function in the .vimrc file, fu! MyFun(count) echo a:count echo a:count if a:count > 0 ...
1
vote
1answer
32 views

vim8 - why does my 0read not read? [closed]

I have the following function in an autoload file: function! closet#FindSkeletonForFile() if exists('b:closet_skeleton') return 0 endif let b:closet_skeleton = s:closet....
10
votes
2answers
2k views

What does `idem` mean in the VIM docs?

One example would be in the List docs: :unlet list[3] "idem
1
vote
1answer
19 views

How to get a function to print something to colon command and let user edit it?

I need to write a function that when executed it opens colon command and paste some stuff on to it and let user edit it before executing the command. for example function! EditRelativePath() :e ...
2
votes
1answer
35 views

Standard way to implement a :tselect-like menu?

In the context of developing a plug-in, what is the most portable (various versions of vim, nvim, ...) and readable way to implement a "menu" similar to what :tselect gives i.e. that appears in the ...
1
vote
2answers
54 views

Toggle between two most recent syntax highlighting settings

I often nest one programming language within another (e.g. HTML inside python). This can be done per-language, and written items in ~/.vim/after/syntax/ for that purpose, but I don't have the patience ...
3
votes
2answers
407 views

Vimscript - Surround word under cursor with quotes

I'm writing a Vim plugin which will need to surround the word directly under your cursor with a quotes. I have tried using simple solutions which use commands like "b" and "e" executed in normal mode, ...
1
vote
1answer
47 views

Get the length/number of colums in the current line/row

How can I get the length of the current row in vim script?
1
vote
0answers
34 views

How to set the language for the user interface using vimscript?

I know I can change the language of the Vim user interface using :language en_US.UTF-8, but how can I do that using vimscript? set language=en_US.UTF-8 is invalid, and the Vim documentation says that ...
3
votes
1answer
27 views

Record all line-number fold-levels and restore fold-states (despite fold-level change)

I have found myself so extraordinarily frustrated with Vim's foldmethod=syntax behavior that I've contemplated dropping the editor entirely, despite being mostly happy with it for a few years now. ...
1
vote
1answer
28 views

Find the location of a directory at runtime to provide a default directory

I want to move some scripts that I have made to some sort of standalone plugin. The content would look like myplug/ plugin/ mydefaultdir/ For the scripts, I require a set of files which could ...
1
vote
2answers
71 views

Insert text in the middle of a string vimscript

I'm trying to make a function in vimscript that converts markdown to html files using pandoc and putting that converted file in a specified directory. Currently i am putting the file in a directory ...
2
votes
2answers
90 views

How to get line numbers of a different window

I would like to get these line numbers of a different window without moving to that window. line('w0') line('w$') line('.') line('$') As for the first two, we can use getwininfo([{winid}]) which ...
3
votes
1answer
58 views

What is the #{} syntax in Vim?

I just noticed this in a Vim help page: popup_beval(s:balloonText, #{mousemoved: 'word'}) What is the #{mousemoved: 'word'}? It looks like a dict? I tried using :help #{, but that doesn't show any ...
9
votes
1answer
1k views

How can I merge two dictionaries in Vim?

I have two dicts: :let defaults = {'hello': 'world', 'bye': 'jupiter'} :let override = {'hello': 'mars'} How can I merge the keys from override so that I end up with a new dict like so: {'hello': '...
1
vote
2answers
376 views

How to delete a line from a variable?

Inside a function, saved multiple lines of external command output to a variable. How to delete a line from the variable? Like first line. I can run let tmp = split(variable, "\n") to assign the ...
2
votes
0answers
17 views

How to identify the last DiffUpdated event?

The DiffUpdated event has been added in patch-8.1.0397. Sometimes the event occurs a few times in a session. For example, when 2 files are opened in diff mode, ":e!" generates the event 3 times. As ...
1
vote
2answers
39 views

remove extra (^@) from visual selection

I'm writing a function to execute an external command using visual selection. I've noticed that if by mistake the entire line is selected, including the new line char the extra ^@ character makes the ...
1
vote
1answer
42 views

di in vim/fortran

I have tried without any luck, but can anyone kindly let me know if di is possible for language like vim/fortran which has structure like do loop Something end do UPDATE: command di', di"...