commands:%s/find/replace/g
finds and replaces all instances in file
:%s/find/replace/gi
finds and replaces all instances in file (ignore case)
:%s/find/replace/gc
finds and replaces all instances in file (confirm each replacement)
:%g/search/s/find/replace
searches the whole file for lines with "search" in them, then runs a substitution s/find/replace on only those lines
:s/\(\d\d\)-\(\d\d\)-\(\d\d\d\d\)/\3-\1-\2
finds a date presumed to be in the broken US format (MM-dd-yyyy) and rearranges it into iso format (yyyy-MM-dd.
the key points in this are the \( and \) surround a part of the searched text we want to reuse in out substitution, and \1, \2, etc refer back to these parts of the text
:let i=10 | 'a,'bg/abc/s/def/\=i/ |let i=i+1
for the range between 'a and 'b, for lines with the string "abc" on them, replace the first occurance of "def" with an incrementing number starting from 10. I commonly have "abc" and "def" set to the same thing (for some reason it doesnt increment if you leave out the "g/abc/" part).
shortcutsC^p
autocomplete words
z=
show spelling suggestions
zg
add to dictionary
split panesC^w, n
new pane
:sp filename.txt
open filename.txt in a new pane
:vsp filename.txt
open filename.txt in a new vertical pane
C^w, w
cycle through panes
C^w, down arrow
select pane below
C^w, up arrow
select pane above
C^w, =
all panes equal height
C^w, +
increase selected pane height by 1
C^w, -
decrease selected pane height by 1
VIM RegEx stuff^
start of line
$
end of line
C^v + C^m
the ^M character that windows users leave on the end of lines
.vimrc:map <F5> :setlocal spell! spelllang=en_au
:imap <F5> <ESC>:setlocal spell! spelllang=en_au
Use F5 to toggle en_au spelling checker
:map <C-a> 0
:map <C-e> $
:cmap <C-a> <home>
:cmap <C-e> <end>
:imap <C-e> <ESC>$i<right>
:imap <C-a> <ESC>0i
Use Ctrl-a/Ctrl-e to move to the start/end of a line, emacs style i believe
set background=dark
tells vim that your terminal has a dark background, dont use light colours for text
set backspace=indent,eol,start
backspace over anything instead of that broken backspace some distros seem to include
set backup
set backupdir=~/tmp/vim
keep backup files somewhere neat and tidy, instead of having tilde files all over the place
set hlsearch
search highlights all matching terms
set ignorecase
case insensitive searching
set infercase
auto-completion automatically adjusts case of keywords
set number
line numbers
set showmatch
highlights the matching brace briefly when highlighted
set cursorcolumn
set cursorline
hi cursorcolumn ctermbg=red
turns on a row and column highlight to make it easy to find the cursor
set expandtab
set tabstop=2
switches to soft tabs, 2 characters wide
Labels: vim