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
2 answers
274 views

How would I remove all text outside single quotes in VIM using regex?

I'm using a vim script to quickly edit some text. I have a large list from an api endpoint that looks like this: save: presets.api + 'campaign/:campaignId/settings', ...
ex7lted's user avatar
  • 37
0 votes
1 answer
104 views

Get number of warnings and errors from the current location list in vimscript

I am using ALE as LSP client, and I would like to write a function to get the number of errors and warnings from the current location list. I think that a possible solution would be to write a ...
Barzi2001's user avatar
  • 506
1 vote
1 answer
505 views

What's the reverse action of ctrl-y?

As title. Just like the case where <C-n> and <C-p> is a pair. I would like to know how to scroll down one line at a time.
NeoZoom.lua's user avatar
  • 1,392
0 votes
1 answer
135 views

Yank list of lines into a register in vimscript

I am writing a function and I wish to yank a range of lines into a register. The line that I cannot fix is the following: let @" = getline(l:line_in,l:line_out) where l:line_in and l:line out ...
Barzi2001's user avatar
  • 506
1 vote
1 answer
215 views

get line numbers /something and ?something

I am moving the first steps in scripting and I am facing this issue. Say that I have a test like the one below 1 bla bla bla 2 3 .. 13 SOME KEYWORK 14 blah blah blah 15 .. .. 21 SOME KEYWORK 22 ...
Barzi2001's user avatar
  • 506
0 votes
1 answer
79 views

What asterisk means before variable name in exists() function?

"filetype.vim" has line: if exists("*fnameescape") What '*' means here? Is it suppose to dereference any value?
l00p's user avatar
  • 253
2 votes
1 answer
162 views

How can I store the number of regex matches in a variable?

In Vim Script, I want to check for the amount of matches from a regular expression (/\%^\n*) and store the amount of matches in a variable. I this possible?
Amarakon's user avatar
  • 261
0 votes
1 answer
64 views

How to get the command short form for custom commands?

The built-in Vim command have a nice property. You have only to type as much such that Vim can guess the command. For :cclose you can type: :ccl :cclo :cclos :cclose Is there a way to get the same ...
Vivian De Smedt's user avatar
2 votes
1 answer
151 views

Open JIRA issues from inside Vim based on JIRA tag

I just learned about the gx command to open URLs from Vim. Is there a way to do the same thing based on the highlighting. For example, I have this match rule to hightlight JIRA issues: syn match ...
Stephen Rasku's user avatar
2 votes
1 answer
2k views

How to call a command with remapping in neovim?

Say I have a normal mode mapping on key P, for sure it can be executed in command mode: :lua normal! P Now I want to do this in lua, so I tried: vim.cmd('normal! P') and NeoVim executed it as "...
NeoZoom.lua's user avatar
  • 1,392
0 votes
1 answer
66 views

vim-airline customization: parse substring from current branch name

