Skip to content

Instantly share code, notes, and snippets.

@girishji
girishji / vim9cmdline.md
Last active June 6, 2024 09:14
Vim Tip: Vim9script in Command Line

Note: This gist is now part of VimBits plugin.

As a Vim user, you might prefer the new vim9script over the legacy script, and wish to use it in the command line. While there's no direct option to switch the command line to parse vim9script, you can execute vim9script commands by simply prepending each command with vim9.

However, remember that execution occurs in the global context, not the script-local context. This means you need to declare variables with the g: prefix, like g:foo = 'bar'.

Common commands such as visual mode select ('<,'>), shell commands (!), substitution (s//), and global (g//) work as expected, even with vim9 prepended.

@lacygoill
lacygoill / CmdlineEnter_CmdlineLeave.md
Last active December 21, 2021 23:57
New events when you enter/leave a command line in Vim

In patch 8.0.1206, Vim has added 2 new events: CmdlineEnter and CmdlineLeave. They are fired every time you enter or leave a command line.

Syntax

There are 7 types of command lines, including one for normal Ex commands, debug mode commands, search commands (with a distinction between forward and backward), expressions, and inputs (more info at :h cmdwin-char). Each of them is associated with a symbol among this set : > / ? = @ -.

You can limit the effect of an autocmd listening to CmdlineEnter / CmdlineLeave to one or several types of command lines by: