7 votes
Accepted

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

Because Vim9 has not been formally released yet, but the features are ready to try out in the latest Vim8 releases. If you see it in the help, then you can use it two ways: The Vim9 script syntax and ...
user avatar
5 votes
Accepted

silent vs. silent! - What is the difference?

It's explained in :help :silent *:sil* *:silent* *:silent!* :sil[ent][!] {command} Execute {command} silently. Normal messages will not be given or added to the ...
user avatar
5 votes
Accepted

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

In the :help cmdline-completion section, see this paragraph discusses suffixes *c_CTRL-D* CTRL-D List names that match the pattern in front of the cursor. When ...
user avatar
5 votes
Accepted

How to get file type by buffer number?

You can use getbufvar() to get a variable definition, together with the '&filteype' syntax to get the value of an option rather than a variable. :echo getbufvar(2, '&filetype')
user avatar
  • 26.2k
5 votes
Accepted

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

You don't need backslash in map command. Simply let g:key = "\<C-j>" inoremap <expr><C-j> g:key UPD. It looks as if you want :h nvim_replace_termcodes() function available ...
user avatar
  • 16.9k
5 votes
Accepted

Is it possible to break out of nested loops?

There is no goto in vimscript [1]. Like most languages that lack goto, you'll need to handle this using a variable: let breaking = 0 for i in range(3) for j in range(5) echo i j ...
user avatar
  • 12.8k
5 votes
Accepted

How to learn vimscript along with vim9script?

The main point of vim9script is to allow Vim plug-ins to access better performance for operations that are typically too slow to perform in the traditional vimscript and historically have required ...
4 votes
Accepted

How I can add <C-6> to a mapping

<C-6> is a normal mapping (I guess you want to switch to alternate buffer). But the way you call it is incorrect -- calling it as an ex-command. Normal mode commands in vimscript should be ...
user avatar
  • 10.4k
4 votes
Accepted

Inserting strings with `<plug>` inside `<cmd>`

It is possible if you manage escaping rules very carefully. For example, nnoremap x <cmd>echo "<bslash><lt>Plug>MyWonderfulMap" v:count<cr> Then :map x prints: n ...
user avatar
  • 12.8k
4 votes
Accepted

How can I expand a:000 list in order to pass through all varargs parameters to another function?

Use :h call(): func! Bar(...) abort return a:000 endfunc func! Foo(...) abort echo call('Bar', a:000) endfunc call Foo('asdf', 'qwer') " --> ['asdf', 'qwer']
user avatar
  • 10.4k
4 votes
Accepted

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

While I was pretty sure the answer was "they are identical" I was only 99% sure so...I checked the code. Function eval4() in eval.c is the entry point for "expr4" operations, i.e. ...
user avatar
  • 18.4k
4 votes

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

The :put Ex command will always work linewise, which is actually described in :help :put: Put the text [from register x] after [line] (default current line). This always works linewise, thus this ...
user avatar
  • 26.2k
4 votes
Accepted

How to overlap searching result?

This is possible if you unset flag c in setting 'cpoptions' (alias 'cpo'). Absence of that flag is described thusly: When not present searching continues one character from the cursor position. With ...
user avatar
  • 18.4k
4 votes

What values are truthy and falsey?

TL;DR: Truthy: Non-0 Numbers (any integer but 0) Strings that convert to a non-zero number All strings starting with a digit which is not '0' Numbers not starting with '0', eg: -123 0x10 0177 ...
user avatar
  • 2,281
4 votes

How to cancel quitting in a QuitPre autocmd

Is this possible using QuitPre? "Quit" means quitting a buffer as in :quit. You probably want ExitPre instead. can I implement such functionality using Vimscript? No, AFAIK, the action ...
user avatar
  • 16.9k
4 votes
Accepted

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

I believe @VivianDeSmedt's comment refers to :help startup (notice that the vimrc is executed after files like plugin/*.vim and others have loaded). In general you cannot use a command until it has ...
user avatar
  • 21.4k
4 votes

How to format code in vim by some external commands?

I would suggest to use :h formatprg and gq normal command. For example, ~/.vim/after/ftplugin/json.vim if executable('jq') let &l:formatprg = "jq -e" elseif executable('js-beautify') ...
user avatar
  • 10.4k
4 votes

Controlling Vim from outside

For Vim you can use the --remote-send flag. It takes as an argument the Vim command that you would like to be executed. For example: vim --remote-send ":echo 'hello'<CR>" Will echo ...
user avatar
3 votes
Accepted

How to check if a dict has a specific key?

Use the has_key function: has_key(my_dict, 'abc') This will return 1 if the key is found, and 0 if the key is not found.
user avatar
  • 461
3 votes
Accepted

Vim 8.2 no user defined functions

There was a regression bug in 8.2.3337 and it was fixed yesterday.
user avatar
  • 10.4k
3 votes
Accepted

Window close event

vim v8.2.3591 added a WinClosed event.
user avatar
  • 146
3 votes
Accepted

How to quickly search for today's date in a file?

This will search for today's date: /<C-R>=strftime('%a %d-%m-%Y')<CR><CR> You can define a mapping to create a shortcut, for example, to search with <Ctrl>G in normal mode you ...
user avatar
  • 16.9k
3 votes

Moving to special marks inside opfunc

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work. I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do ...
user avatar
3 votes
Accepted

Moving to special marks inside opfunc

What I'm missing? :h '] "To the last character of the previously changed or yanked text." You must keep marks intact until you've done with all of them. Maybe :lockmarks or setline() or ...
user avatar
  • 16.9k
3 votes

Is it possible to detect if shiftwidth/tabstop/etc was set in modeline

You can install an OptionSet autocommand. If an option was triggered by a modeline, it will be in the special v variable: v:option_type. Note: there are a whole bunch of v:option... variables for all ...
user avatar
3 votes
Accepted

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

"No range allowed" is due to :silent that never accepts line range, obviously. If you need to silent your command while still accepting line range you have to employ some alternative. Maybe :...
user avatar
  • 16.9k
3 votes
Accepted

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

You can try reading the Vim :help python help page. There's a lot there to get started. It's not easy though. Caution... your version of Vim must be recent enough it must have been installed with ...
user avatar
3 votes
Accepted

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

The problem is that the syntax of quoting strings in order to include whitespace in them is somewhat foreign to Vim, particularly in a context such as user-defined commands, which typically take space-...
user avatar
  • 26.2k
3 votes
Accepted

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

In no particular order. Readability Any sequence of normals, except a very short one, is nearly impossible to read and understand. Vimgolf can't lie. Clobbering registers etc. Quite often there is ...
user avatar
  • 16.9k
3 votes
Accepted

Re-Select Previous Visual Selection with Command

To run normal mode commands as ex command use :normal! as in normal! gv Note, exclamation mark is for running non-mapped "built-in" functionality: :nnoremap l :echo "hello"<...
user avatar
  • 10.4k

Only top scored, non community-wiki answers of a minimum length are eligible