Hints for vim
.vimrc
A custom .vimrc
file can save lots of time and make editing easier. Put the following commands in ~/.vimrc
:
set nohlsearch set autoindent set tabstop=4 set shiftwidth=4 set ruler set showcmd syntax on set bg=dark set spell " enables live spell checking nnoremap <up> gk nnoremap <down> gj inoremap <up> <C-o>gk inoremap <down> <C-o>gj
Line by Line movement
If you dislike vim jumping over all lines when you have a line
that wraps, use gk
and gj
to move up and down. If you want to map
these to the up and down arrows, add the following two lines to your .vimrc
file:
nnoremap <up> gk nnoremap <down> gj
Fortunately, doing this does not make it so that gk
and gj
are inserted when in insert mode. Up and down return to their normal mode.
To have up and down have the same behavior in insert mode add the following to your .vimrc
file:
inoremap <up> <C-o>gk inoremap <down> <C-o>gj
OS X GVim
To begin, download the latest stable version of MacVim. Move the .app
to your Applications folder.
Make sure you have a ~/.bin
folder and it is included in you PATH variable in your .bash_profile
file.
In your .bin
folder create the following script named gvim and make sure you chmod +x
the file.
#!/bin/bash if [ $# -eq 0 ]; then # just open GVim open /Applications/MacVim.app else # create the file if it does not exist if [ ! -f "$1" ]; then touch $1 fi # open the file with GVim open $1 -a /Applications/MacVim.app fi
Next create your ~/.gvimrc
file. Example file:
set backspace=indent,eol,start " allows all proper backspacing set vb " visual beep set lines=56 set columns=92 set anti " antialiasing on set gfn=Monaco:h12 " set the font and size colorscheme torte " set the colorscheme to torte, if torte is not found, use billw set guioptions-=T " removes toolbar
Search and replace
vim uses regular expressions for search and replace.
use /foo
to find foo
in the text.
s/foo/bar
replaces all foo
on a line with bar
.
To replace all foo
with bar
in the whole file use g/foo/s//bar/g
When searching for text it can be helpful to highlight all occurrences. To enable this use the command :set hlsearch
. To disable it use :set nohlsearch
.
To search for foo
and replace it with bar
within a visual selection use :%s/\%Vfoo/bar/g
.
Spelling
To enable live spell checking in vim, use :set spell