You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:s/a\|b/xxx\0xxx/g# Modifies "a b" to "xxxaxxx xxxbxxx"
:s/test/\U&file/ # Modifies "test" to "TEST FILE"
:s/\(test\)/\U\1\efile/ # Modifies "test" to "TEST file"
:s/\v([abc])([efg])/\2\1/g# Modifies "af fa bg" to "fa fa gb"
:s/\v\w+/\u\0/g# Modifies "bla bla" to "Bla Bla"
:s/\v([ab])|([cd])/\1x/g# Modifies "a b c d" to "ax bx x x"
:%s/.*/\L&/ # Modifies "HTML" to "html"
:s/\v<(.)(\w*)/\u\1\L\2/g# Make every first letter of a word uppercase
:%s/^\(.*\)\n\1/\1/ # Remove duplicate lines
:%s/<\/\=\(\w\+\)\>/\U&/g# Convert HTML-Tags to uppercase
:g/^pattern/s/$/mytext# Find and append text to the end
:g/pattern/norm! @i# Run a macro on matching lines
/^\(.*\)\(\r\?\n\1\)\+$# View the duplicates lines
/\v^(.*)(\r?\n\1)+$# View the duplicates lines (very magic)
:v/./,/./-j# Compress blank lines into a blank line
:g/<p1>/,/<p2>/d# Delete inclusively from <p1> to <p2>
The Quickfix List is primarily used to navigate a list of errors/warnings (or file locations) generated by a compiler or linter.
Shortcut
Description
:copen
Open the quickfix window
:cclose
Close the quickfix window
:cnext
Go to the next error/location (:cn also works)
:cprevious
Go to the previous error/location (:cp also works)
:clist
List all errors/locations in the list
:cf [file]
Populate the list with errors from a file (e.g., a compiler log)
Quickfix Do (:cdo and :cfdo)
The :cdo (quickfix do) and :cfdo (quickfix file do) commands execute a command in every file listed in the quickfix list. :cdo iterates over every location in the list, while :cfdo iterates over every unique file in the list.
Command
Description
:cdo [cmd]
Execute [cmd] for every location in the quickfix list.
:cfdo [cmd]
Execute [cmd] for every unique file in the quickfix list.
Miscellaneous
Case {.row-span-2}
Shortcut
Description
vU
Uppercase character
vu
Lowercase character
~
Toggle case character
viwU
Uppercase word
viwu
Lowercase word
viw~
Toggle case word
VU/gUU
Uppercase line
Vu/guu
Lowercase line
V~/g~~
Toggle case line
gggUG
Uppercase all text
ggguG
Lowercase all text
ggg~G
Toggle case all text
{.shortcuts}
Jumping
Shortcut
Description
<C-o>
Go back to previous
<C-i>
Go forward
gf
Go to file in cursor
ga
Display hex, ascii value
{.shortcuts}
Misc command-lines {.row-span-2}
-
-
:h
Help open help view
:edit!
Reload current file
:2,8m0
Move lines 2-8 to 0
:noh
Clear search highlights
:sort
Sort lines
:ter
Open a terminal window
:set paste
Enable Insert Paste sub-mode
:set nopaste
disable Insert Paste sub-mode
:cq
Exiting with an error (aborting Git)
Navigating
Shortcut
Description
%
Nearest/matching {[()]}
[(|[{
Previous ( or {
])|]{
Next ) or }
[m
Previous method start
[M
Previous method end
{.shortcuts}
Counters
Shortcut
Description
<C-a>
Increase number
<C-x>
Decrease number
{.shortcuts}
Tags {.row-span-2 .col-span-2}
Shortcut
Description
:tag Classname
Jump to first definition of Classname
<C-]>
Jump to definition
g]
See all definitions
<C-t>
Go back to last tag
<C-o> <C-i>
Back/forward
:tselect Classname
Find definitions of Classname
:tjump Classname
Find definitions of Classname (auto-select 1st)
{.shortcuts}
Formatting
-
-
:ce 8
Center lines between 8 columns
:ri 4
Right-align lines at 4 columns
:le
Left-align lines
See :help formatting
Marks {.col-span-2 .row-span-4}
Shortcut
Description
`^
Last position of cursor in insert mode
`.
Last change in current buffer
`"
Last exited current buffer
`0
In last file edited
''
Back to line in current buffer where jumped from
``
Back to position in current buffer where jumped from
`[
To beginning of previously changed or yanked text
`]
To end of previously changed or yanked text
`<
To beginning of last visual selection
`>
To end of last visual selection
ma
Mark this cursor position as a
`a
Jump to the cursor position a
'a
Jump to the beginning of the line with position a
d'a
Delete from current line to line of mark a
d`a
Delete from current position to position of mark a
c'a
Change text from current line to line of a
y`a
Yank text from current position to position of a
:marks
List all current marks
:delm a
Delete mark a
:delm a-d
Delete marks a, b, c, d
:delm abc
Delete marks a, b, c
{.shortcuts}
Calculator
Shortcut
Description
<C-r>= 7*7
Shows the result
<C-r>= 10/2
Shows the result
{.shortcuts}
Do this in INSERT mode
Shell
-
-
:!<shell>
Interpret Shell Command
:r!<shell>
Read in output of shell
:r!date
Insert date
:!!date
Replace current line with date
Command line
Shortcut
Description
<C-r><C-w>
Insert current word into the command line
<C-r>"
Paste from " register
<C-x><C-f>
Auto-completion of path in insert mode
{.shortcuts}
Tricks
Remove duplicate lines
:sort | %!uniq -u
To number the lines in the file
:%!cat -n
Copy whole doc to clipboard
:%w !pbcopy # Mac OS X
:%w !xclip -i -sel c # GNU/Linux
:%w !xsel -i -b # GNU/Linux