How do I run a substitute command without changing my current search pattern?
:keeppattern s/old/new/g
When you run a :s or :g command, Vim updates the search register (@/) with the pattern you used.
:keeppattern s/old/new/g
When you run a :s or :g command, Vim updates the search register (@/) with the pattern you used.
:g/pattern/z#.5
The :global command is great for finding lines matching a pattern, but by default it only shows the matching lines themselves.
:/start/,/end/d
Instead of specifying line numbers for Ex command ranges, you can use search patterns.
command-line #ex-commands #editing #search #ranges #command-line
:keeppattern {cmd}
Many Ex commands silently overwrite the search register (@/), which changes your hlsearch highlighting and n/N behavior.
:.+1,.+3d
Vim's Ex command addresses support arithmetic offsets relative to the current line (.
command-line #ex-commands #editing #navigation #command-line
:cexpr system('grep -rn pattern .')
While :make and :grep populate the quickfix list, they are limited to their configured programs.
:cexpr system('command')
The :cexpr command parses any expression into the quickfix list using the current errorformat.
:/start/,/end/ {command}
Vim's range addressing lets you specify a line range using search patterns instead of explicit line numbers.
:<C-r>"
When typing an Ex command or search pattern, you often need to insert text you've already yanked or deleted.
:let @+ = @"
Vim's :let @{reg} syntax lets you read from one register and write to another.
:filter /pattern/ command
The :filter command restricts the output of another Ex command to only lines matching a given pattern.
:verbose nmap <leader>
The :verbose prefix on mapping commands shows not just the mapping definition but also the file and line number where it was defined.
:call feedkeys("iHello\<Esc>", 'n')
The feedkeys() function injects keystrokes into Vim's input buffer as if the user typed them.
q/k?pattern<CR>
Vim's command-line history window (q: for Ex commands, q/ for search) opens a full editing buffer containing your history.
:/start/,/end/command
Vim allows pattern-based ranges in Ex commands, letting you operate on lines between two search matches.
:sandbox {command}
Vim's sandbox mode restricts what a command can do, preventing it from executing shell commands, writing files, or modifying certain settings.
:call timer_start(1000, {-> execute('echo "done"')})
Vim's timerstart() function lets you schedule code to run after a specified delay in milliseconds.
:doautocmd User MyEvent
Vim's User event type lets you define custom events that fire on demand.
:cnoremap <C-a> <Home>
Vim's command line has limited navigation by default.
:command -complete=file -nargs=1 E edit <args>
When defining custom commands with :command, the -complete option adds tab completion for arguments.
command-line #command-line #completion #custom-command #tab-complete