Source

gaby-dotfiles / vimrc

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

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GENERAL CONFIGURATION
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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()
endif

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

" remap leader key
let mapleader = ","

" 80 characters limit
set tw=79
set colorcolumn=80
highlight ColorColumn ctermbg=233
" Boring on html, and raw file...
" match ErrorMsg '\%>79v.\+'

" Window geometry
" set columns=100
" set lines=30

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,[,]

" Automatically change the current directory
set autochdir

" 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\ Regular\ 10
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)
endfunction
nnoremap <silent> <Leader>ml :call AppendModeline()<CR>

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

" shorcuts for buffers
set hidden " Do not need to save file when opening a new file.
nnoremap <M-b> :buffers<CR>:b 
vnoremap <M-b> <ESC>:buffers<CR>:b 
inoremap <M-b> <ESC>:buffers<CR>:b 
nnoremap <Leader>b :bnext<CR>
map <C-F3> <ESC>:bdelete<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>
" ] difficult on my french keyboard
nnoremap <C-k> <C-]>

" shorcuts for buffers
set hidden " Do not need to save file when opening a new file.
nnoremap <M-b> :buffers<CR>:b 
vnoremap <M-b> <ESC>:buffers<CR>:b 
inoremap <M-b> <ESC>:buffers<CR>:b 
nnoremap <Leader>b :bnext<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
    else
        execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
    endif
    echo "spell checking language:" g:myLangList[b:myLang]
endfunction

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

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Start plugins configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pathogen config
"     mkdir -p ~/.vim/autoload ~/.vim/bundle
"     curl 'www.vim.org/scripts/download_script.php?src_id=16224' \
"         > ~/.vim/autoload/pathogen.vim
call pathogen#infect()

" cd ~/.vim/bundle
" git clone git://github.com/jpalardy/vim-slime.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 https://github.com/nanotech/jellybeans.vim
colorscheme jellybeans

" Powerline config
"     cd ~/.vim/bundle/
"     git clone https://github.com/Lokaltog/vim-powerline.git
set laststatus=2

" Taglist 
map <F4> :TlistToggle<cr>

" Settings for ctrlp
"     cd ~/.vim/bundle
"     git clone https://github.com/kien/ctrlp.vim.git
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 https://github.com/scrooloose/syntastic.git
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://repo.or.cz/vcscommand.git
nnoremap <Leader>cR <plug>VCSRevert
let VCSCommandDeleteOnHide=1

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

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Configurationless plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cd ~/.vim/bundle/
" git clone https://github.com/phillipberndt/python-imports.vim.git
" git clone https://github.com/vim-scripts/python_match.vim.git
" git clone https://github.com/vim-scripts/match:it.zip.git
" git clone https://github.com/kien/ctrlp.vim.git
" git clone https://github.com/rstacruz/sparkup.git
" git clone https://github.com/tpope/vim-surround
" git clone https://github.com/psjay/python.vim.git

" require L9 library
" git clone https://github.com/vim-scripts/L9.git
" hg clone https://bitbucket.org/ns9tks/vim-autocomplpop

" # Install rst support
" yaourt -S --noconfirm vim_bridge-git
" cd ~/.vim/bundle/
" git clone https://github.com/nvie/vim-rst-tables.git

" snipmate, snippets
" git clone https://github.com/msanders/snipmate.vim.git
" git clone https://github.com/scrooloose/snipmate-snippets.git

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