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
0answers
44 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:...
-1
votes
0answers
22 views

Mapping to <Esc> and <Return> not registering

I have this set of maps: nnoremap <C-s> :^[:w snoremap <C-s> <Esc>:w<Return>v<C-o> xnoremap <C-s> <Esc>:w<Return>v inoremap <C-s> <Esc>:w&...
3
votes
3answers
356 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
25 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
21 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
119 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 ...
1
vote
0answers
18 views

Syntax highlighting for vimscript in fenced code in StackExchange [migrated]

(Apologies if this question is duplicated. I searched for similar questions but all results that came up were about syntax highlighting within Vim, which is unrelated to my question.) Is there a way ...
3
votes
1answer
33 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
24 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
34 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
21 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
vote
1answer
45 views

How to check if a string starts with another string in vimscript

I know I can use regex matching with ~= and that stridx(haystack, needle) == 0 does work, but if I just want to verify that one string starts with another, I don't want to waste resources checking the ...
2
votes
2answers
64 views

How to find first item that satisfies predicate?

:help index explains that only exact matches are returned. How would you add a predicate to the search, so that we could find the first element that matches that? I want to write this: let i = 0 ...
2
votes
1answer
94 views

How do I make a function stop when an error occurs?

I just wrote a function which tries to call another function, but I got the syntax wrong. However, I was horrified to see that the next line in my function happily started executing anyway. It is as ...
0
votes
0answers
41 views

inoremap doesn't work

Question summary Currently I'm writing a pull request for this vim plugin which should set commas and semicolons automatically. At the moment it looks if it should set a comma/semicolon/double point ...
5
votes
1answer
59 views

How can I get the full command name from shortcuts such as :syn, :synt?

The commands :sy, :syn, :synt, and :synta all run the :syntax command. For a script I'd like to know which command the user typed on the commandline, for example: get_full_command('syn') " ...
2
votes
2answers
198 views

Set line numbers based on line count

If a file has a large number of lines, I'd like to enable line numbers, otherwise leave them off by default. If I run the command: if line('$') > 150 | :set number | endif while vim is open, file ...
1
vote
1answer
56 views

Vim change keyboard language.. via shortcut

I want to change keyboard language via vimscript shortcut. So that i ...
1
vote
1answer
27 views

imap <expr> call multiple functions

I want to map <CR> to call multiple functions e.g. Func1() Func2() Func3() I tried: imap <expr> <CR> Func1() Func2() Func3() But I got "E15:Invalid expression" How can I ...
2
votes
1answer
40 views

Convert working commands to VIMRC friendly mappings (ie: :%s with regex)

Is there a simple way of taking a previously issued command and converting it into a .vimrc-friendly keybinding? For example, I have a simple substitution utilizing regular expressions that won't work ...
0
votes
1answer
43 views

synIDattr returns nothing in function

I have this part of code: function! Test() echom synIDattr(synID(line('.'), col('.'), 1), 'name') endfunction autocmd TextChangedI <buffer> call Test() I expected that every time I change ...
0
votes
0answers
32 views

E716: Key not present in dictionary: “3”

I have this global at the top of my .vimrc: let DevEnv = { 'enabled' : 0, 'open_dirs' : 0, 'term_bufnr' : 0 } One of my .vimrc functions calls: exec 'bd! ' . g:DevEnv.term_bufnr Note that g:DevEnv....
0
votes
0answers
17 views

How to open terminal in split in vimrc with keybinding [duplicate]

I am trying to open a new terminal (size of 10) inside of neovim. I use the command, :split|resize20|term. It works well, but I want to make a hotkey to do this in my init.vim nnoremap <C-P> :...
6
votes
2answers
99 views

Convert absolute path to one relative to another absolute one

Context I’m working on an 'omnifunc' function for Markdown editing. It’s supposed to help me link to other Markdown files while I’m typing a link – based on file content though, not file name. Suppose ...
0
votes
0answers
31 views

Effect of changing directories in a vim command [duplicate]

When executing a vim command, such as the following: :w!<CR>:!cd %:p:h What is the effect after the command is finished? Is the new cwd the directory that I've cd'ed into? Or does that only ...
0
votes
1answer
38 views

How do I go back to my previous position after onoremap yank?

I have an operator function that yanks double quotes or single quotes, ciq works fine because I want to be inside the quotes but when I do yaq (yank a quote) I don't want to move to the place where ...
0
votes
0answers
27 views

Print command output on terminal on vim exit

I am trying to run shellcheck upon exiting vim, however I do not get the output of the command I run. I've tested running something like touch foo instead, and I managed to see the file being created, ...
0
votes
1answer
42 views

How to return keybinding from a function?

I want the below function to return keybindings but all it returns is a string. nmap <expr> <space>t ManageTerminal() function ManageTerminal() if bufname('terminal') ==# 'terminal' ...
0
votes
2answers
31 views

Swap selected block of code upward/downward?

I want to write a Vim Script which can achieve the following function, which is my favorite feature in some IDE. Say I have the following example code: I'm a line and I just stay here. I'm another ...
0
votes
0answers
22 views

How can I know when a real file is closed/opened from/into a visiable window?

What I'm trying to do is, when a window is closed(bw,bunload)/opened (NOT fzf, quickfix q:, buftype=nofile, etc..) resize all the other windows. This code works but I was wondering if there was a ...
2
votes
2answers
66 views

Why does system(cmd) append ^@ to its output?

I want to set node's executable path for neovim. So I have added this line in init.vim. let g:coc_node_path = system('which node') But when I open nvim I get this error. [coc.nvim] "/home/akash/....
1
vote
1answer
39 views

How to 'join' using formatexpr and function

One can find several examples of formatting one sentence per line such as right here: How to set up Vim to work with one sentence per line? The question states that: My current solution is to join a ...
2
votes
1answer
62 views

How do I find the ex/vimscript equivalent of a normal-mode command?

Some operations can be done with either normal-mode commands or ex/vimscript commands. For example, :resize 1 does the same thing as 1 <C-W> _. In scripts, it's possible to simulate normal-mode ...
1
vote
1answer
46 views

What is right way for string concatenation in vimscript?

I wrote some vim plugin, that correctly works with vim8, but when I try run it with neovim I get error about invalid expression in string: let var = str_first .. str_second When I change .. to . all ...
2
votes
1answer
158 views

What does `_` do in this map() expression?

I'm trying to understand the code suggested in https://vi.stackexchange.com/a/28506/6189: function MyLinks(pat, spat, ssub, sflags) abort return glob(a:pat, v:false, v:true) \ ->map({_, v ...
1
vote
2answers
87 views

why are variabes prefixed with `a:`?

I'm trying to understand the code suggested in https://vi.stackexchange.com/a/28506/6189: function MyLinks(pat, spat, ssub, sflags) abort return glob(a:pat, v:false, v:true) \ ->map({_, v ...
4
votes
2answers
78 views

What is `v` in this vimscript?

I'm trying to understand the code suggested in https://vi.stackexchange.com/a/28506/6189: function MyLinks(pat, strip) abort return glob(a:pat, v:false, v:true) \ ->map({_, v -> printf(...
2
votes
1answer
59 views

Quickly correcting spelling mistakes but omitting some cases

I am using vim as a note-taking app. Following an earlier answer here , I have the following mappings which allow me to quickly correct earlier spelling mistakes: " spelling imap <C-l> <...
1
vote
1answer
49 views

Vim: How to manipulate appearance of signs in .vimrc?

I have seen a guy on YouTube who has some sort of Markdown rendering in Vim. The * sign from a list is displayed as a •. When the cursor travels over it, the actual sign shows up. I have checked his ....
2
votes
1answer
203 views

VimWiki - create a “smart” index page for subdir/section of wiki?

I'm using VimWiki for a writing project and for certain sections (like "chapters", contained in sub-directories) I want to create indexes that work similarly to the way VimWiki's diary index ...
0
votes
1answer
31 views

Vimscript: Placing the cursor at a defined position in the buffer

I use vim as a note-taking app by editing a text file and appending notes to it. I have written a simple function to insert a block of text as follows: function! AddBlock2(...) range let l:hdr = ...
0
votes
1answer
46 views

Measuring how much I write in vim by comparing word count on each save

Suppose I want to write N words related to my studies in Vim everyday as my daily goal. Every time I am done writing something I can do g+Ctrl-g and then I can send that number variable to a file. I ...
2
votes
1answer
234 views

Is it safe to define more than 120 signs?

I am working on a plugin that could potentially define more than 120 different signs. The vim / neovim documentation specifies that you can define about 120 signs (not sure why this number and why so ...
3
votes
1answer
145 views

how to loop through list of files?

I can do :echo globpath('~/path/to/dir', 'string*') to get a list like: /home/alec/path/to/dir/string_xyz123.mkd /home/alec/path/to/dir/string_xyz456.mkd /home/alec/path/to/dir/string_xyz789.mkd but ...
2
votes
2answers
41 views

Get first and last visible line from other buffer than current

I know that I can get the first and last visible lines in the current buffer by using line('w0') and line('w$'), but is there a way to do it for other buffers that are visible but not active as well? ...
3
votes
1answer
39 views

Vim shows incorrect theme in error

Basically, all I'm trying to do is enable the syntax option. syntax enable colorscheme cobalt2 For some reason, I get no errors if I comment out the first line, but in case I don't comment it, I get: ...
0
votes
1answer
96 views

How to exit vimscript? [duplicate]

How to exit .vim script file? I want something like this in my init.vim if exists('g:vscode') "Do not execute rest of init.vim, do not apply any configs exit endif "...some configs... ...
3
votes
2answers
72 views

Is it possible to override the filetype of a text file based on the first line?

I have some specifically formatted text files that I'd like to detect when I start vim. When I load these files now, the filetype is automatically set to text. I only want to override that if the ...
1
vote
2answers
71 views

How can I turn these mappings into a vim function?

I use the following mappings to toggle relative numbers in visual mode: nnoremap <silent> v v:<c-u>set nonu rnu<cr>gv nnoremap <silent> V V0:<c-u>set nonu rnu<cr>gv ...

1
2 3 4 5
23