Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
1answer
42 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
22 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
22 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
15 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
31 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,...
1
vote
1answer
38 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
44 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 ...
0
votes
1answer
37 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
50 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
27 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
53 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&...
0
votes
0answers
21 views

Why termopen() deletes the currently opened buffer?

for example, if I have 3 opened buffers listed like this: :ls! 1 "deleteme/test1" line 1 3 # "deleteme/test2" line 1 4 %a "deleteme/test3" line 1 ...
2
votes
1answer
79 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
0answers
34 views

Is there an easy way to inspect a local scoped vim variables?

Is there anyway I can inspect a variable defined in a function without actually calling the it's function? suppose I have this snippet: function! s:handler(line) let l:file = split(a:line, '') ...
0
votes
1answer
26 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
31 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
33 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
41 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
24 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
47 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
30 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
45 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
25 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 ...
5
votes
2answers
263 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 ...
0
votes
1answer
28 views

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

First of all sorry for the dumb question but I already searched google but did'nt find anything (or atleast did'nt understand it at all).. I'm trying to make a vimscript that will read the ....
0
votes
1answer
23 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
48 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
36 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 ...
2
votes
2answers
331 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
20 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
41 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
43 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
41 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
58 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
73 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
61 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
42 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 ...
0
votes
1answer
31 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 ...
2
votes
0answers
44 views

How to escape paths for findfile() and finddir()?

I have run into an escaping problem with the path argument to findfile({name}, {path}) / finddir({name}, {path}). In my code path is a directory, obtained via fnamemodify(<file>, ':h'). Until ...
1
vote
1answer
47 views

How to visually select a pattern only on current line using vimscript?

I'm trying to write a vimscript function that will allow me to map a key to select a regex match on the line my cursor is on. This will help with selecting strings for use with ctags. For example, I ...
1
vote
0answers
74 views

Toggle UltiSnips

I have this following mapping in my .vimrc " Toggle search next with blink and without blink let s:enabled = 0 function! NextMatchToggle() if s:enabled unmap <buffer> n ...
2
votes
0answers
30 views

Why does vim CursorMoved event triggered in this script?

I'm writing a vim script. When fun() is called, I want a new window of 3 lines height is opened, with the content of register h displayed. And then, when the user moved the cursor, like hjkl, the ...
1
vote
3answers
43 views

Repeating a macro to create lines of text

I am pretty new to vim and hence trying to learn some of its powerful features and ofcourse top of the list is macros. So i am trying to create a pattern like this. <tag>var 1</tag> <...
2
votes
1answer
79 views

Sending command to different tmux pane from vim

behave test language need to execute different lines of the behave feature file, for example, if I want to test the line number 99, I'll need to input the following line in the terminal behave ...
3
votes
0answers
27 views

Completly silencing commands like `dd`, `:delete` of old vim versions (7.4.152)

Discl. I'm perfectly aware of :silent :delete or silent :normal dd, I'm also aware of execute(). My context is that I run unit tests with vimrunner on travis, with the version of Vim currently ...
1
vote
1answer
31 views

How to “dereference” variables in keymappings?

I just learned about vimscript. I'm trying to write a small vimscript that'll kinda copy what this does, but more verbosely and very explicitly. (The first case would case typing a ( will insert ()) "...
4
votes
1answer
63 views

Sort lines ignoring leading component

I would like to sort some lines, ignoring a leading part of them. Here's an example from my .spacemacs file: '( better-defaults elixir emacs-lisp erlang evil-commentary ...
0
votes
0answers
38 views

Vim observe text edits in insert mode

I'm building a program that analyzes text in real time or live while the user is editing. The idea is to send all changes or text edits from insert mode to a separate process. The separate process is ...
1
vote
1answer
41 views

Give variable to makeprg

I'm trying to put the output of a command into a QuickFix list when a particular key is pressed. That command takes as its argument the word under the cursor, so my function looks basically like this (...
0
votes
1answer
26 views

[no]foldenable / foldmethod for each buffer but keep those settings persist for each buffer

I have two opening buffers and one has foldenable and foldmethod=indent, other has nofoldenable and foldmethod=syntax. I need that when I move between buffers, each buffer has it own fold settings ...