How do I register a Lua callback that fires before every keystroke to react to keyboard input?
vim.on_key()
vim.
vim.on_key()
vim.
vim.schedule()
vim.
:debug
The :debug command prefix puts Vim into its built-in interactive debugger before executing the given command.
command-line #ex-commands #debugging #command-line #vimscript
:%s/pattern/replacement/ig
The :s substitute command accepts /i and /I flags that override your global ignorecase and smartcase settings for that single substitution, letting you choose c
<C-f> (command-line mode)
Pressing while in the command-line (:, /, or ? prompt) opens the command-line window with your partially-typed command already loaded and ready for full Vim edi
command-line #command-line #ex-commands #editing #navigation
vim.api.nvim_create_user_command()
Neovim's Lua API provides vim.
:earlier {N}m
Vim's :earlier command lets you travel back through the undo history by wall-clock time rather than by the number of changes.
:set wildmode=longest,list
By default, Vim's command-line completion just cycles through matches one at a time.
:ce
Vim has three built-in ex commands for text alignment that most users never discover: :ce (center), :ri (right-justify), and :le (left-justify).
:{range}center {width}
Vim has built-in Ex commands for text alignment: :center, :right, and :left.
command-line #ex-commands #formatting #editing #command-line
:delmarks!
Marks accumulate as you work — ma, mb, mc and so on record positions for later jumps.
:normal! {cmds}
:normal {cmds} executes normal-mode keystrokes from the command line, but it honors your custom key mappings — so remapped keys produce unexpected results in
command-line #ex-commands #macros #normal-mode #command-line
:echo getregtype('a')
The getregtype() function returns the motion type of a register's content — whether it was yanked characterwise, linewise, or as a visual block.
:let winid = win_getid() | ... | call win_gotoid(winid)
The wingetid() and wingotoid() functions let you bookmark a window by its stable integer ID and jump back to it reliably.
:let @q = substitute(@q, 'from', 'to', 'g')
Macros are stored as plain text in named registers, so you can manipulate them with any Vimscript string function.
:s/\(\w\+\) \(\w\+\)/\=submatch(2) . ' ' . submatch(1)/
The submatch(N) function lets you access individual capture groups inside a \= (expression replacement) in a substitution.
:/pattern/+N and :/pattern/-N
Vim's Ex command ranges can use search patterns as line addresses, and those addresses can include a numeric offset (+N or -N) to target lines relative to the m
:setglobal
Vim maintains two values for most options: a global default that applies to new windows and buffers, and a local copy that can be overridden per-buffer or per-w
:Cfilter /pattern/
Vim ships with an optional built-in package called cfilter that adds :Cfilter and :Lfilter commands for narrowing down quickfix and location list entries by pat
:g/pattern/put ='text'
Combining :global with :put = lets you insert synthesized lines of content after every line matching a pattern — without plugins or complex macros.