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
97 views

Auto pairing using strings instead of characters

I'm already aware of existing solution to automatically "surround" sentences/word/etc (eg: auto-surround, vim-surround, etc) but those (as far as i know) don't support using normal strings ...
0
votes
0answers
27 views

Chronologically store visual selections in a buffer

My goal is to enhance the usage of gv with counts, in order to access older selections quickly. Such that 2gv would reselect the selection made before the last. Vim doesn't have events for entering ...
2
votes
1answer
38 views

Passing arguments function with --argument or -a format

Is it possible to pass arguments to Vimscript functions with the --argument or -a format, similar to arguments in the command line? I am writing a command that submits a job in a remote machine. I ...
0
votes
0answers
25 views

Measurement/ tracking the time for editing a file (overall and statistics)

I use vim for coding and also for writing scientific articles and book chapters. It would be very interesting to know the time I spent on a file. For example how many hours or minutes the buffer was ...
0
votes
1answer
25 views

How to detect the change that from insert mode to normal mode, so I can implement Auto-Save?

I want to do the following: autocmd changeFromItoN * if &readonly == 0 && filereadable(bufname('%')) \ | silent update | endif That is: I want to implement the ...
0
votes
0answers
16 views

Open file in new tab or split if current file has changes in fzf.vim

I have been using :Files to get a list of files using fzf.vim. Although whenever I hit enter to open a new file and the current file has not been saved I get an error message saying No write since ...
0
votes
1answer
33 views

Remove text specifying mode “INSERT” in bottom vim line

In the bottom two lines, you'll see the statusline saying "INSERT", and the line where you enter commands showing -- INSERT -- This is quite redundant, and I would like any recommendations ...
0
votes
1answer
13 views

how to autocmd BufWritePost stdout to tidy upon :w?

tldr; How do pass stdout of BufWritePost to an external command? On command line I can run cat index.html | tidy -indent -modify I'm trying to call tidy automatically when I :w This is what I have so ...
0
votes
1answer
22 views

how vi automatically collapses {}

I always come across a lot of code wrapped in {}s while reading, and I wondered if there was a way for vi to automatically fold these {}s instead of manually marking them.
0
votes
0answers
25 views

Let .js files be recognized as .jsx files?

I just figured out how to combine those creepy plugins to work together to achieve the following auto-indent: before / after pressing o: But then this only works on file extension .jsx as shown above,...
-1
votes
1answer
26 views

How to detect whether the current line is empty line?

I want to detect whether the current line my current on is only composed of non-visible characters, and return true of false, and use this check to trigger some nnoremap mapping, how?
0
votes
1answer
50 views

Is it possible to dynamically set the `let var=“string”`? [closed]

I'm playing around with my .vimrc as usual. I have a colorscheme which displays differently with let ayucolor="dark" let ayucolor="mirage" let ayucolor="light" I'm ...
0
votes
1answer
47 views

How to temporarily change file encoding?

I'm using a plugin which can show the minimap for the file I'm editing. The plugin can only works with utf-8, while, my mother tongue is Chinese so I wrote comment in Chinese. Does anyone know how to ...
2
votes
1answer
48 views

How do I work with vim9 and unicode?

I've found myself in a bit of an interesting situation. I'm writing a plugin in which I need to do a tiny bit of line parsing. Given a file: æøå It's easy to verify that col('.') returns 1, 3, and 5 ...
0
votes
1answer
20 views

How to suppress error message of autocmd command when the `silent` doesn't work?

I'm using Coc.vim and I've created an issue on their GitHub, but I'm not sure about whether this can be done by modifying the line I'm using: autocmd CursorHold * silent call CocActionAsync('doHover') ...
0
votes
1answer
25 views

How to run additional command in nnoremap?

I have the following lines in my .vimrc: nnoremap <nowait><silent> ¡ :colorscheme tokyonight<CR> nnoremap <nowait><silent> ™ :colorscheme tone<CR> nnoremap <...
0
votes
1answer
40 views

Useful script to manage buffer and window?

