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
0answers
12 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:...
3
votes
1answer
2k 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
18 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 ...
0
votes
1answer
29 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 ...
2
votes
3answers
333 views

Write buffer list to file

I would like to have a file that contains all files that I opened with vim in the past. I know that there is the viminfo file but I want to have just a file with the filenames. For this I would like ...
0
votes
2answers
27 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 ...
0
votes
1answer
18 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?
0
votes
1answer
26 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 ...
0
votes
1answer
16 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?
0
votes
1answer
41 views

How to get the union/merge of dictionaries?

I'd like to combine two nested dictionaries following these rules: if value is not a dictionary, override the key in resulting dictionary if value is a dictionary, compute union of the two. Example: ...
4
votes
2answers
55 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 ...
0
votes
1answer
37 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!'
19
votes
7answers
4k views

How can I source a visual selection of vimscript?

If I have a couple of lines of vimscript that I want to test before putting in my vimrc, is it possible to visually select, then source them? I have tried make visual selection v, then motions to ...
0
votes
1answer
100 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! s:my_n() let l:start=line("w0") let end = line("w$")...
0
votes
1answer
21 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 . "]" ...
0
votes
1answer
80 views

Useful script to manage buffer and window?

I want to create a vertical split from current buffer for reference another file/the same file. After I've done with this split I don't want to see this buffer-for-reference in the split, but: If ...
4
votes
2answers
105 views

Get first and last visible line from other buffer than current

I know that I can get the first and last visible lines in the current buffer by using line('w0') and line('w$'), but is there a way to do it for other buffers that are visible but not active as well? ...
1
vote
2answers
46 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?
2
votes
0answers
41 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:...
0
votes
1answer
18 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.
0
votes
1answer
20 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.
3
votes
3answers
3k views

What's the difference between call and execute?

E.g., in this snippet if words[0] == "\"spellgood:" call remove(words, 0) for word in words execute "silent spellgood! " . word endfor endif taken from "The first ...
0
votes
0answers
26 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 ...
0
votes
0answers
20 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 ...
0
votes
1answer
103 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 ...
0
votes
1answer
30 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 ...
0
votes
1answer
44 views

Get path to parent directory and use it in a nnoremap command?

Say I have a nnoremap and I want to pass the path of parent directory of current file to it, so the command can use this information. I have read this answer: How can I see the full path of the ...
0
votes
1answer
233 views

How to get the buffer type of the current buffer?

I'm writing mapping, and I want to decide whether I have to do additional actions when current buffer type is a drawer called Fern, here is my command currently nnoremap <nowait><silent> ; ...
0
votes
2answers
40 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 :(
1
vote
1answer
21 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.
3
votes
1answer
46 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?
1
vote
1answer
32 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 ...
3
votes
1answer
78 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 ...
0
votes
1answer
29 views

Display extra column before/after line numbers and modify using Vimscript

How to display extra column before/after line numbers , and modify , programmatically, using Vimscript? Maybe some examples of existing plugins doing so, that I could base of? (this could be great ...
7
votes
2answers
1k views

Is there a way to get the name of the current function in vim-script?

Is it possible to programmatically let a function knows its own name? What I am looking for is something which would allow me to write this code (or something similar): function! myUtils#TestMe() ...
0
votes
1answer
18 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. ...
0
votes
0answers
35 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 ...
3
votes
1answer
59 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 == ...
2
votes
1answer
56 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?
0
votes
0answers
28 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! ...
1
vote
1answer
28 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 ...
1
vote
1answer
36 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 ...
1
vote
2answers
34 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: ...
0
votes
0answers
37 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 ...
0
votes
1answer
39 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 ...
1
vote
1answer
23 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 ...
1
vote
2answers
59 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 ...
1
vote
1answer
69 views

How to detect whether the current line is empty line?

I want a command mapping to detect whether the current line is blank, and perform a different action for each case it detects: true of false. How do I do this?
0
votes
1answer
33 views

How to test if the current file is in some directory?

I want to have a piece of vimscript (a custom formatter) only apply if the current file is inside some directory. How can I tell whether the active buffer is within a particular directory?
0
votes
1answer
147 views

Solving issue with clang-format-vim.py saving new buffer

Summary I configured vim to call clang-format.py following the steps in the clang documentation for vim integration. But when I save a new buffer the plugin fails. I'm new to vimscript and trying to ...

1
2 3 4 5
27