" VIM Configuration " Insprired by Vincent Jousse and http://amix.dk/vim/vimrc.html """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => General """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Cancel vi compatibility set nocompatible " Use , as 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 ;; imap ;; """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => 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 / :nohlsearch """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => 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 =\e[1;*A" " execute "set =\e[1;*B" " execute "set =\e[1;*C" " execute "set =\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 * :call VisualSelection('f') vnoremap # :call VisualSelection('b') """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => 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 j map k map h map l " Switch to alternate file map b :bnext map B :bprevious " Useful mappings for managing tabs map tn :tabnew map to :tabonly map tc :tabclose " 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 cd :cd %:p:h:pwd """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Editing mappings """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Move a line of text using ALT+[jk] or Comamnd+[jk] on mac nmap mz:m+ nmap mz:m-2 vmap :m'>+`mzgv`yo`z vmap :m'<-2`>my` Misc """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Plugins """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " NERDTree configuration " Open with ,e map e :NERDTreeToggle " 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 j mA:Ack " Set a mark and launch de search on the current word nmap ja mA:Ack "=expand("")" nmap jA mA:Ack "=expand("")" " Ctrlp plugin let g:ctrlp_map = 'c' " jedi-vim : autocompletion for python " jedi-vim supports the following commands: " Completion " Goto assignments g (typical goto function) " Goto definitions d (follow identifier as far as possible, includes imports and statements) " Show Documentation/Pydoc K (shows a popup with assignments) " Renaming r " Usages 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 t :TlistToggle """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => 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