""""""""""""" " SHORTCUTS " """"""""""""" " F1 help " F2 open file in a new tab " S-F2 Split and open file " F3 autotags Update " S-F3 autotags Add " F4 open include file " F5 find C symbol " F6 go to definition " F7 go to calls " F8 view tag list " S-F8 build ctags/cscope databases " M-F8 build kernel ctags/cscope databases " F9 Open NerdTree " M-F9 Show diff line " S-F9 Highlight diff line " M-F10 diff tool " F10 folding " S-F10 unfolding " F11 unhighlight search " F12 paste mode " C-left/right switch tab " C-up/down switch window " M-left/right horizontal size " M-up/down vertical size " gc comment/uncomment " C-K indent selection " \-k Set Kernel Coding style " Use snippets with tab e.g : for (see .vim/bundle/vim-snippets/snippets for available " snippets) """"""""""" " GENERAL " """"""""""" " disable vi-compatible mode set nocompatible " Switch syntax highlighting on when the terminal has colors or when using the " GUI (which always has colors). if &t_Co > 2 || has("gui_running") " Revert with ":syntax off". syntax on " I like highlighting strings inside C comments. " Revert with ":unlet c_comment_strings". let c_comment_strings=1 endif filetype plugin on " enable file type detection and do language-dependent indenting filetype plugin indent on "set clipboard=unnamed """""""" " SAVE " """""""" " disable backup set nobackup " save before compilation set autowrite " Put these in an autocmd group, so that you can revert them with: " ":augroup vimStartup | au! | augroup END" augroup vimStartup au! " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler " (happens when dropping a file on gvim). autocmd BufReadPost * \ if line("'\"") >= 1 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif augroup END " command line history set history=200 " Check that file have not been changed " CursorHold : after cursor move " WinEnter or BufWinEnter au WinEnter * checktime au BufWinEnter * checktime """"""""" " INPUT " """"""""" " allow backspacing in insert mode set backspace=indent,eol,start " don't use Ex mode, use Q for formatting map Q gq " Enable mouse for 'a'll mode set mouse=a " key combination timeout set notimeout "set timeoutlen=4000 " set timeout for multicharacter keys codes (like ) set ttimeout " set timeout to tenth of a second (could be increased for slow terminals) set ttimeoutlen=100 " key event timeout set updatetime=1000 """"""""""" " DISPLAY " """"""""""" " highlight the cursor line set cursorline " show the cursor position set ruler " show mode set showmode " display incomplete commands set showcmd " display line number" set number " set status line set statusline=%<%f\ %h%w%m%r%3.(\ %)%{fugitive#statusline()}%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P " always display status line set laststatus=2 set showcmd " display incomplete commands set wildmenu " display completion matches in a status line " show bad white spaces let c_space_errors = 1 let python_space_error_highlight = 1 highlight link cSpaceError SpaceError highlight link pythonSpaceError SpaceError highlight SpaceError ctermfg=235 cterm=reverse """"""""""""""" " INDENTATION " """"""""""""""" " use tabs at the start of a line, spaces elsewhere set smarttab set smartindent set autoindent "" tab=4 "set tabstop=4 "set softtabstop=4 "set shiftwidth=4 " tab=8 set tabstop=8 set softtabstop=8 set shiftwidth=8 " real tabs " set noexpandtab if has("autocmd") " python " autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab autocmd Filetype python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class autocmd Filetype python set tabstop=4 autocmd Filetype python set expandtab autocmd Filetype python set shiftwidth=4 autocmd Filetype python set softtabstop=4 autocmd Filetype python set modeline " Indentation with = for python need autopep8 autocmd Filetype python set equalprg=autopep8\ - endif if has("autocmd") autocmd BufRead,BufNewFile *.iris set ft=python autocmd BufRead,BufNewFile *.ino set tabstop=4 autocmd BufRead,BufNewFile *.ino set softtabstop=4 autocmd BufRead,BufNewFile *.ino set shiftwidth=4 endif " vim -b : edit binary using xxd-format! augroup Binary au! au BufReadPre *.bin let &bin=1 au BufReadPost *.bin if &bin | %!xxd au BufReadPost *.bin set ft=xxd | endif au BufWritePre *.bin if &bin | %!xxd -r au BufWritePre *.bin endif au BufWritePost *.bin if &bin | %!xxd au BufWritePost *.bin set nomod | endif augroup END if has("autocmd") " detect indentation see http://www.freehackers.org/Indent_Finder if has('python') autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output "' . expand('%') . '"' ) endif else " auto-indent set autoindent " smart-indent set smartindent " C-indent "set cindent " indent-expr "set indentexpr "" endif map :pyf ~/.vim/syntax/clang-format.py imap :pyf ~/.vim/syntax/clang-format.pyi """""""""" " SEARCH " """""""""" " highlight search set hlsearch " unhighlight current search map :nohlsearch imap a " highlight search while typing set incsearch " show matching brackets -> key % set showmatch " tenths of a second before blink matching brackets set mat=5 " search word and list lines to jump with F3 " map [I:let nr = input("Which one: ") execute "normal " . nr ."[\t" " go to declaration with F5 " map gd:nohlsearch " imap i " try to go to definition or declaration with , and go back with ; function GoToDefinition() try execute "cscope find g " . expand("") catch /:E259:/ try execute "tag " . expand("") catch /:E257:/ execute "normal! gd" execute "nohlsearch" endtry endtry endfunction nmap , :call GoToDefinition() nmap ; " plugin taglist let Tlist_Ctags_Cmd = '/usr/bin/ctags' let Tlist_Process_File_Always = 1 let Tlist_Exit_OnlyWindow = 1 "let Tlist_Close_On_Select = 1 let Tlist_Auto_Highlight_Tag = 1 let Tlist_Display_Prototype = 0 let Tlist_Display_Tag_Scope = 0 let Tlist_Show_One_File = 1 let Tlist_Compact_Format = 1 let Tlist_Enable_Fold_Column = 0 " sort by name or order ? let Tlist_Sort_Type = "name" "let Tlist_File_Fold_Auto_Close = 1 let Tlist_Inc_Winwidth = 0 "let Tlist_Use_Horiz_Window = 1 let Tlist_Use_Right_Window = 1 " open/close tag list window with F8 "map :TlistToggle nmap :TagbarToggle " close preview window after a completion if has("autocmd") autocmd CursorMovedI *.{[hc],cpp} if pumvisible() == 0|pclose|endif autocmd InsertLeave *.{[hc],cpp} if pumvisible() == 0|pclose|endif endif function! TagInNewTab() let word = expand("") redir => tagsfiles silent execute 'set tags' redir END tabe execute 'setlocal' . strpart(tagsfiles, 2) execute 'tag ' . word endfunction map :call TagInNewTab() """"""""" " PASTE " """"""""" " set/unset paste mode with F12/shift+F12 map :set paste map :set nopaste imap :set paste imap set pastetoggle= " paste with reindent with Esc prefix nnoremap P P'[v']= nnoremap p p'[v']= """""""""" " WINDOW " """""""""" " create window below or at right of the current one set splitbelow set splitright " if multiple windows if bufwinnr(1) " vertically increase/decrease window size with alt+up/alt+down map + map - imap a imap a " horizontally increase/decrease window size with alt+right/alt+left map > map < imap a imap a " switch to next/previous tab with ctrl+right/ctrl+left map gt map gT imap a imap a " switch to next/previous window with ctrl+down/ctrl+up map w map W imap a imap a endif " open automatically quickfix window if has("autocmd") autocmd QuickFixCmdPost * cw endif " open a file in the same directory as the current file with F2 and split with shift+F2 map :tabe =expand("%:h") . "/" nmap :split =expand("%:h") . "/" """""""" " HELP " """""""" " allow embedded man page runtime! ftplugin/man.vim " show vimrc with shift+F1 nmap :tabe ~/.vimrcgg imap " show contextual help with F1 function Help() try if exists('b:current_syntax') && b:current_syntax == "python" :call ShowPyDoc(expand(""), 1) else execute "Man " . expand("") endif catch /:E149:/ execute "help " . expand("") endtry endfunction nmap :call Help() imap " show VIM help with alt+shift+F1 nmap :help =expand("") imap """"""""" " TOOLS " """"""""" " show current changes with F10 command! DiffOrig \ vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis \ | wincmd p | diffthis map :DiffOrig imap a " show git diff when committing let g:git_diff_spawn_mode = 1 if has("autocmd") autocmd BufRead,BufNewFile COMMIT_EDITMSG setf git endif " zf#j creates a fold from the cursor down # lines. "zf/string creates a fold from the cursor to string . "zj moves the cursor to the next fold. "zk moves the cursor to the previous fold. "zo opens a fold at the cursor. "zO opens all folds at the cursor. "zm increases the foldlevel by one. "zM closes all open folds. "zr decreases the foldlevel by one. "zR decreases the foldlevel to zero -- all folds will be open. "zd deletes the fold at the cursor. "zE deletes all folds. "[z move to start of open fold. "]z move to end of open fold. " fold form this bracket nmap zfa{ " unfold or use End nmap zo " Autosave folding "au BufWinLeave * mkview " Autoload folding "au BufWinEnter * silent loadview """""""""""""""""""""""""""""""""""""""""""""""""" "Omni-completion par CTRL-X_CTRL-O """"""""""""""""""""""""""""""""""""""""""""""""""" set omnifunc=syntaxcomplete#Complete " Enable omnicppcompletion let OmniCpp_ShowAccess = 0 let OmniCpp_LocalSearchDecl=1 let OmniCpp_MayCompleteDot = 1 " autocomplete after . let OmniCpp_MayCompleteArrow = 1 " autocomplete after -> let OmniCpp_MayCompleteScope = 1 " autocomplete after :: set path=.,..,/usr/local/include,/usr/include """"""""""""" " Latex " """"""""""""" " package vim-latexsuite " Insert the following line in your ~/.vim/ftplugin/tex.vim file: " imap it Tex_InsertItemOnThisLine " compile with \ll set grepprg=grep\ -nH\ $* let g:tex_flavor = "pdflatex" imap it Tex_InsertItemOnThisLine let g:Tex_DefaultTargetFormat="pdf" if has('gui_running') colorscheme darkblue else colorscheme mycolor endif cnoremap sudow w !sudo tee % >/dev/null """"""""""" " NerdTree """"""""""" autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif map :NERDTreeToggle """"""""""" " GitGutter """"""""""" map :GitGutterSignsToggle map :GitGutterLineHighlightsToggle """""""""" " KernelFormatting """""""""" nnoremap k :SetLinuxFormatting """""""""" " LocalConfig """""""""" if filereadable(expand('~/.vimrc.local')) " Plugins list and settings should be loaded " only once. Load local_settings block let g:local_plugins = 0 let g:local_settings = 1 source ~/.vimrc.local endif """""""""" " W3m """""""""" let g:w3m#external_browser = 'firefox' """""""""" " Debug """""""""" "Or start vim with -V[VERBOSENUMBER][FILE] function! ToggleVerbose() if !&verbose set verbosefile=~/.log/vim/verbose.log set verbose=15 else set verbose=0 set verbosefile= endif endfunction """"""""" " Plugin" """"""""" "Using vundle "cf. https://github.com/gmarik/Vundle.vim ":PluginInstall to install them set rtp+=~/.vim/bundle/Vundle.vim/ call vundle#begin() " let Vundle manage Vundle, required Plugin 'gmarik/Vundle.vim' " Show current modified line Plugin 'airblade/vim-gitgutter' " Communication with git Plugin 'tpope/vim-fugitive' " Support for Gbrowse Plugin 'tpope/vim-rhubarb' " Comment block of code Plugin 'tpope/vim-commentary' " Make terminal vim and tmux work better together. Plugin 'tmux-plugins/vim-tmux-focus-events' " language pack Plugin 'sheerun/vim-polyglot' " color even for terminal without gui... " Plugin 'vim-scripts/CSApprox' " Same as gitgutter but for other cvs "Plugin mhinz/vim-signify " echofunc -> what is the current function Plugin 'mbbill/echofunc' " What to test some color ? Plugin 'vim-scripts/Colour-Sampler-Pack.git' "More VCS Management Plugin 'vim-scripts/vcscommand.vim' " More Snippets : Plugin 'tomtom/tlib_vim' Plugin 'MarcWeber/vim-addon-mw-utils' Plugin 'honza/vim-snippets' Plugin 'garbas/vim-snipmate' " Filesystem exploration Plugin 'scrooloose/nerdtree' " Python completion "Plugin 'klen/python-mode' "" Python Bundle "Plugin 'davidhalter/jedi-vim' "Plugin 'scrooloose/syntastic' "Plugin 'majutsushi/tagbar' "Plugin 'Yggdroot/indentLine' "" Python Code Checking "Plugin 'kevinw/pyflakes-vim' " Omni completion for cpp Plugin 'vim-scripts/OmniCppComplete' " List current file function " let $GIT_SSL_NO_VERIFY = 'true' Plugin 'gitlab@gitlab.mathux.org:Mathieu/taglist.git' " Tagbar look like a maintened taglist Plugin 'majutsushi/tagbar' "Syntax checking Plugin 'scrooloose/syntastic.git' "Completion (need more configuration for python, c# ...) "Plugin 'Valloric/YouCompleteMe' " VimWiki Plugin 'vimwiki/vimwiki' let g:vimwiki_list=[{'path':'~/.vim/vimwiki'}] " Align " eg. to align on the "=" do :'<,'>Align = Plugin 'vim-scripts/Align' " open file at the given line with the file.txt:20 syntax " But it's screw up the git commit message "Plugin 'bogado/file-line' " % match if/then/else/html ... Plugin 'tmhedberg/matchit' " Kernel Formatting Plugin 'gregkh/kernel-coding-style.git' " Web browsing "Plugin 'yuratomo/w3m.vim' " Recognize Key in screen/tmux "Plugin 'drmikehenry/vim-fixkey' "Complete delimiters Plugin 'Raimondi/delimitMate.git' call vundle#end()