gaby-dotfiles / vimrc

Full commit
" My current vimrc
" Feel free to grab what you like inside
" Gabriel AHTUNE <larchange[at]>

" remove menu and toolbar
set guioptions-=m  "remove menu bar
set guioptions-=T  "remove toolbar

" Encoding and line end
set encoding=utf-8
set ffs=unix,dos,mac

" Automatic reloading of .vimrc
if !exists("autocommandes_incluses")
    let autocommandes_incluses=1
    autocmd bufwritepost .vimrc source ~/.vimrc
    autocmd bufwritepost .vimrc call Pl#Load()

" close quickfix when not looking at.
autocmd FileType qf nmap <buffer> <cr> <cr>:lcl<cr>

" Backup
set backupdir=~/.vim/backup/
set directory=~/.vim/backup/

" remap leader key
let mapleader = ","

" 80 characters limit
set tw=79

syntax on
set nocompatible
set bs=2
set number
set title
"set ruler
filetype indent on
set autoread
set scrolloff=3
set showcmd
set ttyfast
set ttymouse=xterm
set mouse=a

" remove ESC delay in no gui env
set ttimeout
set ttimeoutlen=100

" Automatically wrap right/left to next/previous line
set whichwrap+=<,>,h,l,[,]

" No auto change the current directory
set noautochdir 
nn <Leader>cd :lcd %:h<CR>

" search results
set hlsearch
set incsearch
set ignorecase 
set magic
set showmatch

" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500

" Others MISC
set virtualedit=block
set tags=tags;
map <F8> :!/usr/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

" Text, tab and indent related
set gfn=Monaco
set expandtab " Use spaces instead of tabs
set smarttab
set shiftwidth=4 " 1 tab == 4 spaces
set tabstop=4
set ai "Auto indent
set si "Smart indent
set copyindent
set wrap "Wrap lines
set history=1000 

" Some good functions
vnoremap <Leader>s :sort<CR>
noremap <M-m> <ESC>:marks<CR>
vnoremap <M-m> <ESC>:marks<CR>

noremap <Leader>e :e .<CR>

" Re-indent and clean double empty line CTRL + ALT + h
noremap <C-M-h> <ESC>mtgg=G<ESC>:%s/\n[\s\t]*\n\+/\r\r/g<CR>:nohl<CR>'t

" Bind nohl
" Removes highlight of your last search
noremap <leader>n :nohl<CR>
vnoremap <leader>n :nohl<CR>

" Display trailing spaces, tabs by showing a dot
set list
set listchars=tab:>.,trail:.,extends:#,nbsp:.
autocmd filetype html,xml set listchars-=tab:>.

" Append modeline after last line in buffer.
" Use substitute() instead of printf() to handle '%%s' modeline in LaTeX
" files.
function! AppendModeline()
  let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d :",
        \ &tabstop, &shiftwidth, &textwidth)
  let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
  call append(line("$"), l:modeline)
nnoremap <silent> <Leader>ml :call AppendModeline()<CR>

" Make vim a bit more user friendly ...
" Shorcuts for tabs
map <Leader>t <ESC>:tabnew<CR>

" shorcuts for buffers
set hidden " Do not need to save file when opening a new file.
nnoremap <Leader>b :enew<CR>
nnoremap <M-b> :buffers<CR>:b 
vnoremap <M-b> <ESC>:buffers<CR>:b 
inoremap <M-b> <ESC>:buffers<CR>:b 
nnoremap gb :bnext<CR>
nnoremap gB :bprev<CR>
map <C-F3> <ESC>:bdelete<CR>
map <Leader>x <ESC>:bd<CR>

" Better window split 
nnoremap <C-w>v <C-w>v<C-w>l
nnoremap <C-w>s <C-w>s<C-w>j

" Shortcuts for jumps
nnoremap <M-j> :jumps<CR>

" Shortcuts for tags (Etiquettes)
" as C-T already mapped to new tabs ...
nnoremap <backspace> :pop<CR>

" Copy cut past
set pastetoggle=<F2>
set clipboard=unnamedplus