Given the scenario: I want to create a vertical split from current buffer for reference another file/the same file. After I've done with this split I don't want to see this buffer-for-reference in ...
0
votes
1answer
25 views

Using a multiline closure to execute commands in vimscript

I'm writing a script in which I am in need of closure functionalities. Take this function, for instance: func! SetOpNorm(norm_comm, motion_key = 'y') let l:norm_comm = a:norm_comm let l:...
1
vote
1answer
34 views

How to search for vue components with vim's gf?

I want to go to a vue component file. Vue component filenames are written in PascalCase: ExampleComponent.vue In html (or in my case blade.php) the ExampleComponent.vue is instantiated by <example-...
0
votes
1answer
35 views

How to get the buffer type of the current buffer?

I'm writing mapping, and I want to decide whether I have to do additional actions when current buffer type is a drawer called Fern, here is my command currently nnoremap <nowait><silent> ; ...
0
votes
1answer
22 views

How to run internal (Neo)Vim “:Command” from external Terminal?

I'm using MacOSX, and I have script on Terminal, and since I will probably forget how to update everything inside Vim/NeoVim, is it possible to pass command, e.g. :PlugUpdate, to nvim/vim so that I ...
0
votes
1answer
23 views

pylint default filepath in ALE

I am trying to set up my pylintrc file in vim, but am having some difficulty getting it to read from the correct path. It seems to work when I have the file in the directory that contains the vim file ...
0
votes
1answer
17 views

Get path to parent directory and use it in a nnoremap command?

Say I have a nnoremap and I want to pass the path of parent directory of current file to it, so the command can use this information. I have read this answer: How can I see the full path of the ...
0
votes
1answer
37 views

How to inverse boolean in Vimscript?

I have the following script but not working: I don't know what's the standard way to inverse the boolean(I used number 1/0). I not sure whether it's correct to put global variable, which I used to ...
0
votes
1answer
28 views

Map to a key to do nothing?

I'm tuning :sp, :vsp things, and for example I have: nnoremap <nowait> <C-L> <C-W><C-L> nnoremap <nowait> <C-W><C-L> :vsp<CR><C-W><C-L> ...
0
votes
1answer
16 views

Waiting for a copy event

I have the following function: function _X() normal! gvy vs tmp normal!p ALEFix black normal! ggVG normal! y <------- endfunc Unfortunately, the y does not work. That is, ...
0
votes
1answer
29 views

ALE Fix for a visual selection

I am figuring out a way to apply linting to a visual selection of code. For example: I only want to lint run :ALEFix on that section of code, and not the 100s (or 1000s) of lines of other code in the ...
1
vote
2answers
233 views

VimScript: Is it possible to reduce a list into a dictionary like in JS?

I've tried this but it didn't work function! Reduce(array, oper, accumInit) abort let l:accum = a:accumInit for l:item in a:array let l:accum = a:oper(l:accum, l:item) endfor return l:...
1
vote
2answers
31 views

How to check last char is { in vimscript?

I want to create a {} completion myself, and I did: inoremap <CR> if_open_curly_on_left()? <CR>}<ESC>O : <CR> function! s:if_open_curly_on_left() abort let col = col('.') - ...
0
votes
0answers
47 views

How to run vimscript function on visually selected lines of text?

I'm editing DocBook XML files and sometimes I need to format the using an external xmlformat command. it is easy to run do this on the whole buffer of text, but how can i achieve the same only for a ...
0
votes
1answer
24 views

How to use tab for indent in indent function while expand tab was set?

When expandtab is set, how to let the indent function defined in file vim/indent/xxx.vim use tabs, rather than spaces to indent lines? Edit: Here is the background. I have use vim's built-in CHANGELOG ...
2
votes
1answer
35 views

How to use func to quickly add specific comments to certain lines of a file?

