How do I write vimrc configuration that works in both Vim and Neovim by detecting which one is running?
has('nvim')
The has() function tests whether a feature or capability is available, returning 1 (true) or 0 (false).
Search Vim Tricks
Searching...has('nvim')
The has() function tests whether a feature or capability is available, returning 1 (true) or 0 (false).
:0put
The :put Ex command inserts register contents as a new line below the specified line number.
v:count1
The v:count1 variable holds the count typed before a command, defaulting to 1 if no count was given.
:set formatexpr=MyFormat()
The formatexpr option lets you replace Vim's built-in line-breaking logic for the gq operator with your own Vimscript expression or function.
:set showcmd
The showcmd option makes Vim display the currently-typed command in the bottom-right corner of the screen, giving you live feedback as you build up key sequence
:w !cmd
The :w !cmd command sends the buffer's contents as standard input to an external command without modifying the buffer.
ea
The ea compound shortcut moves to the last character of the current word with e, then enters insert mode after the cursor with a.
do
The do command (diff obtain) is shorthand for :diffget.
{count}H and {count}L
Most Vim users know H jumps to the first visible line, M to the middle, and L to the last.
<C-f> (in command-line mode)
When you're already on the Vim command line and realize you need complex edits — inserting text from multiple positions, reordering arguments, or referencing
<C-r>= (command-line mode)
Just like = lets you insert evaluated expressions in insert mode, you can use it inside an Ex command on the command line to embed any Vimscript expression resu
:set winwidth=999 winheight=999
Setting winwidth=999 and winheight=999 tells Vim to try to make the active window at least 999 columns wide and 999 rows tall whenever it gains focus.
<C-r><C-r>x
When you press x in insert mode to paste a register, Vim inserts the text "as if you typed it" — meaning autoindent, textwidth, and other insert behaviors can
:lua =expr
In Neovim, prefixing a Lua expression with = on the :lua command line evaluates it and pretty-prints the result using vim.
vim.keymap.set
vim.
gUU
The gUU command uppercases every character on the current line instantly — no visual selection or motion required.
:%s/\n/ /g
Using \n in the pattern of :substitute matches the newline character at the end of each line, letting you join lines with any separator you choose — something
:nnoremap <expr> {key} {expression}
The argument to any map command (:nmap, :inoremap, etc.
config #config #macros #insert-mode #normal-mode #ex-commands
\%(...\)
Vim's standard grouping syntax \(.
:g/^\s*$/d
The global command :g/^\s$/d removes every line that is empty or contains only whitespace — a common cleanup task when tidying up code, configuration files, o