Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. 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
2 votes
1 answer
40 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
  • 731
0 votes
1 answer
15 views

Is this :compiler script configured properly for pylint, a python linter?

I am pretty new to Vim and coding in general. I'm trying to improve my compile-edit-compile cycle for Python. I just learned about Vim's :make and quickfix system; it's really cool. I would like to do ...
user avatar
1 vote
1 answer
54 views

How to use `%` to jump between single quotes?

As title. I have tried change this option: matchpairs but the result is weird: it will jump to all previous ' if pressed multiple times
user avatar
  • 731
0 votes
0 answers
19 views

Detect new visual selection with vimscript

I asked a related but different question here. I'm writing the vim-visual-history plugin that keeps a traversable history of previous visual selections. To detect the selections, I'm using: autocmd ...
user avatar
  • 866
1 vote
1 answer
33 views

How to detect the previous buffer via '#' exist?

As title. I'm trying to call bd # while it fails when the previous buffer doesn't exist. So my question is how to detect this?
user avatar
  • 731
0 votes
0 answers
18 views

String comparison using 'ignorecase' option in vim9 script

I am trying to port my legacy script to vim9. I found this in vim9 help: The 'ignorecase' option is not used for comparators that use strings. I am looking for a good workaround to use 'ignorecase' ...
user avatar
  • 246
7 votes
2 answers
1k views

Why is Vim9 mentioned at all in the doc of Vim 8?

Looking for lambda in the doc, I've found out (to my surprise) that they do exist in vimscript, and they use the syntax {args -> expr1}. But I've also discovered that there's Vim9, the doc of which ...
user avatar
  • 1,572
1 vote
0 answers
15 views

Vader for testing plugin that eases window navigation

Some time ago I wrote a plugin for easy window navigation, and now I was trying to write some test for it, using Vader, which I knew nothing about until a few hours ago. Basically, with my plugin ...
user avatar
  • 1,572
0 votes
1 answer
49 views

Vimscript: how to detect selection of a text object in visual mode?

I'm writing what may become a plugin that needs to know what is currently visually selected. To do it, I'm using the autocmd CursorMoved event to detect the creation of visual mode selections on the ...
user avatar
  • 866
1 vote
1 answer
24 views

Where is the `end_lnum` field of the item in `setqflist`?

As title. In :h setqflist there is no field end_lnum and end_col. While these options exist in :h getqflist . So my question is simple: If I cannot set it, how can I get it?
user avatar
  • 731
0 votes
1 answer
44 views

How to test for normal execution exit code?

func! ShouldReformat() return normal :w !elm-format --stdin --validate endfunc func! Reformat() if ShouldReformat() normal gggqG endif endfunc But return normal is not taken into account, ...
user avatar
0 votes
1 answer
72 views

Is there a way to let sqlformat or another SQL formatter change only a selection within a file in VIM?

I added a shortcut in VIM so that I can press Esc and ,pt to get the automatic sql formatting from sqlformat command. Taken from Can VIM autoindent SQL?. "autocmd FileType sql call SqlFormatter() ...
user avatar
0 votes
2 answers
22 views

How to get the parent path of a given path?

As title. For example if I have this: foo/bar/baz/bee which is stored in a variable, then which function should I call to get: foo/bar/baz Notice that I will need to store this result back to the ...
user avatar
  • 731
0 votes
1 answer
33 views

How to pass arguments to `:map gx <Plug>(SomeFunction)`?

Context I'm evaluating https://github.com/tyru/open-browser.vim which looks really promising. I figured out how to set the default search engine and add a mapping " vim-openbrowser let g:...
user avatar
0 votes
1 answer
123 views

Compile C++ in vim

I want to make a shortcut for compiling C++ file. I use :map <F5> :!g++ % -o app && ./app <CR>. How can I edit it to set output file's name, C++ file's name without .cpp instead of ...
user avatar
0 votes
1 answer
56 views

How to `source` a path stored in a variable in Vimscript

tldr: The title pretty much summarizes the entirety of the question I am trying to make my configuration more adaptable to different machines so that I can use git to keep them in sync between my ...
user avatar
1 vote
1 answer
27 views

How to check if the current tab is the last tab?

As title. I want to check that if current tab is the last (rightmost) tab, how?
user avatar
  • 731
