Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
1answer
506 views

How to get rid of “Press ENTER or type command to continue”

I'm using ctags to code C++ with vim. I set two shortcuts of ctags as below: autocmd VimEnter * silent! !eval 'ctags -R --c++-kinds=+p --fields=+iaS --extras=+q --language-force=C++ -o newtags; mv ...
2
votes
1answer
35 views

Not displaying ErrorMsg for long lines only with tex, md and calendar buffers

I use and love the plugin calendar.vim. Those days, I decided to add the following to my vimrc: autocmd BufEnter *.tex,*.md call matchdelete(4) autocmd BufLeave *.tex,*.md call matchadd("ErrorMsg", "\...
0
votes
1answer
67 views

How to print a message after `autocmd` is done

I'm using ctags to generate tag file so that I can jump to declaration or to definition while working with C/C++ project. To make ctags work automatically while entering vim, I add such a line in my ...
1
vote
1answer
31 views

How to create or modify vim commands?

In Vim wrapping lines at 80 characters without breaking words can be done with the following commands according to this article: :set formatoptions+=w :set tw=80 gggqG Setting 80 char wrap is ...
0
votes
1answer
96 views

Vim can't search for dot

I'm trying to write a Vim script function to toggle between -> and . but searching for . is seemingly impossible. I've tried to search using ASCII (decimal and hex) and it doesn't work. It all ...
2
votes
1answer
200 views

UltiSnips, Context and Tex

For best experience, I want to enable some snippets to be expanded only in Tex Math environments. A wonderful person, lacygoill helped me on GitHub to achieve just this with the following setup: Let ...
2
votes
0answers
49 views

display list of buffers `ls` without scrolling down

Is there a way to display output at the bottom of the screen like ls does, but without scrolling down to accomodate the output? The Vim Wiki (no https) has the following snippet :nnoremap <A-n>...
2
votes
2answers
69 views

A vim plugin like FLOWSTATE

Is there a way to make vim behave like the app flowstate? What this app does is forces the user to type continuously without pause for a certain period of time (which is very useful for brainstorming)...
0
votes
1answer
47 views

Function arguments + shell

I'm trying to write a command for adding a Python import line. The problem is that what's added it import a:name and not the module name. Here's the code func! PyImport(name) w silent !isort ...
0
votes
1answer
26 views

vimL, how to get alternate window's current buffer number

Say, with 2 windows open in vim, cursor is window 2, how can I get the current buffer of the alternate window (window 1 in this case)?
0
votes
1answer
41 views

Capture the next keypress under 200ms

1) I need to capture the next key press from the keyboard, if there are any in 200 millisecond. Which function should I use to achieve this? 2) Basically I need to re-send the captured key, with some ...
1
vote
1answer
63 views

Vim: Replace visual selection without overwriting the unnamed register

How do I replace a visual selection with some register content without overwriting the unnamed ("") register by the visual selection? The question https://stackoverflow.com/questions/3837772/vim-...
1
vote
1answer
72 views

Integrating ranger into neovim

I am trying to get ranger working inside neovim in a sensible way. The official vim plugin provided by ranger works perfectly in ordinary vim: <Leader>r launches ranger in full screen, q exits ...
1
vote
1answer
53 views

How do I make this vimscript function (taken from another question here) 'forget' about a previous search term?

Based on the accepted answer to this previous question, I put the code below in my .vimrc, which changes the color of my statusline depending on whether my search (started with / or ?) yields results ...
0
votes
1answer
87 views

matchstr() acts differently when used in script?

I have these lines in a script: " go to start of file and search until the end call cursor([1,1]) let moreLinesToGo = v:true let b:qtags = [] while (moreLinesToGo) " search for lines like ":344f:",...
0
votes
1answer
57 views

How to get writefile() to pay attention to &nofixeol?

I want to write the contents of a buffer with writefile(). However I do not want to use binary mode because I suspect it has (undocumented) side effects. My question concerns noeol files, i.e. files ...
0
votes
1answer
84 views

How to parse a string to a list?

Is there a way in Vim to do the following: let S = '[''123'', ''456'', ''789'']' let L = parseStringToList(S) " L is a list containing the string '123', '456', and '789'
2
votes
1answer
29 views

