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.

1
vote
0answers
16 views

What is the correct character for splitting a string on line breaks in Vimscript?

Consider the following text file. line1f line1n line2 Suppose I visual select this, yank it into register a, and then pass it to the following vimscript function: function TestSplit(block) for x ...
1
vote
2answers
45 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) ...
0
votes
0answers
13 views

Running a command after makeprg successfully runs

I have a workflow where I build on one machine and copy the result to a different machine for testing. Currently I use vim-dispatch for running make in the background. What I would like to be able to ...
0
votes
1answer
29 views

vim FIGlet question: “-w76--” after every output

I love the plugin vim-FIGlet but I every time when I run :FIGlet ..., it always produces a text shape of -w76-- right after. For example, this is the output of :FIGlet demo: _ ...
1
vote
0answers
39 views

blue warning suppression, zip folder [on hold]

Is there a way I can remove the blue warnings that appear when editing a file from a zip folder in vim? Is there some setting I can apply in the vimrc file? Sorry, they are not really warnings but ...
0
votes
0answers
32 views

Is there a particular name for when you pre-set a bunch of registers used for a specific task at hand?

For example one could have many of these for different tasks (with different values for different registers based on the task): function !RegisterTemplateTest() # Set contents of said register ...
0
votes
2answers
29 views

How to create a function to `hash` buffer content

I want to create a function that I can call to replace a specific string pattern with md5sum of current buffer. I have no experience writing VimL before and can't figure out the way to do it. This ...
0
votes
1answer
14 views

Check nerd tree is open function

I'm trying to create a simple function in vim which lets me map <leader>b, <leader>n, and <leader>0 to execute a function that checks if a nerd tree is open then cycle tabs and do :...
1
vote
0answers
26 views

Vimscript infinite loop

I'm trying to combine fzf-bibtex with UltiSnips so that I can search my bibliography file and insert a BibTeX key automatically. I use the following function from fzf-bibtex (which calls the binaries ...
2
votes
0answers
44 views

How to use register in a script without side effect?

I want to create a function like this: function Foo() copy something from buffer into a register do something restore register endfunction Foo must have no side effect, every register ...
0
votes
1answer
34 views

Why doesn't this `:execute` command work?

I was looking at this question on Unix & Linux Stack Exchange, and I thought I could write an answer for it using Vim. I ran the following for a quick test, and was surprised to find it didn't ...
0
votes
0answers
31 views

How to stop a function when <esc> is pressed? OR how to catch a <esc> signal in vimscript?

I have a function which calls another function that reads user input from input(). function! fun1() call fun2() endfunction function! fun2() let temp = input("Please input:") endfunction What I ...
2
votes
2answers
102 views

imap <space> to _ (underscore) when writing function names in python files

the goal is to be able to write functions names that follow PEP8 as easily and naturally as writing this sentence. there are many types of situations that need handling insert _ (underscores) for ...
1
vote
1answer
22 views

Vi shortcut to execute line under cursor as a command

I am searching for a way to execute a line under the cursor as a command. I assign it to a combination of <Leader>el and basically I found a way to do it with :exe !@u but the issue I have here ...
0
votes
0answers
32 views

Can I script VIM to process a list of diffs?

I often need to keep several directories synchronized across two or three machines. I will periodically run diff -qr local/path mounted/remote/path > diff-list.txt to get a list of what is ...
0
votes
1answer
39 views

Problem with conditional mapping <expr>

I am trying to reproduce this vimscript code function! NormalRemap() :nnoremap <silent> <nowait> I I :nnoremap <silent> <nowait> a a :nnoremap <silent> <...
0
votes
1answer
42 views

How can I get vim to type continuously, rather than holding in place for keymappings?

For the purpose of this question, imagine that I have set iab phil philosopher In vim, as far as I know, the default display pattern when typing out the characters "phil" at the start of the word is ...
2
votes
1answer
66 views

get exit status from system() call

Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command? ...
0
votes
1answer
55 views

How to create new operator by using existing operator with current motion?

function! OperatorFunc(type, ...) " how to call another operator with current motion? " do other stuff endfunction Is it possible to get motion text? such as get iw from yiw
1
vote
1answer
56 views

How to change string at specific byte index nicely?

I want to change 3rd byte of a string to x, i'm currently using this code: let s = s[:1] . 'x' . s[3:] It's a bit awkward, i wish i can do let s[2] = 'x', but that's not allowed. Are there any ...
2
votes
1answer
96 views

Reliably get the character at a byte index in a string

I'm doing some string processing in vimscript. I obtained a byte index for a character in the string and now want to obtain the character at that byte index. For single-byte charsets (like latin1) ...
1
vote
2answers
58 views

