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.

0
votes
1answer
11 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
23 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
39 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
30 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
19 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
63 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 ...
3
votes
1answer
95 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
56 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
63 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
22 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
43 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 ...
3
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
39 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
44 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
51 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
33 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 ...
7
votes
1answer
348 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 ...
3
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
26 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
35 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
56 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
25 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
105 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
26 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
78 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
44 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
27 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 ...
0
votes
2answers
48 views

How to match autocmd pattern for unique file

I'm trying to make autocommands that will run only when the buffer is a man page (:Man) but I can't get the right pattern as i'm not too familiar with regexp and globs. here's what i've tried so far: ...
2
votes
1answer
34 views

Mapping to insert comment at the end of a line

I'm currently writing a plugin to quickly appends commented TODO: codetags to the end of a line in any file type. How can I make vim make use of it's commenstring feature to append a comment that ...
3
votes
2answers
123 views

Why do functions in Vimscript require a “call” statement?

In Vimscript, if you use a function as an R-value, then the function simply evaluates. For example: let count_pattern += str2nr( strpart( execute( command ), 1 ) ) However, if a function is used by ...
0
votes
1answer
25 views

How to return control characters from a function?

I have a keybinding that works: inoremap <silent> <Tab> <C-r>= \ pumvisible() ? "\<lt>C-N>" : \ CursorAfterOnlyWhitespace() ? "\<lt>Tab>" : \ "\<lt>C-\&...
0
votes
1answer
41 views

Copy text from one buffer to another using Vimscript

I need to process text line by line in one buffer and append the processed text to another buffer in Vimscript. I can do this by using buffer switching ex commands, but I suspect it will cause ...
2
votes
2answers
29 views

Mapping space and backspace for “pager mode”

I used to have some simple map macros that implemented a "pager mode" for vi. When I was reading through a very long file, I would activate pager mode. This would make two key maps: <Space> ...
3
votes
2answers
56 views

Creating a repeatable mapping in Vim

I find myself often aligning certain code blocks by inserting one or more spaces, like in the following situation: case something of Just a▉-> ... Nothing -> ... Here ▉ is the position ...