How do I define a mapping that only takes effect if the key is not already mapped?
:map <unique> {key} {rhs}
The modifier causes Vim to fail with an error if you try to create a mapping for a key that is already mapped in that mode.
640 results for "/pattern"
:map <unique> {key} {rhs}
The modifier causes Vim to fail with an error if you try to create a mapping for a key that is already mapped in that mode.
:%s/^\(.\+\)\n\1$/\1/
This substitute command detects pairs of identical adjacent lines and collapses them into one, using a back-reference to match the repeated content.
function! {name}#{funcname}() in autoload/{name}.vim
Vim's autoload mechanism lets you place functions in autoload/*.
:let view=winsaveview() | {cmd} | call winrestview(view)
When writing Vimscript functions or mappings, commands like :substitute, gg, or :%normal will move the cursor and change the scroll position.
:[range]luado {lua-expr}
Neovim's :luado command runs a Lua expression on each line of a range, allowing you to transform text using the full power of Lua's string library.
:set gdefault
By default, :s/old/new/ only replaces the first occurrence of a pattern on each line.
<C-a> (command-line)
Pressing on the command line expands all current completion matches into the command at once, rather than cycling through them one at a time with .
<C-r><C-w>
When typing a command on the Vim command line, pressing inserts the word currently under the cursor.
<C-w>N
When using Vim's built-in :terminal, the buffer is in Terminal-Job mode by default, meaning all keystrokes go to the running shell.
:cnoremap %% <C-r>=expand('%:h').'/'<CR>
By mapping %% in command-line mode, you can type %% wherever you would normally type a path and have Vim automatically expand it to the directory of the current
:keepjumps {command}
The :keepjumps modifier lets you run any movement or command without recording a new entry in the jump list.
navigation #navigation #ex-commands #jump-list #normal-mode #vimscript
:call setreg('b', getreg('a'), getregtype('a'))
Plain register copies like :let @b = @a move text, but they can lose important metadata about register type.
fnameescape(filename)
When building Vim Ex commands dynamically, filenames with spaces, , %, #, [, or other special characters will be misinterpreted — the space looks like an argu
:windo setlocal colorcolumn=+1
When a setting is window-local, changing it once does not affect your other splits.
:windo {cmd}
:windo {cmd} executes an Ex command in every window in the current tab page, cycling through each one and applying the command before returning focus to the ori
buffers-windows #windows #buffers #ex-commands #buffers-windows
:g/pattern1/g/pattern2/command
Vim's :g command can be nested — the command part of one :g can itself be another :g.
:'<,'>normal @@
When you already have a useful macro but need to apply it to a specific block of lines, :'normal @@ is a high-leverage pattern.
:argdo norm @a | update
Combining :argdo with :norm @a lets you apply a recorded macro to every file in Vim's argument list — a powerful pattern for bulk refactoring across a project
\%V
The \%V atom in a Vim pattern matches only inside the last visual selection.
search #search #visual-mode #substitute #regex #text-objects
<C-a> (command-line mode)
In command-line mode, inserts all completions for the word before the cursor at once, as a space-separated list.