Swapping two vim mappings

I have added the following the mappings to my vimrc. I want K to take me to the top line of the window and H to take me to the first non-empty character of the line. nmap K H nmap H ^ nmap J L nmap L ...
0
votes
1answer
38 views

Why does `:call f(…)` do nothing while mapping it to a binding works?

I'm not really sure how to describe this behavior better than with the example I'm dealing with. I'm trying to write a custom completion using fzf-vim ... and as I'm looking through the documentation,...
2
votes
1answer
542 views

What is the difference of using `au BufNewFile,BufRead *.py` and `au Filetype python` in .vimrc?

As I am setting .vimrc, I found these two code blocks have the same functionality. au Filetype python set \ tabstop=4 \ softtabstop=4 \ shiftwidth=4 \ textwidth=79 and au ...
1
vote
1answer
111 views

Unmapping filetype mappings

I'm trying to unmap some key sequences mapped by python filetype plugin. While I know a better way, I'm still curious if it can be done with autocommands. Here's what I've got so far: augroup ...
1
vote
1answer
175 views

Get the column that the cursor is on in vimscript

In vimscript, how can I get the column that the cursor is currently on? I would like to save this value in a variable.
2
votes
1answer
83 views

How to yank count of matches of a pattern to a register?

%s///n show number of matching pattern like 102 matches on 102 lines. How to copy this output to a register?
0
votes
1answer
75 views

How to use fnamemodify to return dirname/filename?

I am using vim-airline and buffer tabline. I want to make the tab name become dirname/filename. How to achieve it? For example :ec fnamemodify('/usr/lib/abc/file.sh', '<something>') should ...
2
votes
6answers
219 views

Indent on New Line between HTML/XML Tags

I'm currently using imap <silent> <C-c> </<C-X><C-O><C-X><Esc>F<i as per this post and this page to close <></> tags of any kind with <C-c&...
2
votes
1answer
197 views

Escaping Shell Command Arguments in Vim

I'm trying to fully understand the following command in Vim: :exe "grep -R " . shellescape(expand("<cWORD>")) . " ."<cr> I got the use of expand function (force the expansion of into the ...
0
votes
1answer
45 views

What does `{ buf -> … }` mean in vim script?

" As above, but curry the arguments so only the buffer number is required. function! ale#VarFunc(variable_name) abort return {buf -> ale#Var(buf, a:variable_name)} endfunction What does { buf -...
1
vote
1answer
53 views

Insert Page break ^L automatically after specific number of lines/characters?

How could VIM (script?) insert ^L (page break) and /r on an empty line, automatically after every 30 Lines OR 1800 characters while writing? Any ideas?
-3
votes
2answers
69 views

how to append a list value to another list value?

