dotfiles / vim / .vimrc

" .vimrc
" -----------
" Shortcuts:
"   F1       Toggle paste mode
"   F4       Show QuickBuf for buffer selection/manipulation
"   F5       Run 'make' command and show fix window
"   F8       Show NERDTree
"   F9       Show tags list
"   :A       Jump to corresponding file (ie. from .c jump to .h)
"   :AS      Split jump to corresponding file (horizontal)
"   :AV      Split jump to corresponding file (vertical)
"   \cr      Open C reference on keyword with cursor
"   \fl      Toggle folding
"   \vo      Open EasyGrep options
"   \vv      Open EasyGrep searching on current word
"   \wh      Toggle whitespace visibility
" Commands:
"  :Vissort         Sort lines using column selected by visual selection
"  :set mouse=i     Mostly turn off mouse

set nocompatible                    " allow what only vim do

fun VimConfig_default()
    " my default vim settings
    set viminfo='24,/10,"1000,:0        " set .viminfo file settings

    set backspace=indent,eol,start      " makes backspace work
    set hidden
    set mouse=a
    set noswapfile
    set number
    set printoptions+=syntax:y
    set ruler
    set smartcase
    set wildmenu                        " show completions graphically

    " default tabbing settings
    set noexpandtab
    set shiftwidth=4
    set smarttab
    set softtabstop=4
    set tabstop=4

    " default whitespace settings
    set listchars=trail:.,tab:>-,eol:$
    set nolist
    " map <Leader>wh to toggle whitespace visibility
    nnoremap <Leader>wh :set list!<CR>

    " no need for 'visual bell'
    set noerrorbells visualbell t_vb=
    autocmd GUIEnter * set visualbell t_vb=
call VimConfig_default()

fun VimConfig_filetype()
    filetype on
    filetype indent on
    filetype plugin on
call VimConfig_filetype()

fun VimConfig_display()
    " default settings on display

    " set colorscheme
    set t_Co=256            " using 256 colors
    set background=dark
    colorscheme jellybeans  " nice colors for my eyes

    set guifont=Monaco\ 10  " subjectively, this font is beautiful for all kinds of coding
    set guioptions=magi     " no menu & toolbar

    " statusbar
    set laststatus=2
    set statusline=
    set statusline+=%-1.3n\                      " buffer number
    set statusline+=%P\ %-5.10(%l,%c%V%)\        " position in buffer
    set statusline+=%t\                          " file name (if any)
    set statusline+=%h%m%r%w                     " flags
    set statusline+=%=%<                         " switch to right alignment
    set statusline+=<%{&encoding}:               " encoding
    set statusline+=%{&fileformat}:              " file format
    set statusline+=%{strlen(&ft)?&ft:'none'}>\  " file type
    set statusline+=x%02.4B                      " current char
call VimConfig_display()

fun VimConfig_search()
    " default settings on searching:
    set hlsearch    " highlight search
    set ignorecase  " run case-insensitive search
    set showmatch   " show matches
    set incsearch   " enable search while typing

    " highlighted items get bold font
    hi! Statement cterm=bold
    hi! Type cterm=bold
call VimConfig_search()

fun VimConfig_shortcuts()
    map  <F1> :set paste!<CR>

    " map F5 to run make
    nmap <F5> :make<CR>

    " map '+' and '-' to make window bigger or smaller
    if bufwinnr(1)
       map + <C-W>+
       map - <C-W>-
call VimConfig_shortcuts()

fun VimConfig_programming()
    " default settings for using vim as programming editor

    syntax on           " make everything shiny!!
    set autoindent
    set smartindent

    function! Feat_folding()
        " fold lines
        set fillchars=fold:-
        set foldcolumn=1
        set foldlevel=1

        " map <Leader>fl to toggle folding
        nnoremap <Leader>fl :set foldenable!<CR>
    call Feat_folding()

call VimConfig_programming()

fun VimConfig_plugin_easygrep()
    " default settings for plugin: EasyGrep
    let g:EasyGrepEveryMatch = 1
    let g:EasyGrepIgnoreCase = 0
    let g:EasyGrepMode = 2
    let g:EasyGrepRecursive = 0
    let g:EasyGrepReplaceWindowMode = 2
call VimConfig_plugin_easygrep()

fun VimConfig_plugin_nerdtree()
    " default settings for plugins: NERDTree
    let NERDTreeWinPos="right"

    " map F8 to show/hide NERDTree
    nnoremap <silent> <F8> :NERDTreeToggle<CR>
call VimConfig_plugin_nerdtree()

fun VimConfig_plugin_tagbar()
    " default settings for plugins: Tagbar
    let g:tagbar_width = 32
    let g:tagbar_iconchars = ['+', '-']

    " map F9 to show/hide Tagbar
    nnoremap <silent> <F9> :TagbarToggle<CR>
call VimConfig_plugin_tagbar()

" Always do a full syntax refresh
autocmd BufEnter * syntax sync fromstart