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
39 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
48 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
123 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 ...
7
votes
1answer
355 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
48 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
37 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 * ...
1
vote
1answer
32 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
31 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
43 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
60 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
46 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
28 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
210 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
36 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
90 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
51 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
41 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
55 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
133 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
28 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
44 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
32 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 ...
0
votes
1answer
25 views

How to create a enum for command parameters for build integration

There are many build targets in the project, I would like to create a command, for example BuildFor. The idear is, the alternative parameter will present one by one while keep pressing the Tab key ...
1
vote
1answer
98 views

Get current visually selected text

I need to write a function that returns current visually selected text or <cword> on mapping. Result of this function I give further to cscope find s command. Something like this: noremap <C-...
1
vote
2answers
77 views

try catch with :Rexplore

I want to be able to hit a single key to see the netrw buffer for the directory of the file I'm in. Rex will handily move your cursor to where it was previously, but only works if you opened the file ...
0
votes
2answers
102 views

Set cursor in quickfix on autocmd event

I need to set cursor position when opening quickfix window. I have tried autocmd BufEnter * call cursor(2, 2) It doesn't set cursor for quickfix buffer immediately after I have opened it. UPD: I am ...
0
votes
1answer
33 views

How can I make Vimscript check if the current line has a comment?

I want to make a Python ftplugin (but other filetypes will also have this option) where, if the previous line has a comment that starts with #, the next line can be commented via <Shift><CR&...
1
vote
1answer
36 views

Load current buffer in another pane

I'm writing a plugin where I have several buffers open in split panes ( let's call them small panes ). The user can navigate between the small pane using the usual ctrl+w , wincmd etc ways. While I ...
2
votes
1answer
64 views

How to set group of tabs and 1 single terminal in Vim 8?

I am a Vim beginner. I know you can do :tabnew file1 file2 to have Vim open up a bunch of files name file1, file2 spread across as tabs. I know you can move forward and backward between tabs. My ...
0
votes
1answer
55 views

How use a custom time value in `strftime()`

I am able to use strftime() to convert the current time to a string, but now I need to work the other way around: Convert a string to {time} Modify the time value Convert back to string Is there a ...
1
vote
1answer
88 views

How to do a conditional key mapping dynamically?

I know that I can do a conditional key mapping by map-expression: map [key] [condition] ? [foo] : [bar] But now my situation is somehow awkward. I want to map <C-h> to <C-w>h if I have ...
1
vote
1answer
36 views

How to have vnoremap call function once?

I'm trying to write a function + map that works on a visual selection. My function just prints out the marks right now: let g:count = 0 function! s:plink(...) abort let g:count = g:count + 1 ...
0
votes
0answers
69 views

How to get the current word starting from the cursor?

In vimscript expand('<cword>') gives me the word under the cursor. How can I get the word under the cursor starting at he current cursor location (skipping the word start).
0
votes
1answer
40 views

Call function with count after performing some normal! level tasks

I have this following function " copy yanked text to tmux pane function! Send_to_tmux(count) range if (a:firstline == a:lastline) execute "normal! \"zyip" else execute "normal!...
3
votes
1answer
70 views

jobstart callback wont assign variable outside of function

I have a job I want to run in the background of vim, and update my status line with the periodic results of that job. I'm able to setup the timer, call the external job and get my response back. I'm ...
0
votes
1answer
47 views

Vim disables syntax highlighting after execution `autocmd BufAdd * exe 'buffer ' . expand('<abuf>')`

Following code switches off Vim syntax highlighting for buffers opened after its execution. autocmd BufAdd * exe 'buffer ' . expand('<abuf>') Why? Is it bug?
1
vote
0answers
29 views

May I let `titlestring` tell whether I am in command-line mode?

Following from this post, I can happily "project" character n to the titlestring when Vim is in Normal-mode, and "project" character i to the titlestring when Vim is in Insert-mode. This almost ...
1
vote
0answers
51 views

Why does this autocommand works on neovim but not on vim?

I have this little augroup that contains a simple autocommand that hides the /home/devs/ text on top of nerdtree: augroup HideHOME autocmd! FileType nerdtree autocmd FileType nerdtree syntax ...
0
votes
0answers
28 views

Fuzzy / smart / intellisense completion in input mode

Standard Vim completion supposes that you type in the beginning of the word, then press CTRL-N, and get all the words that begin with the prefix you typed in. In my situation, prefixes are mostly the ...
0
votes
1answer
56 views

Display the first line of some file instead of an identifier

Is there some way to display an identifier as something else? Imagine the following setup: You have a readme file: * <<123456>> * <<789078>> This readme file is inside of a ...
1
vote
1answer
75 views

function: sort output alphabetically

This function outputs data between braces as joined lines in a quickfix window. The output is sorted based on line numbers. I'm searching for a method to sort the data alphabetically. I tried to ...
0
votes
2answers
99 views

How to detect running in intellij in vimrc?

I have some plugins I would prefer load by default in the terminal, and cause performance issues or ux glitches in jetbrains ides running ideavim. Neovim needs to start getting adopted, but that's an ...
0
votes
0answers
38 views

How to get the same message and error behavior as normal `n` when calling `normal n` in function

I wrote a vimscript function that prevents the cursor from changing its location on the screen when I press n: function! my_n() let l:start=line("w0") let end = line("w$") let cursor = ...
-1
votes
1answer
29 views

How to edit multiple files with same scriptin/scriptout using vim

When I use a command like vim -s script *.cfg it stops at the end of first file stating that there are x files left to edit and not executing the script in the remaining matching files. script ...
1
vote
0answers
37 views

How to write to a temproary buffer in a plugin

I've started to write my first vim plugin, a simple timer. I want to be able to set a timer for an arbitrary amount of time, and have it notify me once that time has passed. I've got it all working, ...