Fork me on GitHub
20 Dec 2009
My .vimrc

I ported this from my old blog. So it's a bit older already


I'll just blurt it out there, maybe someone finds something useful in it...

" enable filetype guessing
filetype on
filetype plugin on

" do syntax coloring from start
syntax enable
autocmd BufEnter * :syntax sync fromstart

let mapleader=","       " set <leader> to ,
let maplocalleader="\\" " set <localleader> to \

set viminfo+=!          " support for yanking

set nocompatible        " no vi compatibility

set novisualbell        " no visual beeping
set noerrorbells        " no noise

set tabstop=4           " 1 tab = 4 spaces
set shiftwidth=4
set softtabstop=4
set expandtab           " tab --> spaces
set autoindent          " indent when starting new line
set smartindent         " smart indent when starting new line
inoremap # X#         " don't mess up the hashes, e.g. in perl comments

set number              " show line numbers
set ruler               " show line,col numbers
set showmatch           " highlight matching braces
set nowrap              " don't wrap lines
set incsearch           " show matches from search immediately
set hlsearch            " actually do show any matches at all

set foldenable          " do fold
set foldmethod=marker   " fold with markers ({{{1)

set wildmenu            " show completion menu in :e with <C-d>

" disable file browser help
let g:explDetailedHelp=0


""""""""" Fixing file recognition and indentation
autocmd FileType sass setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd FileType haml setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2


""""""""" GUI only """""""""""""""""""""""
set guioptions-=T       " disable toolbar
set gcr=a:blinkon0      " disable blinking


""""""""" Show superfluos spaces """""""""
:highlight ExtraWhitespace ctermbg=darkred guibg=darkred
:autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL


""""""""" F1 = ESC """""""""""""""""""""""
imap <F1> <ESC>
nmap <F1> <ESC>
vmap <F1> <ESC>


""""""""" F2 for paste toggle """"""""""""
nnoremap <F2> :set invpaste paste?<CR>
imap <F2> <C-O><F2>i
set pastetoggle=<F2>


""""""""" F3 for shiftwidth toggle """""""
nnoremap <expr> <F3> (&sw =~ "4$") ? ":set shiftwidth=2<cr>:set tabstop=2<cr>:set softtabstop=2<cr>" : ":set shiftwidth=4<cr>:set tabstop=4<cr>:set softtabstop=4<cr>"
inoremap <expr> <F3> (&sw =~ "4$") ? "<c-o>:set shiftwidth=2<cr><c-o>:set tabstop=2<cr><c-o>:set softtabstop=2<cr>" : "<c-o>:set shiftwidth=4<cr><c-o>:set tabstop=4<cr><c-o>:set softtabstop=4<cr>"


"""""""""" autocompletion """""""""""""""""
" don't auto-insert first item, show menu even with only one entry
set completeopt=longest,menuone
" make completion a bit nicer
inoremap <expr> <space> pumvisible() ? "\<lt>c-y> " : "\<lt>space>"
inoremap <expr> . pumvisible() ? "\<lt>c-y>." : "."
inoremap <expr> : pumvisible() ? "\<lt>c-y>:" : ":"
inoremap <expr> , pumvisible() ? "\<lt>c-y>," : ","
inoremap <expr> ( pumvisible() ? "\<lt>c-y>(" : "("
inoremap <expr> [ pumvisible() ? "\<lt>c-y>[" : "["
"inoremap <expr> <tab> pumvisible() ? "\<lt>c-y>" : "\<lt>tab>"
" starts autocompletion or does nothing
function InsertCompleteWrapper()
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
        return ""
    else
        return "\<c-n>\<down>"
    endif
endfunction
" make <c-SPACE> the autocomplete key
inoremap <expr> <Nul> pumvisible() ? "\<c-e>" : "\<c-g>u<c-r>=InsertCompleteWrapper()<cr>"


""""""""" tn = :tabnew """""""""""""""""""
nmap tn :tabnew<CR>


""""""""" ü = :shell """""""""""""""""""""
nmap ü :shell<cr>


""""""""" buffer magic """""""""""""""""""
nmap bn :bn!<cr>
nmap bp :bp!<cr>
nmap bd :bd<cr>


""""""""" Y,ä = y/p in clipboard """""""""
nmap Y "+y
vmap Y "+y
nmap ä "+gP
vmap ä "+gP


""""""""" surroundings """""""""""""""""""
" needs surround extension: http://www.vim.org/scripts/script.php?script_id=1697
let g:surround_100 = "do \r end"              " d
let g:surround_68 = "do\n\t\r\nend"           " D
let g:surround_119 = "%w{\r}"                 " w
let g:surround_113 = "%q{\r}"                 " q
let g:surround_120 = "%x{\r}"                 " x
let g:surround_114 = "%r{\r}"                 " r
let g:surround_47 = "/\r/"                    " /
let g:surround_35 = "#{\r}"                   " #
let g:surround_37 = "<% \r %>"                " %
let g:surround_53 = "<%\n\t\r\n%>"            " 5
let g:surround_96  = "`\r'"                   " `


""""""""" switch to other ext """"""""""""
" needs FSwitch extension: http://www.vim.org/scripts/script.php?script_id=2590
nmap <F4> :FSHere<cr>


""""""""" Eclipse-like autoindent whole file """""""""""""""""
nmap <c-f> ggVG==


""""""""" XML Beautifier """""""""""""""""
" needs xmllint installed
function! DoPrettyXML()
    " save the filetype so we can restore it later
    let l:origft = &ft
    set ft=
    " delete the xml header if it exists. This will
    " permit us to surround the document with fake tags
    " without creating invalid xml.
    1s/<?xml .*?>//e
    " insert fake tags around the entire document.
    " This will permit us to pretty-format excerpts of
    " XML that may contain multiple top-level elements.
    0put ='<PrettyXML>'
    $put ='</PrettyXML>'
    silent %!xmllint --format -
    " xmllint will insert an <?xml?> header. it's easy enough to delete
    " if you don't want it.
    " delete the fake tags
    2d
    $d
    " restore the 'normal' indentation, which is one extra level
    " too deep due to the extra tags we wrapped around the document.
    silent %<
    " back to home
    1
    " restore the filetype
    exe "set ft=" . l:origft
    endfunction
command! XMLFormat call DoPrettyXML()
Comments?