I want to append every value of list1 in every value of list2, so that this: let list1 = ['one', 'two', 'three'] let list2 = [' wan', ' tu', ' tri'] will become like this: :echo result ['one wan', '...
0
votes
4answers
109 views

how to insert a character string between the first two letters of all the list value?

Suppose I have this string variable: let foo = [ \ 'no you are not foo', \ 'hi you must be foo?' \] I want to enclose all the first 2 characters in foo with '< ' and ' >' ...
0
votes
1answer
76 views

Why vim keeps returning error “E714: List required” when I'm already feeding a list to it?

I have this snippet: let g:git_file_prefix = ['M','A','R','D','U','?'] function! Colorize(str) let index = 0 for file in a:str call add(a:str[index], '$(tput 37)') let index = index + 1 ...
0
votes
2answers
135 views

How to get the specific key in a dictionary using the just the key's value?

Suppose I have a dictionary declared like this: g:dict = { \ 'foo' : ['foobar'], \ 'bar' : ['barfoo'] \} how can I get the key for barfoo using just the value(barfoo) itself?
1
vote
1answer
50 views

Operator pending mode remaps not working

I'm trying to build a vimscript can be used with the Dvorak Simplified Layout. I.e., given that the keys on the keyboard plugged into the computer are laid out in the Dovark Simplified Layout (and the ...
0
votes
1answer
53 views

What does it mean by `…` parameters in a function?

I often see vim function with function definition written like this: function! MyFunction(...) " function body... endfunction What does the ... do within the function?
0
votes
1answer
41 views

How to use a regexp to search/match specific pattern only for the custom statusline and/or tabline?

I got this regexp from google which is for matching specific glyphs in vim-nerdtree. autocmd FileType nerdtree syntax match {hl-group} /\v{glyph}/ containedin=ALL But obviously it won't work on ...
6
votes
2answers
543 views

Are script local functions (s:funcName()) unit testable?

Consider a script local function in a plugin/myplugin.vim file. For example myplugin.vim: func! s:someFunction() return 4 endfunc I would like to unit test this function. In the simplest ...
1
vote
1answer
234 views

How to check if the value of a variable has a specific character?

I'm trying to make a vimscript that will read the .gitignore file, return it's values as a List and check for paths that has wildcards eg: /vim/snippets/*, vim/**/*. let g:ignored = readfile("/home/...
0
votes
1answer
27 views

How can I append every filename as a List value in a variable?

I'm trying to make a List variable that contains all the globbed files's filename as it's value. so far, I'm able to get the file names but I can't seem to make a List out of it. here's my code: let ...
1
vote
2answers
170 views

set rtp in a function does not work

I have the following configuration for OCaml development which works fine: " --------------- OCaml ----------------------------- " Merlin let g:opamshare = substitute(system('opam config var share'),'...
1
vote
1answer
67 views

The difference between a plugin script and a sourced script

First, apologies for attempting to ask a complicated question since I would not be able to provide a lot of details, however, one might catch something that I am missing. I have a vim script, that is ...
3
votes
2answers
471 views

How to remove ^@ character returned by `system()`?

When I call this function inside vim statusline it returns this nvim^@.weird character, What is the meaning of ^@ in returned value and how to get rid of it? function! GetEditor() let s:name = ...
0
votes
1answer
29 views

Read the first line of the current file to process it in a command (Emulating %TeX root)

Currently I have the line :nnoremap <leader>c :w<CR>:!arara %<CR><CR> in my $MYVIMRC. If I press <leader>c, it will save the current file and run the command arara on ...
1
vote
1answer
45 views

Is there any `setvirtcol()`?

I'm looking for a way to precisely set the cursor position given a virtual column. Is there only :exe "normal! ".vcol."|"? NB: I need virtual columns as they're the only thing that I'm able to ...
2
votes
1answer
161 views

vmap and visual block: how do I write a function to operate once for the entire block?

I'm trying to write a simple function that wraps a visual selection of lines with Markdown ``` lines. Here's what I currently have: function! MarkCodeBlock() " Add Markdown code-block delimiters ...
1
vote
1answer
108 views

Check if key is already bound in vimscript / Map key only if not mapped already

I'm wondering if it is possible to check in vimscript if a key (or key combination) is already bound? I know about the :map command which lets me see visually which keys are bound to what actions, ...
1
vote
1answer
157 views

Function to toggle set colorcolumn

I like the set colorcolumn=80 option which highlights the column at 80 characters, however I find it annoying when working with multiple split windows. I'd like to have an option to enable or disable ...
3
votes
1answer
123 views

How to jump to a character offset in a buffer?

Vim has the command :goto to go to a byte offset in a buffer. Is there an equivalent for a character offset? If not, is there a better way to implement it than repeatedly testing the cursor's ...
0
votes
1answer
67 views

Function Unable to Fail: Breaks Macros

Vim functions do not seem to be able to fail without spitting out 3 unnecessary lines. For example, take this set of functions and maps: " NEXT / PREVIOUS " ~~~~~~~~~~~~~~~ " n and N always search ...
4
votes
0answers
116 views

How can I watch variables when debugging Vimscript?

I would like to have another pane active when debugging a Vimscript function which would show the values of chosen local variables and function arguments dynamically. Currently I have to echo or let ...
1
vote
1answer
76 views

What are the allowable characters in identifiers?

In Vim, what characters are allowed in identifiers, such as variable names and function names? I looked up the help for both variables and functions and neither one defines the allowable character ...