Miscellaneous

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

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

Shell

- -
:!<shell> Interpret Shell Command
:r!<shell> Read in output of shell
:r!date Insert date
:!!date Replace current line with date

Calculator

Shortcut Description
<C-r> = 7*7 Shows the result
<C-r> = 10/2 Shows the result
Do this in INSERT mode

Marks

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
da| Delete from current position to position of marka`
c'a Change text from current line to line of a
ya| Yank text from current position to position ofa`
: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

Formatting

- -
:ce 8 Center lines between 8 columns
:ri 4 Right-align lines at 4 columns
:le Left-align lines
See :help formatting

Tags

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)

Counters

Shortcut Description
<C-a> Increase number
<C-x> Decrease number

Navigating

Shortcut Description
% Nearest/matching {[()]}
[( * * [{
]) * * ]{
[m Previous method start
[M Previous method end

Misc command-lines

- -
: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)

Case

Shortcut Description
vU Uppercase character
vu Lowercase character
~ Toggle case character
viw U Uppercase word
viw u 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
Comments