We're formatting our branch name like feature/HD-1234_tiny_description where "1234" refers to a Jira ticket number. I'd like to only display this number in vim-airline (along with vim-...
Sumak's user avatar
  • 103
0 votes
1 answer
409 views

Using Lua, how can I run a function whenever the cursor moves?

I want a function to fire whenever the cursor moves. How can I do this?
White's user avatar
  • 3
3 votes
2 answers
707 views

Detecting the Enter and Leave of Visual mode event

Are there any events similar to InsertEnter and InsertLeave that I could use for visual mode? Looking through the helpfiles, I did not fine any. If not, how would I be able to detect if Vim enters or ...
unrealapex's user avatar
0 votes
1 answer
61 views

Vim: cursor manipulation in help file

So I want to be able to automatically open help files in a new tab. I saw a question on this SE that pretty much solved my problem. I wanted to make just one change: center the screen. "That will ...
Dominik Teiml's user avatar
2 votes
1 answer
121 views

How to "Set previous context mark"?

From the vim manual: m' or m` Set the previous context mark. This can be jumped to with the "''" or "``" command (does not move the cursor, this is ...
pigeon's user avatar
  • 25
5 votes
3 answers
886 views

How to check if an autoload function exists without calling it?

Say I have vim-plug installed But before calling call plug#begin(), I want to check if this function exists How to perform this check? I tried the following: echom empty(g:plug) echom empty(plug) ...
timetowonder's user avatar
2 votes
1 answer
431 views

What does runtime! debian.vim actually do?

The vimrc template I used had the message "Ensure options work with the Vim-related packages available in Debian." for runtime! debian.vim Here is the contents of /usr/share/vim/vim81/...
qwr's user avatar
  • 183
5 votes
1 answer
407 views

How can I convert vim8 function mapping to vim9?

I have a function in vim8 as: function! BSkipQuickFix(command) let start_buffer = bufnr('%') execute a:command while &buftype ==# 'quickfix' && bufnr('%') != start_buffer execute ...
BaRud's user avatar
  • 481
0 votes
1 answer
83 views

Vimscript: how to overwrite a variable that is inside an if block?

I have some code in a function like so: let branch = substitute(system('git rev-list -1 HEAD'), '\n', '', 'g') let num_branches = system('echo `git branch --contains '.branch.'` | wc -l') if ...
Jin's user avatar
  • 185
1 vote
1 answer
115 views

How to make gf replace "res://" prefix with project root?

Godot scripts sometimes contain lines like: extends "res://cars/driveable.gd" If my project is in c:/project, then that line refers to the path c:/project/cars/car_base.gd. How can I make ...
idbrii's user avatar
  • 641
2 votes
2 answers
50 views

Function for recursive linebreak

I am writing my .tex files in vim and have automatic linebreaks at 80 characters. I would like the linebreak to automatically perform a concatenation J if there is text below it, so that I don't get ...
Andrew Draganov's user avatar
0 votes
0 answers
510 views

Cannot find colorscheme in neovim

I am a very very new user of neovim and i was trying to customize it using init.vim. When i was trying to set a color theme for neovim, it did not work. I am using vim-plug and i have the plugin in ...
stove's user avatar
  • 1
1 vote
4 answers
1k views

Cannot switch tabs when in terminal tab

For using the terminal while working with Rust. I've added this config (NVIM) (TTerm one). if has('nvim') command Ter vsplit term://zsh command Tter tabe term://zsh else command Terminal ...
Sahil Sonawane's user avatar
0 votes
2 answers
477 views

How can I get the active window in a tab?

For example, if I do: % vim file :tabedit one :split two I end up with two tabs, and one tab with two windows. How can I get the active window of the second tab? My goal is to get a list of all tabs ...
Martin Tournoij's user avatar
0 votes
1 answer
48 views

How to enforce a specific order for the windows opened by diffsplit?

Calling diffsplit {filename} opens the new file at the top and the current file at the bottom. Similarly, the vertical version opens the new file on the left and the current file on the right. Is it ...
Matt's user avatar
  • 177
0 votes
1 answer
195 views

How to change editor options when switching to diff mode?

I have a few options I like to apply both when Vim is opened in diff mode and when it is switched to diff mode, e.g., when calling diffsplit. I have the following lines in my ~/.vimrc: command! -nargs=...
Matt's user avatar
  • 177
1 vote
1 answer
99 views

Certain commands in vimrc not being picked up anymore

I am having an issue where anything I enter into my .vimrc file is not being picked up, regardless of how many times I add it / close the file / re-open it, etc. Here is the most basic example of what ...
samuelbrody1249's user avatar
0 votes
2 answers
500 views

How to read Vim stack trace?

When debugging Vim plugin you may be confronted to error messages of the kind: Error detected while processing function GrandFather[2]..Father[5]..Son Line 6: E484: Can't open file foo.txt What ...
Vivian De Smedt's user avatar
1 vote
1 answer
149 views

Execute command inside if

I use fzf.vim plugin and I want to map Ctrl-P: If the file is part of a git repo, then I want to use the :GFiles command (to show all files from the root directory of project). If there is no git ...
moskalenco_a's user avatar
2 votes
3 answers
212 views

How to check if the last executed command was *this* function?

I want to write a function which allows me to execute different movement commands using the same key pressed repeatedly. So, I wrote a function Jumptails and mapped it to the key <End>. The ...
Tom's user avatar
  • 43
3 votes
0 answers
66 views

When editing vim script files (*.vim), line continuations are not highlighted properly

When I edit VIM syntax highlighting definitions or any other VIM script file (*.vim), I lose syntax highlighting on lines that are continued from the previous one. For example, syntax region ...
karlh's user avatar
  • 405
1 vote
2 answers
576 views

How to remove underscore and capitalize the next character in the first word?

I want to modify the first word of each line: remove underscore character and capitalize the next character. Input: word_example_one other_words ... word_example_two other_words ... ...
Fisher's user avatar
  • 1,086
2 votes
2 answers
238 views

How can I use `:keepjump` with `gd`/`gf`/searches?

I know that plugin that can do it almost certainly exists. Or maybe I could use something like LSP for this. But I want to make my simple command, that will go to file with definition of component / ...
moskalenco_a's user avatar
1 vote
1 answer
159 views

Automatically highlight visual selection matches

Since there are no VisualEnter and VisualLeave events, I am trying to make a function that will activate on every cursor movement in visual mode, i.e. it will automatically highlight all the matches ...
lobelk's user avatar
  • 21
7 votes
1 answer
810 views

How to learn vimscript along with vim9script?

I've finally made the decision to learn vimscript. I don't hate reading manual and really like the built-in help files, so I am starting with usr_41.txt and plan to read eval.txt afterwards. Now as I ...
Masquue's user avatar
  • 81
1 vote
1 answer
79 views

bind/map a call to win_gotoid with script level argument

I'm trying to set a nmap bind to make the focus change from Window B back to Window A. Both Window IDs are store at the script level: s:win_id_a and s:win_id_b. The current snippet I've is the ...
Moraes's user avatar
  • 115
0 votes
1 answer
19 views

Plugin Dev - Keeping Track of Windows inside a single Tab

I'm trying to build a new plugin and I got myself a question about managing multiple windows inside a single tab (hope the terms are correct). So far the examples and projects I've explored trying to ...
Moraes's user avatar
  • 115
0 votes
1 answer
60 views

mkview file code meaning

I use :mkview %.vimview to create a view file under current directory, and in the file created there is a line of code like this: if bufexists(fnamemodify("~/PycharmProjects/rl/report/...
Jiang Yuanhao's user avatar
0 votes
0 answers
19 views

vimscript does not print anything if lines to be printed are less than a screen full

I have the following vimscript: #!/usr/bin/env vim -S let i=1 while i<10 echo "Value of i is: " i let i += 1 endwhile q When I save it in a file with +x and try to run ...
Ketan's user avatar
  • 265
0 votes
1 answer
39 views

Opfunc inserts text before cursor position sometimes

function! s:Surround(motion = "") abort let [_, l:start_row, l:start_col, _] = getpos("'[") let [_, l:end_row, l:end_col, _] = getpos("']") let l:before = &...
Big McLargeHuge's user avatar
0 votes
1 answer
154 views

How can I open a vim fold so that it is not affected by `foldclose=all`?

In my config file I have set foldclose=all so that folds get automatically closed upon cursor leaving them. However, sometimes, I want a specific fold not to close for a while. Because folds below ...
lobelk's user avatar
  • 21
2 votes
1 answer
278 views

open several files into same buffer

I have several file paths saved in a register. I would like to open them all into the same new buffer. (as if I ran cat * files | vim - from command line. As this is part of a plugin, I would like to ...
Matthew Webb's user avatar
0 votes
1 answer
216 views

How to restore cursor position after the document is reformatted?

I'm reformatting an XML document with an external command from a vimscript function which accepts a range, and I need the cursor to stay at the same line it was before the reformatting. When trying ...
Tomáš Bažant's user avatar
1 vote
1 answer
75 views

apply conceal to already defined syntax

I created my own syntax file tailored to UVM log files, in which each line is formatted in the same way: <msg severity> <path>(<line number>) @ <simulation time>: <hierarchy&...
Nimrod Weinberg's user avatar
0 votes
1 answer
341 views

Vim Autoindent does not work [closed]

I'm configuring my Vim editor. Now I want it to automatically indent when I press enter after a parenthesis (like in modern IDEs) function test() { | } I already have autoindent and smartindent ...
ttatoni26's user avatar
2 votes
2 answers
56 views

Save all lines of a terminal buffer into a list after its job finishes

I need to save all lines of a terminal buffer into a list after its job finishes asynchronously. I,m opening the terminal buffer like this: let term_buf_no = term_start(cmd, {'term_name': name, '...
Tomáš Bažant's user avatar
0 votes
1 answer
113 views

Re-use or close vim terminal buffer on next command run

I'm opening a terminal buffer for my XML validation with the following command: let term_buff_no = term_start(validate_cmd, {'term_rows': 10}) However, when running the same command again, a new ...
Tomáš Bažant's user avatar
2 votes
1 answer
171 views

How to keep focus in the "normal" editing buffer while a terminal buffer is opened and running a command?

I am editing a DocBook XML file and want to validate it by running a custom command validate_cmd. In my plugin, I'm running the following: let term_buff_no = term_start(validate_cmd, {'term_rows': 10})...
Tomáš Bažant's user avatar
2 votes
2 answers
613 views

Controlling Vim from outside

Is there a way to control the opened instance of Vim from outside? Let me clarify, I saw many posts about controlling an external program from Vim by simply executing commands on special key strokes ...
vdegenne's user avatar
  • 121
2 votes
1 answer
224 views

How to create window split for the current tab?

As title. Say I have three splits top, middle, bottom. I want to create a new split from the bottom(so the result will be top, middle, bottom, new_bottom), even if my current is at either top or ...
NeoZoom.lua's user avatar
  • 1,392

1 2 3
4
5
32