How do I copy all lines matching a pattern to the end of the file?
:g/pattern/t$
How it works The :g (global) command combined with :t (copy) lets you duplicate all lines matching a pattern to a specific location.
411 results for "G"
:g/pattern/t$
How it works The :g (global) command combined with :t (copy) lets you duplicate all lines matching a pattern to a specific location.
:g/pattern/normal dd
The :g/pattern/normal {commands} command executes normal mode keystrokes on every line in the file that matches the given pattern.
:%s/old/new/g
The :%s/old/new/g command replaces all occurrences of old with new across every line in the file.
:g/^$/d
The :g/^$/d command deletes every blank line in the file using Vim's powerful global command.
:keepjumps
When writing scripts or running commands that move the cursor (like :g, :s, or :normal), Vim normally adds each cursor position to the jump list.
:g/pattern/.-1,.+1d
The :g (global) command normally operates on lines that match a pattern.
:g/pattern/d
The :g/pattern/d command deletes every line in the file that matches the given pattern.
&
The & command in normal mode repeats the last :s substitution on the current line.
search #search #substitution #ex-commands #repeat #normal-mode
:g/^/m0
The :g/^/m0 command is a clever use of Vim's global command to reverse every line in the file.
:g/pattern/normal {cmd}
Combining :global with :normal lets you run any normal-mode keystrokes on every line that matches a pattern.
g<C-a>
The g command increments numbers across a visual selection so that each subsequent line gets a progressively higher value.
:%s/,/\r/g
In Vim's substitute command, \r in the replacement string inserts a newline.
:g/pattern/normal @q
The :global command combined with :normal lets you execute a recorded macro on every line that matches a given pattern.
macros #macros #command-line #ex-commands #global #batch-editing
:g/start/,/end/d
The :g (global) command can operate on ranges, not just single lines.
:s/,/\r/g
In Vim's substitute command, use \r (not \n) in the replacement to insert a real newline.
:%s/\<word\>/\u&/g
Vim's substitute command supports case conversion modifiers in the replacement string.
:%s/\v(old)/\=toupper(submatch(0)[0]).tolower(submatch(0)[1:])/g
Standard substitutions don't preserve the original case of matched text.
:%Subvert/old/new/g
The vim-abolish plugin by Tim Pope provides the :Subvert command (abbreviated :S), which performs search-and-replace operations that automatically handle every
:g/pattern/y A
The :g/pattern/y A command yanks every line matching the pattern and appends it to register a.
command-line #command-line #registers #global #ex-commands #filtering
:g/pattern/m0
When working with large files, you sometimes need to reorganize content by pulling all lines matching a certain pattern to the top.
command-line #global #move #ex-commands #editing #command-line