How do I sort lines and remove duplicates in one command?
:sort u
The :sort u command sorts all lines in the buffer (or a selected range) alphabetically and removes duplicate lines in a single pass.
415 results for "n N"
:sort u
The :sort u command sorts all lines in the buffer (or a selected range) alphabetically and removes duplicate lines in a single pass.
>>
The >> command shifts the current line one shiftwidth to the right, adding indentation.
g- / g+
Vim doesn't have a simple linear undo stack — it maintains a full undo tree with branches.
editing #editing #undo-redo #normal-mode #advanced #productivity
: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
: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.
v3aw
In visual mode, repeating text object motions progressively expands the selection.
:set formatoptions+=cro
The formatoptions setting controls how Vim automatically formats text as you type — including comment continuation, auto-wrapping, and paragraph formatting.
:call setreg('a', @a, 'l')
Registers in Vim have a type — characterwise, linewise, or blockwise — that affects how their contents are pasted.
*cgn
Global substitution is fast, but sometimes you need selective control over each occurrence.
:cfirst and :clast
:cfirst and :clast jump directly to the first or last entry in the quickfix list, skipping all intermediate results.
*NgUgn
gn is often treated as a visual selection command, but it is more powerful when used as a motion target for operators.
:%s/pattern/\=expr/g
Prefixing the replacement field of :s with \= tells Vim to evaluate the rest as a Vimscript expression and use its result as the replacement string.
:g/pattern/join
The :g/pattern/join command combines the :global command with :join to merge every line matching a pattern with the line immediately following it.
command-line #ex-commands #editing #command-line #search #normal-mode
:verbose nmap <lhs>
When key behavior is inconsistent, the root cause is usually mapping precedence.
command-line #command-line #mappings #debugging #config #normal-mode
/pattern/e+1<CR>
Most Vim searches place the cursor at the start of the match.
\_.\+
By default, .
:'<,'>sort!
The sort! command sorts the selected lines in reverse (descending) order.
:snomagic /foo.\+/bar/<CR>
When a pattern is mostly literal text with just a little regex, default magic mode can force extra escaping and make substitutions harder to read.
/\vstart\_.{-}end
Multiline searches in Vim often overmatch because .
:set shortmess+=c
Insert-mode completion can spam the command line with status text like "match 1 of N" and related prompts.
config #config #completion #command-line #options #insert-mode