2022 Developer Survey is open! Take survey.

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
1 answer
11 views

How to get total width of Vim with vertical splits?

winwidth(0) returns the width of the current window. However, if vim has multiple vertical splits, forming multiple windows, winwidth(0) would only return the width of the current window. For example,...
user avatar
  • 23
5 votes
1 answer
255 views

Is it possible to break out of nested loops?

Say I have a nested loop, is there a way to break out of the outer loop from the inner one? For example this code: for i in range(3) for j in range(5) echo i j if i == 1 && ...
user avatar
  • 193
1 vote
1 answer
48 views

What is the significance of duplicating syntax-group name references?

According to :syn-define, several syntax ITEMs can be put into one syntax GROUP. Am I correct to infer that, regardless of the number of ITEM instances, e.g., syn keyword alphaBeta alpha beta syn ...
user avatar
1 vote
2 answers
26 views

How to find/highlight a word in the current line only

As title. The current problem is that my window is scrolled to the first/next(?) global occurrence. But I just want it to move my cursor to the local one, i.e. the current line, if any.
user avatar
  • 721
0 votes
0 answers
21 views

How to use command to insert a space in insert mode?

As title. Given that I'm already in insert mode and there is some insert mode function. Inside the function, I want to insert a space by command, how?
user avatar
  • 721
0 votes
1 answer
18 views

Configure the statusbar to show rows

I want to configure the statusbar in vim to show which row I'm on. I have it currently set as statusline=%l/%L\ (%3p%%) I want however to do something like the following statusline=%3l/%3L\ (%3p%%) ...
user avatar
1 vote
1 answer
20 views

Only highlight trailing whitespace in normal mode

I have some code in my ~/.vimrc to highlight trailing whitespace. " Highlight trailing whitespace hi TrailingWhitespace ctermbg=red guibg=red matchadd("TrailingWhitespace", '\v\s+$') I ...
user avatar
2 votes
1 answer
44 views

Is there a way to run an ex command without hitting colon first?

I am doing some scripting related to tmux and Vim. In my tmux window, I have Vim in one tmux pane and a Tcl command line in another tmux pane. I want to create a Tcl proc which will dump a string to ...
user avatar
1 vote
1 answer
183 views

Is it possible to execute Ex Commands (colon commands) in VimScript (vimrc/init.vim)?

First off, just an FYI: I am not that experienced with writing VimScript I have a plugin that I want to have enabled using its custom Ex command (:RainbowParentheses). Putting that inside my init.vim: ...
user avatar
1 vote
1 answer
20 views

How can I exit insert mode from a script?

I'm using the answer to this question to create a timeout to insert mode: Alarm for inactivity Once this timeout has been reached, I want the script to make vim leave insert mode, but I'm not sure ...
user avatar
0 votes
0 answers
22 views

Review: Vim9script plugin for easy window navigation

Some time ago, I wrote a plugin for easy window navigation, using which one can enter a "custom mode" via <leader>w, where Ctrl-w is prepended to any keys pressed, except for Escape ...
user avatar
  • 1,562
1 vote
2 answers
33 views

Write the current paragraph to temp file in Vim

I'm trying to write a function to write the contents of the current paragraph the cursor is on to a temp file. In normal more vip:w!temp.txt<cr> works fine, but placing normal! vip:w!unidecode....
user avatar
  • 195
0 votes
2 answers
32 views

How to get the buffer number of `:bn`?

