Deleting {{{
x character under cursor
d left delete character to left (same for right too)
dd delete (a) line(s)
dw delete (a) word(s)
de delete to end of word
d$ delete to end of line
[number] d d|w|e|$ or d [number] d|w|e|$
}}}
Moving {{{
arrows
e end of word
$ end of line (same as End key)
g$ end of screen line (if wrapped)
g^ start of screen line (if wrapped)
w next word
b start of word
ctrl+G show position in file
shift+G [number] move to end of file [then to line number]
}}}
Undo {{{
U fix a whole line
u undo last command
ctrl+R redo (after undo)
}}}
put (paste) {{{
p|P put after|before current line }}}
replace {{{
r replace single character
R overwrite mode
cw same as d e i deletes word to end and goes to insert
c$ same as d$i }}}
substitute (shortens to s): {{{
:s/old/new/ search and replace first occurrance on the line
/g ALL occurrances
/c confirm each change
:#,#s/old/new/g between lines #,#
:%s/old/new/g whole file
}}}
}}}
Search {{{
/ search fwd
? search back
n find next match
p find previous
% find matching () {} []
:set ic set options to "ignore case"
:set hls is
options to highlight search and incremental search
:nohlsearch or :set nohls
remove highlight of search
* search fwd for word under cursor (# for back)
g* as * but partial matches
gd find local definition (also gD for global)
}}}
Regexp {{{
{-} as few as possible
}}}
special characters {{{
type CTRL-V followed by the number. Eg. <C-V>032 is a space.
ga or :as[cii] -print the ascii value of the character under cursor
g8 -print char code for utf-8
}}} :! external command execute command
jumping {{{
:
ctrl+] jump to thing between |bars| ctrl+T ctrl+O jump back “ go back to where you were }}}
recording {{{
. repeat last command
q{register} where {register} is a-z starts recording
q ends recording
@{register} do commands
}}}
marks {{{
mt mark top
mb mark bottom
't
'b reference top or bottom
m{a-z} set mark
`a move to mark a
'a move to start of line where mark a is
}}}
indent {{{
>> indent one
<< de-indent one
:>>> indent three
2>> indent 2 lines one
= reindent
visual > indent one
visual n> indent n
insert <C-T> indent line
insert <C-D> deindent line
}}}
text editing {{{
for editing text files you probably want to use the following settings:
:set expandtab
:set tabstop=4
:set textwidth=64
:set autoindent
:set formatoptions+=awn
1. the first line means use spaces not tabs
2. size of tabs
3. width of text - affects text entered in insert mode
4. takes indentation from first line of paragraph while reformatting
5. always format, use space at end of line to indicate paragraph continues
(this is useful as it allows you to not HAVE TO have a blank line
between paras), allow numbers so that 2nd+ lines wrap according to space
after number like this paragraph)
useful commands
:retab for redoing tabs according to current settings
gqap reformat paragraph. Miss off ap to do other things.
useful to follow with . repeat last command
gwap reformat paragraph. Leave cursor where it was
}}}
map keystrokes {{{
:map keys towhat this works for normal mode
:map! keys towhat this works for insert mode
:noremap keys towhat normal mode, keys aren't mapped again.
}}}
windows {{{
<C-W> s split vertically
<C-W> <C-V> split horizontally
<C-W> <C-N> new empty window
<C-W> <C-Q> close current window (same as :q)
}}}
word count {{{
g CTRL-G shows a word, byte and line count, and where you are.
in visual mode, it tells you how many are in the selection.
}}}
registers {{{
(See help <C-R> and help registers)
" unnamed register, last yank, delete etc.
% current filename
# alternate filename ?
* the clipboard contents (X11: primary selection)
+ the clipboard contents
/ the last search pattern
: the last command-line
- the last small (less than a line) delete
. the last inserted text
= the expression register: you are prompted to
enter an expression (see |expression|)
}}}
editing in command mode {{{
useful:
CTRL-V enter control codes (eg. follow by Enter or CTRL-M for new line)
alternatively, dial in numbers, eg 082 for R
:%s/ CTRL-V TAB / \n
would replace all tabs with a new line.
CTRL-R \" put in the contents of the unnamed register (used by yank etc.)
CTRL-R x put in the contents of register x.
}}}
vimrc settings {{{
My ~/.vimrc:
" search
set ignorecase
set smartcase
set hlsearch
set incsearch
" gui
syn on
color morning
set guifont=...
" line breaks
set showbreak=\ \ \ \
set lbr
" sets current working dir
set acd
" enable syntax highlighting
:syntax on
" map control shift c to copy entire buffer to clipboard
map <C-S-C> :%y +<C-M>
}}}
