" Highly based on amix/vimrc : https://github.com/amix/vimrc " Sections: " -> General " -> VIM user interface " -> Colors and Fonts " -> Files and backups " -> Text, tab and indent related " -> Visual mode related " -> Moving around, tabs and buffers " -> Status line " -> Editing mappings " -> vimgrep searching and cope displaying " -> Spell checking " -> Misc " -> Helper functions " "{{{ OS specifics commands " if has("win64") || has("win32") || has("win16") " "{{{ Windows " " source $VIMRUNTIME/vimrc_example.vim " source $VIMRUNTIME/mswin.vim " behave mswin " " set diffexpr=MyDiff() " function! MyDiff() " let opt = '-a --binary ' " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif " let arg1 = v:fname_in " if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif " let arg2 = v:fname_new " if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif " let arg3 = v:fname_out " if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif " if $VIMRUNTIME =~ ' ' " if &sh =~ '\ ' . arg3 " if exists('l:shxq_sav') " let &shellxquote=l:shxq_sav " endif " endfunction " " " Turn persistent undo on " try " set undodir=%userprofile%\Vim\vimfiles\undodir " set undofile " catch " endtry " " "= CPP compile and run commands " " augroup CppBuild " autocmd! " autocmd filetype cpp nnoremap :w exec '!g++ -std=c++14 -Wall -Wextra -pedantic '.shellescape('%').' -o '.shellescape('%:r').' && '.shellescape('%:r') " autocmd filetype cpp nnoremap :w exec '!clang++ -std=c++14 -Wall -pedantic -Werror '.shellescape('%').' -o '.shellescape('%:r').' && .\'.shellescape('%:r') " augroup END " " " " Vim default font on gvim " set guifont=Hack:h18 " " "}}} " " else " " " {{{ Linux " "Turn persistent undo on means that you can undo even when you close a buffer/VIM try set undodir=~/.vim/undodir set undofile catch endtry " CPP compile and run commands augroup CppBuild autocmd! autocmd filetype cpp nnoremap d :w exec '!g++ -std=c++14 -Wall -Wextra -pedantic '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r') autocmd filetype cpp nnoremap f :w exec '!clang++ -std=c++14 -stdlib=libc++ -Wall -pedantic -Werror '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r') augroup END " "}}} " " " endif " "}}} " {{{ Plugin Handlers Begin" " Specify a directory for plugins (for Neovim: ~/.local/share/nvim/plugged) call plug#begin('~/.vim/plugged') set nocompatible " be iMproved, required "filetype off " required " set the runtime path to include Vundle and initialize "set rtp+=~/.vim/bundle/Vundle.vim "call vundle#begin() " alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required " Plugin 'VundleVim/Vundle.vim " }}} " {{{ Plugins Plug 'valloric/youcompleteme' Plug 'tpope/vim-surround' Plug 'tpope/vim-fugitive' Plug 'scrooloose/nerdcommenter' Plug 'tpope/vim-repeat' Plug 'majutsushi/tagbar' Plug 'junegunn/vim-easy-align' Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'easymotion/vim-easymotion' Plug 'SirVer/ultisnips' Plug 'honza/vim-snippets' Plug 'ervandew/supertab' Plug 'xolox/vim-easytags' Plug 'xolox/vim-misc' Plug 'myusuf3/numbers.vim' Plug 'scrooloose/syntastic' Plug 'zhou13/vim-easyescape' Plug 'octol/vim-cpp-enhanced-highlight' Plug 'scrooloose/nerdtree' Plug 'terryma/vim-multiple-cursors' Plug 'mhinz/vim-startify' " The fancy start screen for Vim. Plug 'christoomey/vim-tmux-navigator' Plug 'airblade/vim-gitgutter' " session management Plug 'tpope/vim-obsession' " Autosave Session.vim Plug 'dhruvasagar/vim-prosession' Plug 'gikmx/ctrlp-obsession' " Airline Plugins Plug 'itchyny/lightline.vim' " Plug 'bling/vim-airline' " ColorScheme Plugins Plug 'tomasr/molokai' Plug 'morhetz/gruvbox' Plug 'NLKNguyen/papercolor-theme' Plug 'sonph/onehalf', {'rtp': 'vim/'} Plug 'dikiaap/minimalist' Plug 'vegangaro/graynito' " Unused but interesting Plugins Plug 'vim-airline/vim-airline-themes' " Plug 'xuhdev/singlecompile' " Plug 'Yggdroot/indentLine' " Plug 'tpope/vim-commentary' " Plug 'benmills/vimux' " Plug 'tomtom/tcomment_vim' " Plug 'ctrlpvim/ctrlp.vim' " Plug 'wincent/command-t' " Plug 'godlygeek/tabular' " align text " }}} " {{{ Plugin Handlers End " Initialize plugin system call plug#end() "Vundle things " All of your Plugins must be added before the following line " call vundle#end() " required " filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line " }}} " {{{ General " Sets how many lines of history VIM has to remember set history=500 " Enable filetype plugins filetype plugin on filetype indent on " Set to auto read when a file is changed from the outside set autoread " With a map leader it's possible to do extra key combinations " like w saves the current file let mapleader = "," let g:mapleader = "," " Write and quit with c-s and c-q nnoremap :w nnoremap :q " Cut/Copy/Paste to work using the standard hotkeys vmap u "+yy vmap y "*yy " vmap c"+p " imap + " " Yanked words to clipboard vnoremap k "*y vnoremap j "+y " " :W sudo saves the files " (useful for handling the permission-denied error) " command W w !sudo tee % > /dev/null " A simple mapping to break the line at the cursor by pressing Ctrl+Enter: " nmap i[Ctrl+V][Enter][Ctrl+V][Esc][Enter] " }}} " {{{ VIM user interface " set 7 lines to the cursor - when moving vertically using j/k set so=7 " Turn on the WiLd menu set wildmenu " Ignore compiled files set wildignore=*.o,*~,*.pyc if has("win16") || has("win32") set wildignore+=.git\*,.hg\*,.svn\* else set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store endif "Always show current position set ruler " Height of the command bar set cmdheight=2 " A buffer becomes hidden when it is abandoned set hid " Configure backspace so it acts as it should act set backspace=eol,start,indent set whichwrap+=<,>,h,l " Ignore case when searching set ignorecase " When searching try to be smart about cases set smartcase " Highlight search results set hlsearch " Makes search act like search in modern browsers set incsearch " Don't redraw while executing macros (good performance config) set lazyredraw " For regular expressions turn magic on set magic " 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 " No annoying sound on errors set noerrorbells set novisualbell set t_vb= set tm=500 " Properly disable sound on errors on MacVim if has("gui_macvim") autocmd GUIEnter * set vb t_vb= endif " ***************************** " Add a bit extra margin to the left set foldcolumn=1 setl foldmethod=marker " Tweak the color of the fold display column " au ColorScheme * hi FoldColumn cterm=bold ctermbg=233 ctermfg=146 set nowrap "Don't wrap lines set linebreak "Wrap lines at convenient points " call alias inside vim set shell=/bin/bash\ -i " }}} " {{{ colors " enable syntax highlighting syntax enable " set utf8 as standard encoding and en_us as the standard language set encoding=utf8 " use unix as the standard file type set ffs=unix,dos,mac " let g:xxxx_original = 1 " colorscheme onehalfdark " status line set laststatus=2 " lightline themes : :h g:lightline.colorscheme let g:lightline = { \ 'colorscheme': 'graynito', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], \ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ] \ }, \ 'component_function': { \ 'gitbranch': 'fugitive#head' \ }, \ } " "airlines themes " let g:airline_theme='zenburn' " let g:airline_powerline_fonts = 1 " " 256 colors " set t_ut= " set termguicolors " set background=light " set background=dark set t_co=256 " }}} " {{{ Files, backups and undo " " Turn backup off, since most stuff is in SVN, git et.c anyway... set nobackup set nowb set noswapfile " }}} " {{{ 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 " Linebreak on 500 characters set lbr set tw=500 set ai "Auto indent set si "Smart indent set wrap "Wrap line "***************************** "Fix indentation nnoremap mzgg=G`z " if has('gui_running') " set list listchars=tab:▶‒,nbsp:∙,trail:∙,extends:▶,precedes:◀ " let &showbreak = '↳' " else " set list listchars=tab:>-,nbsp:.,trail:.,extends:>,precedes:< " let &showbreak = '^' " endif " " " " set showbreak=\\ " }}} " {{{ Visual mode related " Visual mode pressing * or # searches for the current selection " Super useful! From an idea by Michael Naumann vnoremap * :call VisualSelection('', '')/=@/ vnoremap # :call VisualSelection('', '')?=@/ to / (search) and Ctrl- to ? (backwards search) " map / " map ? " " Disable highlight when is pressed map :noh " " Smart way to move between windows map j map k map h map l " Close the current buffer map bd :Bclose:tabclosegT " Close all the buffers map ba :bufdo bd map l :bnext map h :bprevious " Useful mappings for managing tabs map tn :tabnew map to :tabonly map tc :tabclose map tm :tabmove map t :tabnext " Let 'tl' toggle between this and the last accessed tab let g:lasttab = 1 nmap tl :exe "tabn ".g:lasttab au TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory map te :tabedit =expand("%:p:h")/ " Switch CWD to the directory of the open buffer map cd :cd %:p:h:pwd " Specify the behavior when switching between buffers try set switchbuf=useopen,usetab,newtab set stal=2 catch endtry " Return to last edit position when opening files (You want this!) au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif " }}} " {{{ Editing mappings " Remap VIM 0 to first non-blank character " map 0 ^ " Delete trailing white space on save, useful for some filetypes ;) fun! CleanExtraSpaces() let save_cursor = getpos(".") let old_query = getreg('/') silent! %s/\s\+$//e call setpos('.', save_cursor) call setreg('/', old_query) endfun if has("autocmd") autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces() endif " mapping F5 to remove whitespace trailing nnoremap :let _s=@/ :%s/\s\+$//e :let @/=_s :nohl :unlet _s " Manually Remove whitespace traling by typing command: / $ " Fix indentation map mzgg=G`z " }}} " {{{ Spell checking " Set spell check for en and br set spelllang=en,br " Pressing ,ss will toggle and untoggle spell checking map ss :setlocal spell! " Shortcuts using map sn ]s map sp [s map sa zg map s? z= " }}} " {{{ Misc " Remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm " Quickly open a buffer for scribble map q :e ~/buffer " Quickly open a markdown buffer for scribble map x :e ~/buffer.md " Toggle paste mode on and off " map pp :setlocal paste! " Toggle auto-indenTING FOR CODE PAste set pastetoggle= " }}} " {{{ Fast editing and reloading of vimrc configs nnoremap e :tabedit $MYVIMRC " }}} " {{{ GUI related Fonts GVIM " Set font according to system if has("mac") || has("macunix") set gfn=Hack:h14,Source\ Code\ Pro:h15,Menlo:h15 elseif has("win16") || has("win32") set gfn=Hack:h14,Source\ Code\ Pro:h12,Bitstream\ Vera\ Sans\ Mono:h11 elseif has("gui_gtk2") set gfn=Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11 elseif has("linux") set gfn=Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11 elseif has("unix") set gfn=Monospace\ 11 endif " Disable scrollbars (real hackers don't use scrollbars for navigation!) :set guioptions-=m "remove menu bar :set guioptions-=T "remove toolbar :set guioptions-=r "remove right-hand scroll bar :set guioptions-=L "remove left-hand scroll bar " }}} " {{{ Vim Plugins Specify "Auto-Reload Your Vimrc " augroup reload_vimrc " { " autocmd! " autocmd BufWritePost $MYVIMRC source $MYVIMRC " augroup END " } " " Start interactive EasyAlign in visual mode (e.g. vipga) xmap ga (EasyAlign) " Start interactive EasyAlign for a motion/text object (e.g. gaip) nmap ga (EasyAlign) " vim-multiple-cursors let g:multi_cursor_next_key="\" "vim-cpp let g:cpp_class_scope_highlight = 1 "Highlighting of class scope is disabled by default. To enable set let g:cpp_member_variable_highlight = 1 "Highlighting of member variables is disabled by default. To enable set let g:cpp_experimental_simple_template_highlight = 1 "There are two ways to hightlight template functions. Either "let g:cpp_experimental_template_highlight = 1 "which is a faster implementation but has some corner cases where it doesn't work. let g:cpp_concepts_highlight = 1 "Highlighting of library concepts is enabled by let c_no_curly_error=1 "Braces inside square brackets shown as error " Tagbar keybinding to F8 nmap :TagbarOpenAutoClose " NERDTree keybinding to CTRL + n map :NERDTreeToggle " Add spaces after comment delimiters by default let g:NERDSpaceDelims = 1 " Use compact syntax for prettified multi-line comments let g:NERDCompactSexyComs = 1 " Align line-wise comment delimiters flush left instead of following code indentation let g:NERDDefaultAlign = 'left' " Set a language to use its alternate delimiters by default let g:NERDAltDelims_java = 1 " Add your own custom formats or override the defaults let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } } " Allow commenting and inverting empty lines (useful when commenting a region) let g:NERDCommentEmptyLines = 1 " Enable trimming of trailing whitespace when uncommenting let g:NERDTrimTrailingwhitespace = 1 " syntastic 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 "syntastic c++11/14/17 let g:syntastic_cpp_compiler = 'g++' let g:syntastic_cpp_compiler_options = '-std=c++14' let g:syntastic_cpp_checkers = ['gcc'] " let g:syntastic_cpp_compiler = 'clang++' " let g:syntastic_cpp_compiler_options = '-std=c++14 -stdlib=libc++' " let g:syntastic_cpp_checkers = ['clang_check', 'gcc'] " youcompleteme C- family let g:ycm_global_ycm_extra_conf = "~/.vim/.ycm_extra_conf.py" " Trigger configuration. Do not use if you use https://github.com/Valloric/YouCompleteMe. let g:UltiSnipsExpandTrigger="" let g:UltiSnipsJumpForwardTrigger="" let g:UltiSnipsJumpBackwardTrigger="" " If you want :UltiSnipsEdit to split your window. let g:UltiSnipsEditSplit="vertical" let g:tmux_navigator_no_mappings = 1 nnoremap {c-h} :TmuxNavigateLeft nnoremap {c-k} :TmuxNavigateDown nnoremap {c-j} :TmuxNavigateUp nnoremap {c-l} :TmuxNavigateRight nnoremap {c-p} :TmuxNavigatePrevious "vim-gitgutter " let g:gitgutter_override_sign_column_highlight = 0 " And then either update your colorscheme's SignColumn highlight group or set it in your vimrc: " highlight SignColumn ctermbg=whatever " terminal Vim "EasyMotion " map (easymotion-prefix) "CtrlP " let g:ctrlp_map = '' " let g:ctrlp_cmd = 'CtrlP' " }}}