As title. When running :bn the current buffer will be switched to the next buffer. I want to get the buffer number of this buffer without changing the current buffer(or, at least, can switch back to ...
user avatar
  • 123
0 votes
1 answer
26 views

Appending text to lines maintaining context

I'm trying to write some script (a function) which I can use to add some additions to a BASH script I'm modifying. This BASH script automates the building of a series of packages. The part of the ...
user avatar
-1 votes
1 answer
47 views

How to simulate an Enter key in command mode?

As title. Is it possible to simulate an Enter(i.e. <CR>) in command-mode, i.e. after pressing :?
user avatar
  • 123
0 votes
0 answers
21 views

How to split view all buffers in vim with equal distribution vertical horizontal

How can I split view all buffers in vim with a distribution between vertical and horizontal? Is there a plugin? I know how to make all buffers appear in either horizontal or vertical splits: :ball :...
user avatar
  • 11
0 votes
1 answer
39 views

How to filter lines only if the filter is successful?

I have the following lines in ~/.vim/ftplugin/python.vim: " yapf integration function FormatFile() :normal mp 0,$!yapf :normal `p endfunction autocmd BufWritePre *.py call FormatFile() ...
user avatar
  • 23
0 votes
1 answer
27 views

How to make an abbreviation that expands without pressing space

I am trying to replicate the behavior of beg abbreviation shown on the page https://castel.dev/post/lecture-notes-1/ with vimscript. That means I want to make it so that when I type "beg" in ...
user avatar
  • 11
2 votes
2 answers
42 views

How to detect whether the current file might contains a long line?

As title. I want to disable some plugins when the current file is a production file, i.e. it is compacted into < 10 lines but each line contains >1000 columns. I'm using NeoVim so I prefer ...
user avatar
  • 123
0 votes
0 answers
30 views

Convert Vim keymap to lua

I want to change my emmet leader key in vim, but I do not know how to do this in lua. Vim Script code: imap ,, <C-y>, Lua Code: local map = vim.keymap.set
user avatar
  • 1
0 votes
1 answer
25 views

How to take the path argument passed into vim/neovim into account when call `getcwd()` within the config?

As title. I'm using NeoVim. If I use vim.fn.getcwd() in the config I will not get the correct path considering the argument, e.g. nvim ./go/deeper/into/some/folder, passed to nvim. Solutions in ...
user avatar
  • 123
0 votes
0 answers
9 views

How can I sync part of a DOC cross reference with another file?

Is there a way in Vim to sync part of the markdown DOC across multiple files? For example, I have a description of a project, and I have to insert it in other files. When the main description is ...
user avatar
0 votes
1 answer
38 views

How to edit the current buffer in another existing buffer?

As title. I'm in a situation where a file is loaded into a buffer that is not listed in the buffers from the list :ls. So I want to transfer the content of the current unlisted buffer to an existing ...
user avatar
  • 123
3 votes
1 answer
66 views

Duplicate selected lines programmatically

I'm creating a Vim script and a critical part of it is duplicating the selected lines. To duplicate lines, I have this mapping which works as intended: vnoremap <Leader>d :copy '><CR> ...
user avatar
1 vote
2 answers
30 views

Create an autoload alias for an autoload function

I have a function like this in autoload/foo/bar.vim: function! foo#bar#do_stuff(...) abort " do stuff return endfunction Is it possible to create an "alias" for this function, ...
user avatar
2 votes
0 answers
27 views

Issue when moving Vim9script plugin's functions to autoload

I've read :help write-plugin to understand a bit more about how to write a plugin in Vim9script, but there aspects of that that puzzle me. Here's a very simplified, working version of the example ...
user avatar
  • 1,562
0 votes
1 answer
26 views

Replacing regex with italic code in Vim for Latex

I am using vim to write a document in Latex. I have to replace a regex with the italic code, which is \textit{regex}. I use the Vim code: :%s/regex/\textit\{regex\}/g But the \t expression is ...
user avatar
0 votes
1 answer
32 views

How can I continue executing commands on a splitted terminal window with Vim?

Let's say I run the following command on a node.js file inside Vim: :terminal node %" I'd like to continue executing commands on the newly opened window with a single command. But if I try ...
user avatar
  • 375
0 votes
1 answer
19 views

Function call makes cursor jump to beginning of file

I'm writing a function that should run a linter and then populate the location list with appropriate linting messages. The problem is that when I call the function (by running :Phpcs), the cursor ...
user avatar
  • 103
1 vote
1 answer
28 views

"non-greedy" [<any chars>](word) regexp problem

consider this sentence (a line in a text file): mi chiamo [Giorgio Robino](person) ed abito in [corso Magenta 35/4 a Genova](address) I want to search (select/extract) the pattern <any chars> ...
user avatar
0 votes
1 answer
44 views

How to chain multiple script commands?

I have used this script to be able to highlight results from test reports: https://vim.fandom.com/wiki/Highlight_multiple_words When using it in Vim, it works fine when I type :Highlight 1 FAILED (For ...
user avatar
  • 137
1 vote
1 answer
40 views

How to add commands from an external script to .vimrc?

I have used this script to be able to highlight results from test reports: https://vim.fandom.com/wiki/Highlight_multiple_words When using it in Vim, it works fine when I type :Highlight 1 FAILED (For ...
user avatar
  • 137
0 votes
0 answers
26 views

Call custom bash function from Vim

I have created a bash function, in its own .sh file, which I want to use from within Vim, and later use if from within the lightline config file. I have tried many ways, but I cannot make it work. ...
user avatar
  • 165
1 vote
1 answer
34 views

How to select a regexp group in vim?

I want to select/visualize a regexp GROUP in a vim regexp expression in vim. By example I would like to highlight (search) a span of characters inside square brackets, having this line: bla bla bla [...
user avatar
1 vote
0 answers
20 views

Meaning of number in "Error detected while processing function foo#bar[3]"

When vim produces an error message like, Error detected while processing function foo#bar[3] what's the significance of the number in square brackets (e.g. 3 in the above example). The actual error I'...
user avatar
  • 1,170
3 votes
1 answer
40 views

getting the fold state of lines in nested folds

vim provides the methods foldclosed() and foldclosedend() to get the first and last line of a closed fold. The problem is: It does not respect nested folds. For example this file: line 1 line 2 ...
user avatar
  • 545
1 vote
1 answer
31 views

Best Way to Strip Most Significant Digit from a Number

My goal is, given a positive integer, write a function to remove the leading digit and return the number given by the remaining digits. I have two ways of doing it presented here, and I'd like the ...
user avatar
  • 326
1 vote
1 answer
63 views

In a vimrc, how do you preload a register with a string containing Special characters, like a newline?

In a vimrc file I want to preload register C with a string I regularly need when coding. The string has a newline in it but no success in getting it to work properly. Here is an example vimrc snippet ...
user avatar
1 vote
0 answers
30 views

How to pre-render a terminal buffer before displaying it in a popup

I am currently trying to write my first plugin. So this is my first attempt at vimscript. I want to display the output of a shell command in a popup window. This can easily achieved with: command Cat ...
user avatar
  • 123
0 votes
1 answer
50 views

How do I use the \+ quantifier?

Running Windows 10 (Home) and VIM - Vi IMproved 8.1 (2018 May 18, compiled May 18 2018 18:36:07) MS-Windows 32-bit GUI version with OLE support Included patches: 1 Compiled by mool@tororo. I have ...
user avatar
4 votes
2 answers
184 views

Use CTRL key from the variable in map-<expr>

I have a variable with a "key" in vim notation, <C-j>. How can I use it in <expr> mapping? let g:key = "<C-j>" inoremap <expr> <C-j> '\' .. g:key &...
user avatar
  • 9,753
0 votes
1 answer
16 views

How to auto-confirm shortcut command

I have a function called Comment in my vimrc, and I have a shortcut that 'runs' this function: nnoremap <S-Tab> :call Comment() The way it currently works is I press [Shift]+[Tab] in normal ...
user avatar
0 votes
1 answer
119 views

Is there any good way to delete lines in a file

I'm writing myself a function that allow users to align the column by a given character The script is working well so far, I haven't seen any bugs yet, but I found the part that deletes the old lines ...
user avatar
  • 11
0 votes
0 answers
59 views

How to view the full shell error from a vim script?

I have been using vim/nvim for years on my desktop, and one of the most useful libs I have is the FZF vim plugin, specifically the command that lists the tags from the current buffer: :BTags [QUERY]: ...
user avatar
  • 539
2 votes
1 answer
26 views

Vimscript - Prevent Column From Moving When Using a Count

When you use a count to a key mapping it goes down count number of times and resets to column 1. Actually it already resets to col 1 when entering the function if there is a count. So I can save the ...
user avatar
0 votes
0 answers
16 views

How can I have my mapping handle a count in a function? [duplicate]

I wrote the following filetype plugin. It comments out lines in shell scripts by typing <leader>c. The problem is when I execute the mapped command multiple times by writing for example 4<...
user avatar
1 vote
0 answers
40 views

Vim local statusline doesn't set up correctly upon open new window

I tried to write a small script to give the statusline distinguishable appearance on current and non-current window. The local active and inactive statuslines are defined by the following code: ...
user avatar
  • 11
1 vote
1 answer
24 views

Is it possible to only change the guibg of the current window?

As title. Say I have 2 (vertical) window splits, I just want to change the background color of the right one. Is this even possible? If so, How?
user avatar
  • 721
0 votes
0 answers
12 views

Source script on a specific filetype without .vimrc modification [duplicate]

Is there a mechanism that I can use in vim/gvim which lets me automatically source a specific script file when I open a file of certain type? I have a specific file format (a subtype of XML) and when ...
user avatar
2 votes
1 answer
39 views

How to get file type by buffer number?

As title. Currently, I only have the buffer number, I need to know which filetype it is.
user avatar
  • 721

1
2 3 4 5
28