I wrote a function, the function is used to add comments to some lines, the content is as follows: func Add(x) call setline(a:x+1, "\ //*********************************************************...
1
vote
1answer
31 views

Selecting a region with vimscript

This is a follow-up to Understanding a vimscript function The file format is: Theorem ∀ P. P ==> P Proof rw [] \\ metis [] I modified that vimscript function: fu! HOLSelectTactic() let ...
1
vote
1answer
25 views

Understanding a vimscript function

I have the following function in a vim plugin: fu! HOLSelect(l,r) let l:cursor = getpos(".") if search(a:l,"Wbc") == 0 return endif normal v if search(a:r,"W&...
1
vote
1answer
86 views

Understanding a command definition

I have the following line in a vim plugin: nn <silent> <LocalLeader>E :call HOLSelectTactic()<CR>-Vo+ :help helped me in understanding lots of details, I list them to check if they ...
0
votes
1answer
29 views

How do I open a relative path under the cursor

I often have file log where there are several relative path to files. The paths are relative to the location of the filelog. My understanding is that I'm able to open the relative path if the CWD of ...
2
votes
1answer
33 views

How to get the list of modified lines in the buffer?

Is there a n[vim] function to get the list of modified lines? A clunky way is to parse the output of :changes but I only require the changes since last write. I have to use it in a python-based plugin....
1
vote
1answer
31 views

How do you explicitly throw an error?

There are several wordings for this depending on what programming languages you are used to, but none of them turned up results for me. Also, neither help abort() nor help raise() nor help throw() ...
0
votes
3answers
44 views

How to filter without destroying original list?

I have a list of strings which is interesting in its own right, but I also want a filtered version of it for other purposes. But I discovered to my horror that filter, in addition to returning a ...
1
vote
1answer
56 views

Is there a way to use matchadd() to highlight multiple lines without highlighting newlines?

Suppose I have this in a text buffer (vim --clean mydoc.txt): One Two Three Four I highlight all lines using :call matchadd('ErrorMsg', '.*'), resulting in: Notice that the newline character on each ...
0
votes
0answers
120 views

Vim-Airline TabLine not displaying with arrows

I have set up Vim-Airline, but Vim-Airline-Tabline's tab seperator is showing vertically rather than as arrows. My tabline: Expected tabline: init.vim relating to airline: let g:...
3
votes
3answers
390 views

What does the 'z' flag for search() do?

I was looking at the documentation for search() (:help search()). I noticed that there is a "z" flag: 'z'    start searching at the cursor column instead of zero When the 'z' flag is not ...
0
votes
1answer
40 views

VIM: How to call a vimscript function after press a shortcut or execute a command?

I want to know how to call a function after a normal or Ex command. Examples: bind a function to search command. When I input /xxxx to search xxxx, also call the function. press * to highlight ...
0
votes
1answer
31 views

How do I enable mouse in netrw only (terminal vim)?

I would like to be able to use my mouse to scroll and click on directories to expand them in netrw. I don't want the mouse to be on for any other filetype/buffertype, so that I can still highlight/...
4
votes
2answers
130 views

Unit Testing Vimscript built-ins: possible to override/mock or inject substitutes?

I found a bug in the CoC plugin, and I was going to fix the bug, but first I wanted to write some documentation/learning tests as well as a regression test. The question was how: unit testing does not ...
3
votes
1answer
38 views

Backward search in current line with search() and z option

I am trying to write a couple of simple functions to find the next and previous links in Vimwiki and move to them. Links in Vimwiki are indicated with the syntax [[link to something]]. Since I only ...
0
votes
1answer
31 views

Map the - key to “delete the current line, then paste it below the one we're on now”

I am doing the exercise of learn vim the hard way I have trouble mapping "the - key to "delete the current line, then paste it below the one we're on now". I tried: :map - dd p :map - :...
0
votes
2answers
45 views

What is the vimscript's no operation statement?

What is the NOP code for vimscript?
0
votes
0answers
42 views

Tool for convert multi files vimrc into single file

i try to collect my .vimrc files into single file is there anyway to generate single file using vimscript depending on source vimscript keyword or python code example of my .vimrc if isdirectory($HOME....
0
votes
1answer
23 views

Get count of string in vim

To get the count of a string I usually do something a bit hack-ish such as the following: Do a :%substitution on the string in question, such as: # how many times does the string "<Item "...

1
2 3 4 5
24