substituting /* in vimscript

I'm trying to remove the verilog block comment start: /* I'm trying to do this inside a function: call setline(line('.'), substitute(getline('.'), '/*','','')) Of some reason, it doesn't to ...
2
votes
1answer
65 views

Change/Set color to a string in statusline

I'll preface by saying that I am using Airline, plytophogy/vim-virtualenv plugin and gruvbox as the Airline theme. I am trying to change the color of some string in the status line to, say, orange. ...
1
vote
0answers
23 views

How to use visual mode in python/dyn?

Vim documentation states how to run command and normal mode commands (source): vim.command(str) python-command Executes the vim (ex-mode) command str. ...
1
vote
0answers
13 views

Where could I find documentation of python/dyn or python3/dyn?

I guess that :py command is executed by some kind of extended Python interpreter. This extended Python has vim package available: :py import vim; print(dir(vim)); print(vim.__package__, vim.__name__) ...
0
votes
1answer
21 views

Why does backslash-escaping a CJK character cause a very-magic regex match to fail?

My understanding of very-magic regexes is that you can escape any character outside [A-Za-z0-9_] with a backslash to make it match literally. However, I don't see that behaviour with CJK characters. ...
2
votes
1answer
45 views

How can I search for Unicode characters by hex code in very magic regexes in vimscript?

I am working on UTF-8 support for my editorconfig-core vimscript plugin. I have hit a strange snag. This is in official GVim 7.4 Win32. I would like to get this working on 7.4, rather than ...
2
votes
2answers
188 views

Detect existing key binding before creating one

A plugin I've recently started maintaining currently checks to see if any bindings exist to its functions before creating the default ones. This makes it easy to setup custom bindings and not have to ...
2
votes
0answers
34 views

Is it possible to call searchpair or searchpairpos on string instead of current buffer?

searchpair or searchpairpos works only on current buffer. Are there similar functions work on string instead of buffer?
1
vote
0answers
40 views

Syntax highlighting - help me find the bug

I have a bug and I can't figure out the solution. Perhaps you esteemed folk can be of aid. I want to extend a syntax file (julia syntax in polyglot package). I want to include the following patterns ...
0
votes
1answer
37 views

Change the backspace behavior in neovim

I have the following function that inserts tabs if cursor is at the start of a line and required amount of spaces otherwise. function! SpecialTab() abort if (col('.') == 1) || (matchstr(getline('....
0
votes
1answer
45 views

Are there any built-in functions to search sorted list?

Are there any built-in functions to search sorted list? Such as binary_search, lower_bound, upper_bound, etc.
0
votes
1answer
59 views

Integrating autocomplete and snippets

I'm trying to set up an autocompletion/snippet workflow that's a bit complicated. This is stemming from needing a better workflow for latex. Right now I'm using coc.nvim and UltiSnippets but I am ...
0
votes
1answer
34 views

Distinguish between the column number of cursor after and before the first character in a line

Take for example, " This is a line How do I check if my cursor is after the first " character or before it, if I'm in insert mode? The reason I need this is because I have a insert-mode ...
6
votes
1answer
350 views

How to source a part of a file

I can source a file, e.g. my vimrc with :so % or :so <filename>. But what do I do when I need to source only part of a file. I want some way to visually select a portion of the file with :h v ...
2
votes
1answer
47 views

Why can't I use a literal Tab as the {commands} for :normal?

I'd like to write the following code: function Normal(command) execute "normal!" a:command endfunction call Normal("\<C-O>") call Normal("\<C-I>") The first call to Normal succeeds, ...
2
votes
0answers
34 views

Jump to last position when using vim netrw to open a file

I am looking to jump automatically to the last position in any file that I open. I have in my ~/.vimrc file: autocmd BufReadPost * ...
0
votes
1answer
27 views

Get the current mode in vimscript/Python

I have a vimscript function that needs to call Python code, depending on what mode I'm in. Some posts here recommend to use :mode() such as Within a function, Is there a way to determine if vim is in ...
0
votes
0answers
30 views

highlight link with condition file does not exist

For a wiki syntax plugin, i'd like to have two highlighting colors for links. Links already having a destination file should be green and links with no destination yet should be red. [[This file ...
1
vote
1answer
43 views

Vimscript or macro to “rotate” column 20 (or n) vertically?

Given an integer n and a block of text, rotate every character or element in the n-th column up or down to the next position that exists. A line with more than k characters. A longer line with more ...
0
votes
2answers
38 views

Vimdiff: Is there a way of knowing if there are differences in the diff files or not?

I am trying to find (in Vim script) if the 2 files open using vimdiff are same or different? Is there a way to do that? (a variable like &diff perhaps?)
0
votes
3answers
57 views

How to write a vimscript to replace the word under cursor in i mode?

I'm writting a complete script, and when the function is triggered in i mode, I need to delete the word under the cursor and call the function complete to put new words. I only know to delete the ...
0
votes
0answers
44 views

how does t_AB and t_Sb option difference in vim?

I see three sets of options for terminal colors on the vim documentation. The first set of options: t_AB set background color (ANSI) *t_AB* *'t_AB'* t_AF set foreground color (ANSI) ...
0
votes
0answers
26 views

How to pass '\v\C[pattern]' into the built-in match() VimScript function

I am attempting custom fold logic as my first VimScript. What works for me: USING VERY MAGIC (\v) and explicit CASE SENSITIVE (\C), find python comments in foo.py that begin with hash, then Roman ...
0
votes
2answers
118 views

How to execute commands in vim, piping the output back into the editor in real time?

So, to begin, this is similar to Pipe shell command into buffer in real-time. The difference is that the top answer there pipes the output to a new buffer. How do I pipe the output to the editor ...
2
votes
1answer
28 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
82 views

How to execute selected lines in bash and print the output in the next line?

I know that with this command: :yyp!!bash I can execute current line and print the output in the next line (actually it copies the current line to the next line, executes it, and replaces it with ...
1
vote
1answer
52 views

Is there a Set datatype in VimScript?

I am aware of lists and dictionaries in vim. But are sets supported in VIM to store only unique values? Or do I just have to use a dictionary with some dummy value?
1
vote
2answers
45 views

Vim Syntax Highlighting for an Object's Method Call

I would like an object method call to be syntax highlighted in Vim. For instance, in an expression that contains person.getName(), I would like to match getName and give it some syntax highlighting. ...
2
votes
1answer
29 views

Silence errors from colorscheme, silent! and try/catch not working

I modified a colorscheme file which generates E419/E420 errors when loading, but I would like to ignore them silently. silent! and try/catch aren't working for me. My .vimrc is shown below. All the ...