" General settings {{{ " Filetype support filetype plugin indent on syntax on runtime macros/matchit.vim colorscheme gruvbox " Use the gruvbox colorscheme: https://github.com/morhetz/gruvbox set background=dark " Use a dark background set scrolloff=5 " Keep at least 3 lines above/below when scrolling set lazyredraw " Don't update the display while executing macros set tabstop=4 " Tab indentation levels every four columns set shiftwidth=4 " Indent/outdent by four columns (when pressing >>) set expandtab " Convert all tabs that are typed into spaces (it has a better compatibility with other computers) set shiftround " Always indent/outdent to nearest tabstop set smarttab " Use shiftwidths at left margin, tabstops everywhere else set laststatus=2 " Always show the statusline set nonumber " Don't display line numbers set backspace=indent,eol,start " Fix backspace set hlsearch " Highlight search set incsearch ignorecase " Increase search set noswapfile " Don't use swap file set smartcase " Override the 'ignorecase' option if the search pattern contains upper case characters. set showcmd " Show commands at bottom set hidden " Switch buffers without the need of saving them set clipboard=unnamedplus " Copy to clipboard when yanking text with yy/dd etc. set path=.,** " Set path to the current and children directories set wildmenu wildmode=full " Display all matching files when we tab complete set undofile undodir=~/.vim/tmp/undo/ " Set undofiles (undo files even if you exited the file) set splitbelow splitright " Split belor and/or right when opening new buffers set list listchars=eol:$,trail:∙ listchars+=tab:│\ fillchars+=vert:│,fold:\ set foldenable foldmethod=marker " Set up statusline set statusline=\ %f\ %y\ %m%=%l,%c\ \ \ \ \ \ \ \ \ \ \ \ %P\ | " }}} " Mappings {{{ " Ergonomics inoremap ( inoremap ) inoremap [ inoremap ] inoremap * " http://items.sjbach.com/319/configuring-vim-right noremap ; : noremap : ; nnoremap ' ` " Make 0 go to the first character rather than the beginning " " of the line. When we're programming, we're almost always " " interested in working with text rather than empty space. If " " you want the traditional beginning of line, use ^ nnoremap 0 ^ nnoremap ^ 0 " Supercharge dot formula nnoremap c* *``cgn " Delete trailing spaces nnoremap :let _s=@/ :%s/\s\+$//e :let @/=_s :nohl :unlet _s " Juggling with buffers nnoremap ,b :buffer * nnoremap ,B :sbuffer * nnoremap :bprevious nnoremap :bnext nnoremap :buffer# " Juggling with matches nnoremap ,i :ilist / nnoremap [I [I:ijump nnoremap ]I ]I:ijump " Move to other buffers nnoremap j nnoremap k nnoremap l nnoremap h " Visual select inside a whole function xnoremap if /^\s*}V% " File navigation nnoremap ,f :find * nnoremap ,s :sfind * nnoremap ,v :vert sfind * nnoremap ,F :find =fnameescape(expand('%:p:h')).'/**/*' nnoremap ,S :sfind =fnameescape(expand('%:p:h')).'/**/*' nnoremap ,V :vert sfind =fnameescape(expand('%:p:h')).'/**/*' nnoremap gb :ls:buffer " better completion menu inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" " Smooth listing cnoremap CCR() function! s:CCR() command! -bar Z silent set more|delcommand Z if getcmdtype() == ":" let cmdline = getcmdline() if cmdline =~ '\v\C^(dli|il)' | return "\:" . cmdline[0] . "jump " . split(cmdline, " ")[1] . "\\\" elseif cmdline =~ '\v\C^(cli|lli)' | return "\:silent " . repeat(cmdline[0], 2) . "\" elseif cmdline =~ '\C^changes' | set nomore | return "\:Z|norm! g;\" elseif cmdline =~ '\C^ju' | set nomore | return "\:Z|norm! \\" elseif cmdline =~ '\v\C(#|nu|num|numb|numbe|number)$' | return "\:" elseif cmdline =~ '\C^ol' | set nomore | return "\:Z|e #<" elseif cmdline =~ '\v\C^(ls|files|buffers)' | return "\:b" elseif cmdline =~ '\C^marks' | return "\:norm! `" elseif cmdline =~ '\C^undol' | return "\:u " else | return "\" | endif else | return "\" | endif endfunction " Commands for adjusting indentation rules manually command! -nargs=1 Spaces execute "setlocal tabstop=" . . " shiftwidth=" . . " softtabstop=" . . " expandtab" | setlocal ts? sw? sts? et? command! -nargs=1 Tabs execute "setlocal tabstop=" . . " shiftwidth=" . . " softtabstop=" . . " noexpandtab" | setlocal ts? sw? sts? et? " Share text on ix.io (visual select something, type :IX, and it will upload to ix.io) command! -range=% IX ,w !curl -F 'f:1=<-' ix.io | tr -d '\n' | xclip -i -selection clipboard " Clear all the registers available: https://stackoverflow.com/a/41003241 command! ClearReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor " Fix the go to next line if wrap is enabled nnoremap j v:count ? 'j' : 'gj' nnoremap k v:count ? 'k' : 'gk' " }}} " AutoCMD's {{{ if has('autocmd') augroup Set_FileTypes autocmd! autocmd BufRead,BufNewFile,BufWritePost *.pl set filetype=prolog autocmd FileType gitcommit setlocal spell autocmd FileType qf wincmd J | setlocal wrap autocmd FileType mail \ if expand('%:p') =~ '^/tmp/mutt/\(neo\)\?mutt-' | \ set ft=pandoc | \ else | \ setlocal spell | \ endif augroup END " Return to last edit position when opening files (You want this!) augroup Remember_cursor_position autocmd! autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif augroup END augroup VimSettings autocmd! " automatic location/quickfix window autocmd QuickFixCmdPost [^l]* cwindow autocmd QuickFixCmdPost l* lwindow autocmd VimEnter * cwindow " various adjustments of the default colorscheme highlight ModeMsg ctermbg=Red ctermfg=White cterm=bold highlight Search ctermfg=White ctermbg=Red cterm=bold highlight IncSearch ctermfg=White ctermbg=Red cterm=bold highlight StatusLine ctermfg=35 ctermbg=8 highlight StatusLineNC ctermfg=8 ctermbg=35 " Tabline color settings highlight TabLine ctermfg=White ctermbg=Black cterm=NONE highlight TabLineFill ctermfg=White ctermbg=Black cterm=NONE highlight TabLineSel ctermfg=White ctermbg=DarkBlue cterm=NONE " Spell color settings highlight SpellBad term=underline cterm=underline ctermbg=Red highlight SpellCap term=underline cterm=underline highlight SpellRare term=underline cterm=underline highlight SpellLocal term=underline cterm=underline " Git-specific settings autocmd FileType gitcommit nnoremap { ?^@@|nnoremap } /^@@|setlocal iskeyword+=- augroup END " Show spaces as red if there's nothing after it (stole Greg Hurrel) augroup TrailWhiteSpaces highlight ColorColumn ctermbg=1 autocmd BufWinEnter match Error /\s\+$/ autocmd InsertEnter match Error /\s\+\%#\@ match Error /\s\+$/ autocmd BufWinLeave call clearmatches() augroup END endif " }}} " Grep {{{ command! -nargs=+ -complete=file_in_path -bar Grep silent! grep! | redraw! command! -nargs=+ -complete=file_in_path -bar LGrep silent! lgrep! | redraw! nnoremap ,G :Grep xnoremap ,G :let cmd = "Grep " . visual#GetSelection() \ call histadd("cmd", cmd) \ execute cmd if executable("ag") set grepprg=ag\ --vimgrep set grepformat^=%f:%l:%c:%m endif " }}} " Netrw {{{ let g:netrw_sort_by = 'time' let g:netrw_sort_direction = 'reverse' let g:netrw_banner = 0 let g:netrw_liststyle = 3 let g:netrw_browse_split = 3 let g:netrw_fastbrowse = 1 let g:netrw_sort_by = 'name' let g:netrw_sort_direction = 'normal' let g:netrw_winsize = -28 function! ToggleExplore() if &ft ==# "netrw" Rexplore else Explore endif endfunction map :call ToggleExplore() " }}}