Vim
Navigation:
h "Left
j "Down (physical line)
k "Up (physical line)
l "Right
gj "Down (visual line)
gk "Up (visual line)
Moving lines:
:m+1 "Move the current line down one line
:m-2 "Move the current line up one line
:m$ "Move the current line to the end of the file
:10m20 "Move line 10 to line 20
:20m10 "Move line 20 to line 11
:m10 "Move the current line to line 10 or 11, depending on whether the current line is before or after
Turn off highlighting:
:noh
Open multiple files as tabs (from outside of vim):
$ vim -p file1.cxx file2.cxx " Globbing works, too.
Open a file as a tab (from within vim):
:tabedit file3.cxx
Navigate between tabs:
:tabn " Next tab
:tabp " Previous tab
:tabfirst " First tab
:tablast " Last tab
{i}gt " Jumps to the i'th tab
Move a tab:
:tabm 0 "Moves the current tab to the specified index
Find and replace:
:s/replaceThis/withThis/gc " Current line
:%s/replaceThis/withThis/gc " All lines in document
:15,20s/replaceThis/withThis/gc " Lines 15 to 20, inclusive
" :s is short for :substitute
" c requires confirmation
Jump to…
0 "Beginning of a line
$ "End of a line
:76 "Line number 76
( "Previous sentence
) "Next sentence
b "Previous word
w "Beginning of next word
e "End of next word
Settings:
:set nu "Turn on line numbers
:set nonu "Turn off line numbers
:set wrap lbr "Wrap long lines between words
Syntax highlighting:
:syntax on "Turn on
:syntax off "Turn off
Alter case of selected text:
u "Lowercase
U "Uppercase
~ "Invert Case
Undo/Redo:
u "Undo
Ctrl+r "Redo
Inserting text:
i "Insert text before cursor
a "Insert text after cursor
I "Insert text before first non-whitespace character
A "Insert text at end of line
Nice things to put in .vimrc
:
" Wrap long lines between words
set wrap lbr
" Add line numbers
set nu
" Highlight txx as cpp
autocmd BufReadPost,BufNewFile *.txx set filetype=cpp
Remove trailing whitespace:
:%s/\s\+$//gc " replace '\s\+$' with ''
Highlight Non-ASCII Characters:
:set hlsearch " Make sure that what you search for will be highlighted
/[^\d0-\d127] " Highlight ASCII digits (0 to 127)
:nohlsearch " Turn highlighting back off