""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Important: " This requires that you install https://github.com/amix/vimrc ! " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => GUI related """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Set font according to system if has("mac") || has("macunix") set gfn=IBM\ Plex\ Mono:h14,Hack:h14,Source\ Code\ Pro:h15,Menlo:h15 elseif has("win16") || has("win32") set gfn=IBM\ Plex\ Mono:h14,Source\ Code\ Pro:h12,Bitstream\ Vera\ Sans\ Mono:h11 elseif has("gui_gtk2") set gfn=IBM\ Plex\ Mono\ 14,:Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11 elseif has("linux") set gfn=IBM\ Plex\ Mono\ 14,: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-=r set guioptions-=R set guioptions-=l set guioptions-=L " Colorscheme set background=dark colorscheme peaksea """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Fast editing and reloading of vimrc configs """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" map e :e! ~/.vim_runtime/my_configs.vim autocmd! bufwritepost ~/.vim_runtime/my_configs.vim source ~/.vim_runtime/my_configs.vim """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Turn persistent undo on " means that you can undo even when you close a buffer/VIM """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" try set undodir=~/.vim_runtime/temp_dirs/undodir set undofile catch endtry """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Command mode related """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Smart mappings on the command line cno $h e ~/ cno $d e ~/Desktop/ cno $j e ./ cno $c e eCurrentFileDir("e") " $q is super useful when browsing on the command line " it deletes everything until the last slash cno $q eDeleteTillSlash() " Bash like keys for the command line cnoremap cnoremap cnoremap cnoremap cnoremap " Map ½ to something useful map ½ $ cmap ½ $ imap ½ $ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Parenthesis/bracket """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" vnoremap $1 `>a)` vnoremap $2 `>a]` vnoremap $3 `>a}` vnoremap $$ `>a"` vnoremap $q `>a'` vnoremap $e `>a`` " Map auto complete of (, ", ', [ inoremap $1 ()i inoremap $2 []i inoremap $3 {}i inoremap $4 {o}O inoremap $q ''i inoremap $e ""i """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => General abbreviations """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" iab xdate =strftime("%d/%m/%y %H:%M:%S") """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Omni complete functions """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" autocmd FileType css set omnifunc=csscomplete#CompleteCSS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Ack searching and cope displaying " requires ack.vim - it's much better than vimgrep/grep """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Use the the_silver_searcher if possible (much faster than Ack) if executable('ag') let g:ackprg = 'ag --vimgrep --smart-case' endif " When you press gv you Ack after the selected text vnoremap gv :call VisualSelection('gv', '') " Open Ack and put the cursor in the right position map g :Ack " When you press r you can search and replace the selected text vnoremap r :call VisualSelection('replace', '') " Do :help cope if you are unsure what cope is. It's super useful! " " When you search with Ack, display your results in cope by doing: " cc " " To go to the next search result do: " n " " To go to the previous search results do: " p " map cc :botright cope map co ggVGy:tabnew:set syntax=qfpgg map n :cn map p :cp " Make sure that enter is never overriden in the quickfix window autocmd BufReadPost quickfix nnoremap """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Helper functions """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" func! DeleteTillSlash() let g:cmd = getcmdline() if has("win16") || has("win32") let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "") else let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "") endif if g:cmd == g:cmd_edited if has("win16") || has("win32") let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "") else let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "") endif endif return g:cmd_edited endfunc func! CurrentFileDir(cmd) return a:cmd . " " . escape(expand("%:p:h"), " ") . "/" endfunc "================================================================================= " " Following file contains the commands on how to run the currently open code. " The default mapping is set to F5 like most code editors. " Change it as you feel comfortable with, keeping in mind that it does not " clash with any other keymapping. " " NOTE: Compilers for different systems may differ. For example, in the case " of C and C++, we have assumed it to be gcc and g++ respectively, but it may " not be the same. It is suggested to check first if the compilers are installed " before running the code, or maybe even switch to a different compiler. " " NOTE: Adding support for more programming languages " " Just add another elseif block before the 'endif' statement in the same " way it is done in each case. Take care to add tabbed spaces after each " elseif block (similar to python). For example: " " elseif &filetype == '' " exec '! %' " " NOTE: The '%' sign indicates the name of the currently open file with extension. " The time command displays the time taken for execution. Remove the " time command if you dont want the system to display the time " "================================================================================= map :call CompileRun() imap :call CompileRun() vmap :call CompileRun() func! CompileRun() exec "w" if &filetype == 'c' exec "!gcc % -o %<" exec "!time ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "!time ./%<" elseif &filetype == 'java' exec "!javac %" exec "!time java %" elseif &filetype == 'sh' exec "!time bash %" elseif &filetype == 'python' exec "!time python3 %" elseif &filetype == 'html' exec "!google-chrome % &" elseif &filetype == 'go' exec "!go build %<" exec "!time go run %" elseif &filetype == 'matlab' exec "!time octave %" endif endfunc