dotfiles/.vimrc

299 lines
7.9 KiB
VimL

" VIM Configuration
" Insprired by Vincent Jousse and http://amix.dk/vim/vimrc.html
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cancel vi compatibility
set nocompatible
" Use , as <leader> for shorcut
let mapleader = ","
" Set utf8 encoding as default.
" Need to use lusty explorer under windows because ruby doesn't know latin1
set encoding=utf8
" Set to auto read when a file is changed from the outside
set autoread
" Enable filetype plugins (coloration, indent)
filetype on
filetype plugin on
filetype indent on
" Enable pathogen plugin
call pathogen#infect()
" Mapper esc sur ;;
map ;; <ESC>
imap ;; <ESC>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 3 lines to the cursor - when moving vertically using j/k
set so=3
" Turn on the WiLd menu
"set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc
" Show title, line number, status bar
set title
set number
set ruler
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
"set mat=2
" Don't redraw while executing macros (good performance config)
set lazyredraw
" No annoying sound on errors
set noerrorbells
set novisualbell
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Format the status line
"set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4
set ai " Auto indent
set si " Smart indent
set wrap " Wrap lines
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Searching
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
" If one upercase is provide, searching becomes case sensitive
set smartcase
" Highlight search results
set hlsearch
" Highlight search results during input
set incsearch
" Switch off curent search
map <silent> <leader>/ :nohlsearch<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable
" Make Vim recognize XTerm escape sequences for Page and Arrow
" keys combined with modifiers such as Shift, Control, and Alt.
" See http://www.reddit.com/r/vim/comments/1a29vk/_/c8tze8p
"if &term =~ '^screen'
" " Page keys http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/FAQ
" execute "set t_kP=\e[5;*~"
" execute "set t_kN=\e[6;*~"
"
" " Arrow keys http://unix.stackexchange.com/a/34723
" execute "set <xUp>=\e[1;*A"
" execute "set <xDown>=\e[1;*B"
" execute "set <xRight>=\e[1;*C"
" execute "set <xLeft>=\e[1;*D"
"endif
"set t_tu=
" Compatibility with xterm that support only 256 colors
"let g:solarized_termtrans=1
"let g:solarized_termcolors=256
"set t_Co=256
" Color
"set background=light
"colorscheme solarized
colorscheme desert
""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Switch to alternate file
map <leader>b :bnext<cr>
map <leader>B :bprevious<cr>
" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
" Reminder :
" gt go to next tab
" gT go to previous tab
" {i}gt go to tab in position i
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>
nmap <M-k> mz:m-2<cr>
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
" Delete trailing white space on save, useful for Python
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDTree configuration
" Open with ,e
map <leader>e :NERDTreeToggle<CR>
" Hide file when opening other files
" Need by lusty-explorer
set hidden
" Ack
" Default parameter
let g:ackprg="ack -H --nogroup --column"
" Set a mark an lauch the search
nmap <leader>j mA:Ack<space>
" Set a mark and launch de search on the current word
nmap <leader>ja mA:Ack "<C-r>=expand("<cword>")<cr>"
nmap <leader>jA mA:Ack "<C-r>=expand("<cWORD>")<cr>"
" Ctrlp plugin
let g:ctrlp_map = '<leader>c'
" jedi-vim : autocompletion for python
" jedi-vim supports the following commands:
" Completion <C-Space>
" Goto assignments <leader>g (typical goto function)
" Goto definitions <leader>d (follow identifier as far as possible, includes imports and statements)
" Show Documentation/Pydoc K (shows a popup with assignments)
" Renaming <leader>r
" Usages <leader>n (shows all the usages of a name)
" Open module, e.g. :Pyimport os (opens the os module)
" Syntastic : syntax checking
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" vim-airline: status bar
" Show buffers
let g:airline#extensions#tabline#enabled = 1
" Taglist : show classes, members, ...
" Open with ,t
map <leader>t :TlistToggle<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
en
return ''
endfunction