"vmap <Enter> "*y<ESC>
"vmap <Enter> y<ESC>
" select just pasted content
nnoremap <leader>v V`]

" save, save as
noremap <C-s> :w<CR>
noremap <C-M-s> :w 

"undo, redo
set undolevels=1000

" Indentation
vnoremap < <gv
vnoremap > >gv

" fold
nnoremap <space> za

" Moving in wrapped lines
nnoremap j gj
nnoremap k gk
nnoremap <up> gk
nnoremap <down> gj

" auto completion
inoremap <C-space> <C-x><C-O>
"set ofu=syntaxcomplete#Complete
set completeopt+=longest,menu
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
  \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'

inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
  \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'

autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif

" Diff
nnoremap <Leader>dd :vert diffsplit 
nnoremap <Leader>dp :vert diffpatch 
nnoremap <Leader>dw :windo diffthis<CR>
nnoremap <Leader>dx :windo diffoff<CR>
nnoremap <Leader>dt :diffthis<CR>
nnoremap <Leader>do :diffoff<CR>
nnoremap <Leader>du :diffupdate<CR>
" Ignore space
set diffopt+=iwhite

" Spell check
let b:myLang=0
let g:myLangList=["nospell","en","fr"]
function! ToggleSpell()
    let b:myLang=b:myLang+1
    if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
    if b:myLang==0
        setlocal nospell
        execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
    echo "spell checking language:" g:myLangList[b:myLang]

nmap <silent> <F7> :call ToggleSpell()<CR>

" Toggle 80 column marker
inoremap <F3> <ESC>:call ToggleColorColumn()<CR>i
vnoremap <F3> <ESC>:call ToggleColorColumn()<CR>gv
nnoremap <F3> <ESC>:call ToggleColorColumn()<CR>

func! ToggleColorColumn()
    if exists("b:colorcolumnon") && b:colorcolumnon
        let b:colorcolumnon = 0
        exec ':set colorcolumn=0'
        echo '80 column marker off'
        let b:colorcolumnon = 1
        exec ':set colorcolumn=80'
        echo '80 column marker on'

nmap <F5> a<C-R>=strftime("%Y-%m-%d %I:%M:%S")<CR><Esc>
imap <F5> <C-R>=strftime("%Y-%m-%d %I:%M:%S")<CR>

" Toggle Vexplore with <F10> 
function! ToggleVExplorer()
  if exists("t:expl_buf_num")
          let g:netrw_browse_split = 0
          let expl_win_num = bufwinnr(t:expl_buf_num)
          let cur_win_nr = winnr()
          exec expl_win_num . 'wincmd w'
          exec cur_win_nr . 'wincmd w'
          unlet t:expl_buf_num
          unlet t:expl_buf_num
      let g:netrw_browse_split = 4
      exec '1wincmd w'
      let t:expl_buf_num = bufnr("%")
map <silent> <F10> :call ToggleVExplorer()<CR>

let g:netrw_altv = 1
let g:netrw_winsize = 25

" Python
let g:py_select_leading_comments = 0
let b:unaryTagsStack = ""
let python_highlight_all=1
let python_slow_sync=1
let python_print_as_function=1

" Rst support for title
nnoremap <leader>0 yyPVr#jpVr#j
nnoremap <leader>1 yypVr=j
nnoremap <leader>2 yypVr-j
nnoremap <leader>3 yypVr~j
nnoremap <leader>4 yypVr"j

imap <C-x>m <ESC>:r! <cword><CR><ESC>i

" Start plugins configuration
" Pathogen config
"     mkdir -p ~/.vim/autoload ~/.vim/bundle
"     curl '' \
"         > ~/.vim/autoload/pathogen.vim
call pathogen#infect()

" cd ~/.vim/bundle
" git clone git://
" once slime and pathogen installed, you can run code in comment to install the
" other plugins
let g:slime_python_ipython=1
let g:slime_target = "tmux"
let g:slime_paste_file="/tmp/slime_paste_file"
nmap <F12> <plug>SlimeParagraphSend
vmap <F12> <plug>SlimeParagraphSend
imap <F12> <ESC><F12>i

" set colorscheme
"     cd ~/.vim/bundle/
"     git clone
colorscheme jellybeans

" Powerline config
"     cd ~/.vim/bundle/
"     git clone
set laststatus=2

" Taglist 
map <F4> :TlistToggle<cr>

" Settings for ctrlp
"     cd ~/.vim/bundle
"     git clone
let g:ctrlp_max_height = 20
set wildignore+=*.pyc
set wildignore+=*_build/*
set wildignore+=*/coverage/*
set wildignore+=*.mp3,*.pdf,*.png,*.jpg,*.mov,*.bmp,*.mp4,*.avi

" Syntastic
" git clone
let g:syntastic_error_symbol='✗'
let g:syntastic_warning_symbol='⚠'
let g:syntastic_auto_jump=1
let g:syntastic_auto_loc_list=1
let g:syntastic_mode_map = { 'mode': 'passive',
            \ 'active_filetypes': [],
            \ 'passive_filetypes': [] }
map <F2> :w<CR>:SyntasticCheck<CR>

" git clone git://
nnoremap <Leader>cR <plug>VCSRevert
let VCSCommandDeleteOnHide=1

" git clone

" Opted
let g:opted_dir = '~/.opted/v003'

" Configurationless plugins
" cd ~/.vim/bundle/
" git clone
" git clone
" git clone
" git clone
" git clone
" git clone
" git clone
" git clone
" git clone
" require L9 library
" git clone
" hg clone

" # Install rst support
" yaourt -S --noconfirm vim_bridge-git
" cd ~/.vim/bundle/
" git clone

" snipmate, snippets
" git clone
" git clone

" Apply the filetype customization only at the end... to avoid conflict
filetype plugin on