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
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 ...
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
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
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> ; ...
9
votes
5answers
4k 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, ...
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
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
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
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 ...
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,...
38
votes
1answer
20k views

Use conditional operators AND or OR in an IF statement?

This is probably an incredibly simple question, but I did not find any answer so far (I must lack the right sources, and I don't know where to search in vim's help). I have a condition and I would ...
-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 ...
5
votes
2answers
295 views

Why vim plugins have a check on &cp

I'm trying to wrap my head around vim plugin development and I see a constant check on a variable to see if the plugin has already been loaded like: if exists('g:loaded_plugin') || &cp finish ...
2
votes
3answers
154 views

VIM mouse scrolling on Konsole show ^[OA at the top and ^[OB at the bottom of the page

function! GitBranch() return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") endfunction function! StatuslineGit() let l:branchname = GitBranch() return strlen(l:...
15
votes
5answers
3k views

How can I source a visual selection of vimscript?

If I have a couple of lines of vimscript that I want to test before putting in my vimrc, is it possible to visually select, then source them? I have tried make visual selection v, then motions 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
325 views

Why does ViM use VimScript? [closed]

As a person that is interested in the tools used to build useful software Why does ViM need a built-in language such as VimScript ( VimL )? Why It cannot be just C?
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') ...
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 ...
1
vote
1answer
231 views

How to populate the preview window?

I need to show a 'prompt' in the preview window when the user makes a selection of an item in a popup window, which is similar to the way the tern-for-vim completion plugin does in Javascript files, ...
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
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:...
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 ...
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
64 views

Solving issue with clang-format-vim.py saving new buffer

Summary I configured vim to call clang-format.py following the steps in the clang documentation for vim integration. But when I save a new buffer the plugin fails. I'm new to vimscript and trying to ...
1
vote
3answers
1k views

try catch with :Rexplore

I want to be able to hit a single key to see the netrw buffer for the directory of the file I'm in. Rex will handily move your cursor to where it was previously, but only works if you opened the file ...
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
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> ...
9
votes
1answer
2k views

Is there any way to distinguish between neovim and regular vim?

I was trying to migrate to neovim from vim. But in the end, there's some plugins which require python3 support and neovim package doesn't build with python3 by default( I'm on ubuntu, install neovim ...
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 ...
4
votes
1answer
1k views

How to get the current mode in vim?

I'm writting scripts for vim, and I want to let the script do different things in different mode. I know that the statusline will show the current mode, but I don't know how to get the exact current ...
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 ...
2
votes
3answers
138 views

Is it possible to perform a visual block selection programmatically using line and column numbers?

I've looked around in :help V but haven't found anything of this sort, but was wondering if there's a function I can call from vimscript that would visually select a region based on (row, column) ...
20
votes
3answers
2k views

The simplest way to start Vim in private mode

I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands: set history=0 set nobackup set nomodeline set noshelltemp set ...
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&...
2
votes
3answers
2k 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 ..." " ...
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 ...

1
2 3 4 5
24