0 votes
1 answer
46 views

How to check if a buffer hidden in all tabs?

As title. I want to check that a buffer is not shown in any tabs. How to do so?
user avatar
  • 731
0 votes
1 answer
65 views

How can I switch to the `[No Name]` buffer

As title. Is it possible to change the current buffer by vimscript to the (only) [No Name] buffer? I need these tools: an API to return all (loaded) buffers loop through each of them if the buffer ...
user avatar
  • 731
0 votes
2 answers
51 views

How could I create a terminal window in the background?

I want vim to launch rails console(it's like relp) within terminal windows when vim is launched on my project directory. To launch rails console, I need to run three commands like below and it's ...
user avatar
1 vote
1 answer
48 views

Re-Select Previous Visual Selection with Command

As title. I want to create a function that facilitate this behaviour. I have tried this but it didn't work: exe 'gv' I tried from this direction because this works: exe 'c!'
user avatar
  • 731
0 votes
1 answer
24 views

Place visual selection inside of a variable inside of a command

I want to write a command that works with a visual selection, so I wrote something like this: command! -range Foo \ exec "norm \"ay" | \ echo "[" . @a . "]" ...
user avatar
  • 193
4 votes
2 answers
61 views

Advice on the use of :exe "norm!" vs. built in functions when writing vimscipt and plugins

I've been using vim for about 3 years and am starting to write my first plugin. I've noticed when looking at the code of other popular plugins that the functions very rarely seem to achieve their aim ...
user avatar
  • 866
0 votes
1 answer
55 views

NeoVim: How to move the cursor to a window by its window number?

As title. After doing windo it seems like Vim forgot where it started.
user avatar
  • 731
1 vote
2 answers
52 views

How to count the total number of windows excluding some buftype?

As title. Some floating windows will have buffer type (buftype) value nofile, I don't want to count them! How?
user avatar
  • 731
0 votes
1 answer
31 views

How to count the total number of splits opened in the current tab?

As title. I want to detect the case when there is only one split in the current tab.
user avatar
  • 731
0 votes
0 answers
39 views

vim execute not working in script

I am using a plugin that expands the word template by a template but only if the word template is followed by a tab. I am trying to write the word new then in insert mode jump to the end of the line ...
user avatar
0 votes
0 answers
33 views

activate vim-lsp on single JavaScript files

vim-lsp's typescript-language-server doesn't seem to work or get activated when working on single JavaScript files or projects that are (I think) under version control. Is there a way to configure ...
user avatar
0 votes
1 answer
549 views

Neovim 0.5+ setup as Rust IDE

So I am trying to set up neovim 0.5+ as a rust IDE. I am following this guide. Except, as shown in the guide, there is not completion even after doing <c-x><c-o>. I have kept the config in ...
user avatar
0 votes
1 answer
92 views

Vimscript - Loading function(s) from another .vim file

I'm forking an old vim plugin (effectively dead since 2018) that needed some love. Once I got to the .vim file, I noticed that the functions were all defined in there, which made the file unreasonably ...
user avatar
  • 1
1 vote
2 answers
42 views

How to center the current line to 80% height of the current window, in NeoVim?

As title. Since no one wants to become a turtle, I want to setup a behavior like M but instead pin the current line to 80% height (0% start from bottom) of the current window, not to center.
user avatar
  • 731
0 votes
2 answers
58 views

Use command to move cursor like `^` and `$`, in NeoVim?

As title. How to move the cursor with vim command :...? I want to make a toggle that achieves this behavior but I didn't find anywhere this is explained :(
user avatar
  • 731
2 votes
0 answers
46 views

Make Lightspeed work with Repmo

I'm trying to make the EasyMotion-like (cursor jumping) Lightspeed plugin work with Repmo which repeats a previous motion. So far, (and after many hours), I've come up with the following: let g:...
user avatar
  • 2,221
1 vote
1 answer
49 views

How to cancel quitting in a QuitPre autocmd

I want to write an autocmd that prompts the user when the user tries to quit Vim. Based on the user's response, Vim should either quit, or cancel the quit. Is this possible using QuitPre? If not, how ...
user avatar
  • 801
3 votes
1 answer
92 views

Sort tab-completion suggestions (files first, then directories) in vim command line

When i go to command mode, type :e and press tab, i get like this Excuse the file, directory writings on the right side (used for explanation) A.cpp file Adamwathan/ directory ...
user avatar
  • 111
3 votes
1 answer
81 views

What values are truthy and falsey?

What are the truthy and falsey values in classic vimscript (not vim9script)? What is the canonical list, and where do I find it in :help?
user avatar
  • 2,221
0 votes
1 answer
19 views

Set all highlight groups starting with a certain name?

Basically I have a long list of highlight groups that start with DevIcon (DevIconPng, DevIconJs etc.), they all come with their own ctermfg and guifg and I would like to change them to a single color. ...
user avatar
0 votes
0 answers
37 views

The dilemma of using both space-tab and tab

Now I have to learn some makefile. I only need to use the plain-old tab in this file. In other ones I want to happily keep my 4-space-tab. My current idea is to find a way/script so that I can toggle ...
user avatar
  • 731
2 votes
1 answer
62 views

How to overlap searching result?

Given that I have string AABBAABBAA. I cannot find two AABBAA with the / that vim provides. Is there any option to enable this behaviour or I need a script/plugin?
user avatar
  • 731
0 votes
0 answers
31 views

How to determine the cursor is close to the last line of the file?

As title. I have the following script and I want to set scrolloff to 0 when the cursor is approaching the last line of the current file. vim.cmd [[ augroup switchScrolloffTopBottom autocmd! ...
user avatar
  • 731
3 votes
1 answer
208 views

How to check if value is v:null?

What is the proper way to check if a particular variable is null? I use v:null as a special value to indicate something in a custom function's return value. I have tried: let l:v = v:null echom l:v == ...
user avatar
1 vote
1 answer
33 views

BufDelete running after window is closed

For some reason, the BufDelete autocommand is being executed right after a window is created, instead before, and i think it shouldn't be like that, according to the docs: Before deleting a buffer ...
user avatar
1 vote
1 answer
46 views

Is it possible to set scrolloff to top and bottom with different values?

As title. For example, say I imagine there is something like scrolloffTop and scrolloffBottom and I can set each with different values. If there is no such options, I would like to know is it possible ...
user avatar
  • 731
1 vote
2 answers
39 views

-complete=file without extra processing of the arguments

Without -complete=file: command! -nargs=* C1 echo <q-args> C1 fzf#vim#grep /home/yuri/.vim/pack/foo/start/fzf.vim " fzf#vim#grep /home/yuri/.vim/pack/foo/start/fzf.vim With -complete=file: ...
user avatar
  • 339
0 votes
0 answers
43 views

Auto update a buffer opend in a split when it changed?

I'm writing TypeScript and there is a command npx tsc --watch that will (over)write to an output file every time the source file is changed. I open one split for each of these files. But when I save ...
user avatar
  • 731
0 votes
1 answer
51 views

vim. How do you replace 'x' with 'y' and 'y' with 'x'? [duplicate]

I don't want to do this manually, and I'm sure there is a way for vim to do it. I probably am not googling the correct question to find the result I want, but here is what I want to do. I have this ...
user avatar
1 vote
1 answer
69 views

`:call append!` -- how vim insert line (append or setline) while respecting indentation

I want to put a string function output in my vim when press xx. My current working example is: nnoremap <silent> xx :call append('.', 'string_output')<CR> However, this put a line without ...
user avatar
  • 25
1 vote
2 answers
61 views

How do I suppress beginning newline added by put()?

I've got this simple function: " generates a link in markdown using an extern script function! WebLink() put =system('~/bin/taskwiki_helper.pl markdown_link_from_url') endfunction It works ...
user avatar
  • 1,237
3 votes
1 answer
220 views

Can the arguments to a custom Vim command be grouped by quotes?

I would like to define a custom Vim command that takes arguments grouped by single or double quotes. For example, if my arguments are a "b c" then I want a to be considered the first ...
user avatar
1 vote
0 answers
153 views

ALE project root for Python

I use ALE to run linters while editing Python code in vim. When working on code in a package, I can't get ALE to respect the pylint configuration in the project root. I've had it in .pylintrc as well ...
user avatar

1
2
3 4 5
28