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
1 vote
1 answer
50 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
  • 771
0 votes
1 answer
33 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
  • 203
4 votes
2 answers
64 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
  • 995
0 votes
1 answer
145 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
  • 771
1 vote
2 answers
60 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
  • 771
0 votes
1 answer
64 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
  • 771
0 votes
0 answers
50 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
40 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
679 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
173 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
69 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
  • 771
0 votes
2 answers
66 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
  • 771
2 votes
0 answers
49 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,281
2 votes
1 answer
66 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
  • 811
3 votes
1 answer
96 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
  • 121
3 votes
1 answer
114 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,281
0 votes
1 answer
23 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
41 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
  • 771
2 votes
1 answer
64 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
  • 771
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
  • 771
3 votes
1 answer
342 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
42 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
56 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
  • 771
1 vote
2 answers
45 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
50 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
  • 771
0 votes
1 answer
57 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
112 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
63 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,257
3 votes
1 answer
274 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
223 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
0 votes
1 answer
50 views

Generate relatively unique "cache filename" for given file path (like swap files do)

For each filename, Vim generates (relatively) unique filename for it's swap cache directory. Let's say I would like to store some information for each file (like swap files do), e.g. with : silent ...
user avatar
0 votes
1 answer
57 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 ...
user avatar
1 vote
1 answer
55 views

Echo filename before deleting buffer

I would like to echo the filename before deleting any buffer (:bd, :q). I wanted to achieve this by using auto-commands like this: augroup DummyCodeGroup autocmd! autocmd BufDelete * lua print(...
user avatar
  • 113
0 votes
2 answers
21 views

Insert mode <S-Tab> to delete one <Tab>-indent?

I want to use <S-Tab> to do the reverse of <Tab> in insert mode in Lua. (If this is complicated in Lua then VimScript is OK) How?
user avatar
  • 771
2 votes
0 answers
50 views

Constant-update Words Per Minute in Vim?

I'm interested (mostly just for fun) in seeing my typing speed while working in Vim. I saw this post but this requires starting and stopping a function. I would prefer this to be a constantly updating ...
user avatar
  • 21
1 vote
1 answer
35 views

How to get activated current `b:keymap_name` value

I have a below line set keymap = russian-jcukenwin.vim in .vimrc. When I press C-^ I get indicator in mode line , like INSERT (RU). I'd like to output it in lightline vim config, and there is %k flag ...
user avatar
  • 13
0 votes
1 answer
79 views

Is there a vim that uses python instead of vimscript throughout?

There is a vim plugin that allows even the .vimrc to be composed in lua. But I would prefer python. Does anyone know of such a plugin or version of vim that uses python throughout the internals, ...
user avatar
4 votes
1 answer
914 views

What is the difference between "==" and "is" for checking the equality of strings?

What is the difference between == and is; ==# and is#; ==? and is? when checking whether or not two strings are equal? Sometimes I see foo is# 'bar', and I wonder whether or not it is always ...
user avatar
  • 811
0 votes
1 answer
92 views

How to replace selected text T with some function(T), using a keyboard shortcut?

I want to annotate words /sentences for a "named entity recognition" purpose; inside a text file, I want to annotating words or sentences with this format [pattern](label): [a word where the ...
user avatar
0 votes
1 answer
186 views

Vim editor entities tagging/annotation tool

I'm looking for a word/sentence annotation tool/plugin to be used INSIDE vim editor. Specifically I'm looking for a cli tool NER (named entity) tagging. Any idea/suggestion/tip? By example, I would ...
user avatar
0 votes
0 answers
69 views

in vimscript how to write the code a CTRL-C to be executed

I run a sourced vimscript like this: exec 'g#' . WE_var_searchmode . ' ' . WE_var_pattertosearch . '#exec " A | B | C | make_CTRL-C | ... | LAST " ' The outer execute '...' is needed to ...
user avatar
1 vote
1 answer
30 views

Is there a way for Vim to re-source all the startup files without quitting and re-starting?

I write a lot of Vim plugins. When I make an edit to a plugin's .vim file, I'll often just quit Vim and restart it to test it. In some cases, I would like to avoid quitting and restarting Vim. I ...
user avatar
0 votes
0 answers
119 views

vim problem when in "try" ... "catch" an "if" is between

When a vim script is to be watched for errors and interrupts, try is put somewhere near the beginning and catch after a long sequence of code. In this sequence of code it is very probable to have some ...
user avatar
0 votes
1 answer
49 views

How can I execute a piece of selected lines on terminal with a mapped command?

I've created the following script on my vimrc file: function! ExecuteOnTerminal() if (&ft=='javascript') :%terminal node elseif (&ft=='sh') :%terminal bash elseif (...
user avatar
  • 385
0 votes
1 answer
70 views

how to install this? NerdTree visual selection

I've been trying to install this package called nerdTree-visual-selection. It is a package that 'defines key mappings that will work on nodes contained in a Visual selection in NERDTree'. It was weird ...
user avatar
0 votes
1 answer
42 views

How to (1) get depth of execute-nesting and (2) interrupt the global command?

From a sourced file I am running my vim script. The aim of the script is to run :global. I am searching for \\%(pattern1.*/)\@<!pattern2 The patterns are variables, so I use execute; for the work ...
user avatar
2 votes
1 answer
265 views

How to async run vimscript system calls

I have a vimscript function which uses a combination of vimscript functions and also some calls to :call system(). The vimscript and the system() calls can be 5-10 seconds slow, during which time, Vim ...
user avatar
1 vote
1 answer
71 views

How to glob the buffer-list?

Having a command: command! -nargs=+ Foo call s:my_fun(<f-args>) How can I get a glob-match when user say: Foo *met*.c ?
user avatar
0 votes
1 answer
30 views

Executing settings based on directory during startup

I am trying to execute some custom settings based on the directory on startup. For this I am trying: autocmd VimEnter /path/to/dir/* :source /custom.vim When I now execute: cd /path/to/dir vim I ...
user avatar
  • 123
0 votes
0 answers
15 views

Handling softlink directories in Windows

I'll edit the title as soon as I think of a way to succinctly word my question. I have the following for my statusline: set stl=%{expand('%:~:.') It gets the current filename's fullpath and truncate ...
user avatar
  • 3,082

1 2
3
4 5
28