Friday, July 10, 2009

My vimrc file

Got to save my .vimrc (vim configuration file) once in a while and now is a good time as I just cleaned it up a bit. Did not tweak it too much, but it has a few handy shortcuts, some for python some just general purpose. The file can be found as gist (revisioned pastebin) here.

And here is a raw paste:
" set tabstop settings
set ts=8
set sw=8

" wrap long lines
set textwidth=80
set linebreak
set smartindent

syntax on
set nocompatible
set novisualbell

" check for external modification
set autoread

" incremental search
set incsearch

" set spelling highlight options
highlight clear SpellBad
highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline
highlight clear SpellCap
highlight SpellCap term=underline cterm=underline
highlight clear SpellRare
highlight SpellRare term=underline cterm=underline
highlight clear SpellLocal
highlight SpellLocal term=underline cterm=underline

" ---------- START OF SHORTCUTS DEFINITIONS (KEY BINDINGS) ----------
"
" INDEX
"
" ,s enable spellcheck highlight
" ,S dissable spellcheck highlight
" ,c-d save all and exit
" ,c trim spaces at end of lines
" ,C trim spaces at the beginning of lines
" ,d insert date in YY-MM-DD format
" ,u insert unix timestamp
" <F2><F3><F4> execute file with python interpreter 2/3 and with argument
" <F5><F6> enable/dissable paste mode
" <F9><F10> exchange spaces with tabs and tabs with spaces
" <F12> general search and replace template

" spell checking shortcuts (ctrl+[sS] to switch it on/off)
map ,s :set spell<CR> :setlocal spell spelllang=en_us<CR> :set spellfile=~/.vim/spellfile.{encoding}.add<CR>
map ,S :set nospell<CR>

" add python 2, 3 and 3 with arguments execution to F2-F4
au filetype python nmap <F2> <esc>:w<CR>:tabfirst<CR>:! python %<CR>
au filetype python nmap <F3> <esc>:w<CR>:tabfirst<CR>:! python3 %<CR>
au filetype python nmap <F4> <esc>:w<CR>:! python3 %

" add save all and exit shortcut to ctrl+d
nmap <c-d> <esc>:xa<CR>

" add shortcut for switching paste mode on/off (F5-F6)
nmap <F5> :set paste<CR>i
nmap <F6> :set nopaste<CR>

" shortuct for swapping spaces with tabs (F9-F10)
nmap <F9> :%s/ /\t/g<CR>
nmap <F10> :%s/\t/ /g<CR>

" general search and replace template
nmap <F12> :%s///g

" suppress all spaces at end/beginning of lines
nmap ,c :%s/\s\+$//<CR>
nmap ,C :%s/^\s\+//<CR>

" insert current date in YY-MM-DD or UNIX time format
map ,d :r!date +\%Y-\%m-\%d<CR>hJi
map ,u :r!date +\%s<CR>

""" --------- END OF KEYBINDINGS --------------

" set execution bit for scripts
au bufwritepost *.sh silent !chmod +x %
au bufwritepost *.x.py silent !chmod +x %

" if we edit makefiles, make sure that tabs are not replaced with spaces
au filetype make setlocal noexpandtab

" set plaintext documents to a text with of 72 chars
autocmd BufRead *.txt set tw=72

No comments:

Post a Comment