Page
Navigation
Links

Edit

Navigate

Search

Find And Replace (regex)

Indentation

Case

Read/Write files

File Encoding

Abbreviations

Vim settings

Working with multiple files

Window splitting

Auto-completion

File explorer

Tabs

Marks

Edit

cw change word under cursor, from the current cursor position
ciw change entire word under cursor (change inner word)
d delete text selected in visual mode
dG delete lines to end of file
:10,20d delete lines 10 through 20
y yank text selected in visual mode
p put text from buffer
Column editing - insert text:
1. ctrl + v (or ctrl + V) to go into column mode
2. Select rows to edit using j (down) or k (up)
3. shift + i to go into insert mode in column mode
4. Type text (only the first row is changed).
5. Esc
Basically, remember to use the control key with v to get into block visual mode, and then use the shift key with i to insert in column mode.

An alternative to insert text at beginning of line is using a regex pattern :%s/^/hello/g
/word Search word from top to bottom
?word Search word from bottom to top
/jo[ha]n Search john or joan
/\< the Search the, theatre or then
/the\> Search the or breathe
/\< the\> Search the
/\< ¦.\> Search all words of 4 letters
/\/ Search fred but not alfred or frederick
/fred\|joe Search fred or joe
/\<\d\d\d\d\> Search exactly 4 digits
/^\n\{3} Find 3 empty lines
:bufdo /searchstr/ Search in all open files
e Move to the end of a word
w Move forward to the beginning of a word
b Move backward to the beginning of a word
$ Move to the end of the line
0 Move to the beginning of the line
Jump to end of file G
gg Jump to beginning of file (same as 1G)
50G jump to line 50
% Jump to corresponding item, e.g. from an open brace to its matching closing brace
H Jump to the top of the screen
M Jump to the middle of the screen
L Jump to the bottom of the screen
^ Move to the first non-blank character of the line
) Jump forward one sentence
( Jump backward one sentence
} Jump forward one paragraph
{ Jump backward one paragraph
10<PageUp> or 10<CTRL-B> Move 10 pages up
5<PageDown> or 5<CTRL-F> Move 5 pages down
'm Jump to the beginning of the line of mark m
`m Jump to the cursor position of mark m
'' Return to the line where the cursor was before the latest jump (two single quotes)
`` Return to the cursor position before the latest jump / undo the jump (two backticks)

Find and Replace (regex)

Search and Replace Tips vim.wikia.com
Regex Tips vimregex.com
:s/old/new/ Replace first occurence of old with new [current line]
:s/old/new/g Replace old with new [current line]
:%s/old/new/g Replace all occurences of old with new
:%s/old/new/gc Replace all occurences with confirmation
:2,35s/old/new/g Replace all occurences between lines 2 and 35
:5,$s/old/new/g Replace all occurences from line 5 to EOF
:%s/old/new/gi Replace all occurences of old by new, case insensitive
:%s/^/hello/g Replace the begining of each line by hello
:%s/$/Harry/g Replace the end of each line by Harry
\r \n \& \1 \2 in replace pattern: newline, null byte, ampersand, 1st backreference, 2nd backreference
:%s/ *$//g Delete all white spaces
:g/string/d Delete all lines containing string
:v/string/d Delete all lines containing which didn’t contain string
:%s/\r//g Delete DOS carriage returns (^M)
:%s/\r/\r/g Transform DOS carriage returns in returns
:%s#<[^>]\+>##g Delete HTML tags but keeps text
:%s/^\(.*\)\n\1$/\1/ Delete lines which appears twice
Ctrl+a Increment number under the cursor
Ctrl+x Decrement number under cursor
ggVGg? Change text to Rot13

Indentation

>> Indent
<< De-indent
5>> Indent 5 lines
5== Re-indent 5 lines
>% Increase indent of a braced or bracketed block (place cursor on brace first)
<% Reindent a braced or bracketed block (cursor on brace)
=% Reindent a braced or bracketed block (cursor on brace)
]p Paste text, aligning indentation with surroundings
=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block
>i{ Increase inner block indent
<i{ Decrease inner block indent
:set autoindent Turn on auto-indent
:set smartindent Turn on intelligent auto-indent
:set shiftwidth=4 Defines 4 spaces as indent size
ctrl-t, ctrl-d Indent/un-indent in insert mode
>> Indent
<< Un-indent

Case

Vu Lowercase line
VU Uppercase line
g~~ Invert case
vEU Switch word to uppercase
vE~ Modify word case
ggguG Set all text to lowercase
:set ignorecase Ignore case in searches
:set smartcase Ignore case in searches excepted if an uppercase letter is used
:%s/\<./\u&/g Sets first letter of each word to uppercase
:%s/\<./\l&/g Sets first letter of each word to lowercase
:%s/.*/\u& Sets first letter of each line to uppercase
:%s/.*/\l& Sets first letter of each line to lowercase

Read/Write files

:1,10 w outfile Saves lines 1 to 10 in outfile
:1,10 w >> outfile Appends lines 1 to 10 to outfile
:r infile Insert the content of infile
:23r infile Insert the content of infile under line 23

File Encoding

Encoding Tips
Source for some of these tips
:edit ++enc=<encoding> [filename] open a file with a specified encoding
:write ++enc=<encoding> [filename] save a file with a specified encoding.
Note: the characters must be available in the target encoding - i.e., Greek letter Ω (Unicode 03A9) can be represented in UTF-8 but not Latin-1.
:set encoding
 =<encoding>
Specifies the encoding that Vim will use internally for input, buffers, registers, etc. By default this is set to UTF-8. If no encoding is specified, the current encoding will be displayed.
:set fileencoding
 =<encoding>
This command specifies the character encoding that should be used for saving files. If the encoding specified by ':set fileencoding' differs from ':set encoding', Vim will attempt to convert the contents of the file from the existing encoding (':set encoding') to the target encoding (':set fileencoding').
:as
ga
This command displays the code point of the character under the cursor. You may also use the much easier keyboard shortcut ‘ga’. The decimal, hexadecimal, and octal code point values will be displayed.
g8 This command displays the hexadecimal value of the bytes used to represent the character under the cursor. This differs from 'ga' which displays the code point value of the character – the value a character has within a coded character set. This command displays the actual byte value on disk – the value used to represent a character within a character encoding form.
8g8 This command identifies any invalid UTF-8 character sequences in the current file. For example, if the file is encoded as UTF-8, but contains a byte or set of bytes which do not represent a valid UTF-8 character, this command will position the cursor over that location in the file.

File explorer

:e . Open integrated file explorer
:Sex Split window and open integrated file explorer
:browse e Graphical file explorer
:ls List buffers
:cd .. Move to parent directory
:args List files
:args *.php Open file list
:grep expression *.php Returns a list of .php files contening expression
gf Open file name under cursor

Tabs

:tabnew Creates a new tab
gt Show next tab
:tabfirst Show first tab
:tablast Show last tab
:tabm n(position) Rearrange tabs
:tabdo %s/foo/bar/g Execute a command in all tabs
:tab ball Puts all open files in tabs

Window splitting

ctrl+ws split windows
ctrl+ww switch between windows
ctrl+wq Quit a window
ctrl+wv Split windows vertically
:e filename Edit filename in current window
:split filename Split the window and open filename
ctrl-w up arrow Puts cursor in top window
ctrl-w ctrl-w Puts cursor in next window
ctrl-w_ Maximise current window
ctrl-w= Gives the same size to all windows
10 ctrl-w+ Add 10 lines to current window
:vsplit file Split window vertically
:sview file Same as :split in readonly mode
:hide Close current window
:­nly Close all windows, excepted current
:b 2 Open #2 in this window

Auto-completion

Ctrl+n Ctrl+p (in insert mode) Complete word
Ctrl+x Ctrl+l Complete line
:set dictionary=dict Define dict as a dictionary
Ctrl+x Ctrl+k Complete with dictionary
:{arrow} Command history (must type initial colon first)

Marks

mk Marks current position as k
˜k Moves cursor to mark k
d™k Delete all until mark k

Abbreviations

:ab mail mail@provider.org Define mail as abbreviation of mail@provider.org

Syntax highlighting

:syntax on Turn on syntax highlighting
:syntax off Turn off syntax highlighting
:set syntax=perl Force syntax highlighting

Vim settings

:set backupdir=<folder> change backup folder (vimrc entry)
:set nobackup
:set nowritebackup
turn off backups (vimrc entry)
:set guifont=
 Courier_New:h11
 Courier\ New:h11
 Courier\ New 11

Windows
Mac
Linux (space separated)
set guifont=* view available fonts

Working with multiple files

:e filename Edit a file in a new buffer
:bnext (or :bn) go to next buffer
:bprev (of :bp) Go to previous buffer
:bd Delete a buffer (close a file)
:sp filename Open a file in a new buffer and split window