" This file is inspired by spf13's vimrc " My custom commands {{{ imap ; imap , imap " Grep for a word and open the result in errorlist command! -nargs=+ Gr :silent execute 'grep! -nr "" | copen' " Raw version of Gr command. command! -nargs=* Grc grep -nr " Add file header to current buffer. Depends on https://github.com/harish2704/file-header command! Header :execute '0r!file-header %' " Open Terminal in split window command! Termw :execute '!konsole -e bash-session &' command! Term :execute 'sp | term' " Cd to current file's directory command! Cwd :execute 'cd %:p:h' " Cd to current file's directory, but limit to current tab command! Tcd :execute ':tcd %:p:h' " Reload current buffer command! Reload :execute "bufdo execute 'checktime . bufnr('%')'" " Delete current file and close buffer command! Rm :execute '!rm %' | bd " Copy current file path to unnamedplus register command! CopyFilename :let @+=@% " Open vscode in on current line command! Code :execute "!code ./ -g %:". ( line('.')+1 ) " }}} " My settings {{{ filetype on " required! filetype plugin indent on " Automatically detect file types. " set selection=exclusive " Do not inlcude char under cursor while doing visual selection set mouse=a set clipboard=unnamedplus set history=1000 " Store a ton of history (default is 20) set spell " Spell checking on set hidden " Allow buffer switching without saving set noswapfile set title set path=., set foldlevel=99 set foldmethod=indent au BufEnter *.js.ejs set ft=javascript.ejs au BufEnter *.sshconf set ft=sshconfig " Disable python linting autocmd VimEnter *.py SyntasticToggleMode let g:python_host_prog='/usr/bin/python2' let g:python3_host_prog='/usr/bin/python3' let javaScript_fold=0 " JavaScript let perl_fold=1 " Perl " let php_folding=1 " PHP let r_syntax_folding=1 " R let ruby_fold=1 " Ruby let sh_fold_enabled=1 " sh let vimsyn_folding='af' " Vim script " let xml_syntax_folding=1 " XML " set completeopt+=preview " Syntax based folding found be slow. In most of the cases, we will do indenting according to syntax. autocmd FileType java set foldmethod=indent autocmd FileType html set foldmethod=indent autocmd FileType javascript set foldmethod=indent autocmd FileType xml set foldmethod=indent " % key will be mapped by MatchTag plugin to match HTML tags. " It is not need on php file autocmd FileType php unmap % " Add file header automatically for javascript files autocmd BufNewFile *.js :Header autocmd BufNewFile *.py :Header " }}} " for formating {{{ " set nowrap " Wrap long lines set autoindent " Indent at the same level of the previous line set expandtab " Tabs are spaces, not tabs set tabstop=2 " An indentation every four columns set shiftwidth=0 " Use indents of 4 spaces set softtabstop=0 " Let backspace delete indent set wrap set cursorline " Highlight current line set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace set nocompatible " be iMproved syntax on " for JavaScript {{{ " if we press 'gf' under require('abc/xyz'), then also sarch for ./abs/xyz.js autocmd FileType javascript set includeexpr='./'.v:fname autocmd FileType typescript set includeexpr='./'.v:fname " }}} " for java {{{ autocmd BufRead *.java set include=^#\s*import autocmd BufRead *.java set includeexpr=substitute(v:fname,'\\.','/','g') autocmd BufRead *.java set suffixesadd=.java,.xml autocmd BufRead *.ect set suffixesadd=.ect ft=html.ect " For vue js " autocmd BufRead,BufNewFile *.vue setlocal filetype=html.vue " For Nunjucks templates autocmd BufRead *.njk set ft=jinja autocmd BufEnter *.gradle set ft=groovy " }}} " for UI {{{ set showmode " Display the current mode if has('statusline') set laststatus=2 " Broken down into easily includeable segments set statusline=%w%h%m%r " Options " set statusline+=%{fugitive#statusline()} " Git Hotness " set statusline+=\ [%{&ff}/%Y] " Filetype set statusline+=\ [%n] " Filetype " set statusline+=\ [%{winnr()}] " Filetype set statusline+=%<%f\ " Filename " set statusline+=\ [%{getcwd()}] " Current dir set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info endif set backspace=indent,eol,start " Backspace for dummies set linespace=0 " No extra spaces between rows set nu " Line numbers on set showmatch " Show matching brackets/parenthesis set hlsearch " Highlight search terms set noincsearch set winminheight=0 " Windows can be 0 line high set ignorecase " Case insensitive search set smartcase " Case sensitive when uc present set wildmenu " Show list instead of just completing set wildmode=list:longest,full " Command completion, list matches, then longest common part, then all. set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too set scrolljump=1 " Lines to scroll when cursor leaves screen set scrolloff=0 " Minimum lines to keep above and below cursor set list " }}} " for JS {{{ let g:html_indent_inctags = "html,body,head,tbody" let g:html_indent_script1 = "inc" let g:html_indent_style1 = "inc" " }}} " AutoCloseTag {{{ " Make it so AutoCloseTag works for xml and xhtml files as well au FileType xhtml,xml ru ftplugin/html/autoclosetag.vim " }}} " For NeRD Tree NERD Commenter {{{ let NERDTreeShowBookmarks=1 let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr'] let NERDTreeChDirMode=0 let NERDTreeQuitOnOpen=1 let NERDTreeMouseMode=2 let NERDTreeShowHidden=1 let NERDTreeKeepTreeInNewTab=1 let g:nerdtree_tabs_open_on_gui_startup=0 " * Commenting support for jinja tempaltes " * Typedoc compatible Sexycomment support for typescript ( '/**' instead of '/*'' ) " * jsdoc3 compatible Sexycomment support for javascript ( '/**' instead of '/*'' ) let g:NERDSpaceDelims=1 au BufEnter *.ts let b:NERDSexyComMarker='* ' au BufEnter *.js let b:NERDSexyComMarker='* ' au BufEnter *.jsx let b:NERDSexyComMarker='* ' let g:NERDCustomDelimiters = { \ 'jinja': { 'left': '{# ', 'right': ' #}', 'leftAlt': '{# ', 'rightAlt': ' #}' }, \ 'typescript': { 'left': '//', 'leftAlt': '/**', 'rightAlt': '*/' }, \ 'javascript': { 'left': '//', 'leftAlt': '/**', 'rightAlt': '*/' }, \ } " }}} " Session List {{{ set sessionoptions=blank,buffers,curdir,tabpages,winsize,resize,winpos " nmap c :JavaCorrect " nmap pt :ProjectsTree " }}} " for JavaScript syntax checking {{{ let g:syntastic_always_populate_loc_list = 1 let g:syntastic_javascript_checkers = ['eslint'] " let g:syntastic_javascript_checkers = ['jshint'] " let g:syntastic_typescript_checkers = ['tsuquyomi'] " }}} " gides {{{ " let g:indent_guides_start_level = 2 let g:indent_guides_guide_size = 1 let g:indent_guides_enable_on_vim_startup = 1 " }}} " for Gtags {{{ let g:Gtags_Auto_Map = 1 let g:Gtags_VerticalWindow = 1 let g:Gtags_Auto_Update = 1 let g:GtagsCscope_Auto_Load = 1 " }}} " set lazyredraw let g:sparkupNextMapping = '' " for taggatron. " let g:tagcommands = { " \ "php" : { " \ "tagfile" : ".php.tags", " \ "args" : "-R --langmap=PHP:+.mod" " \ } " \} "for Plug {{{ " " Use deoplete. let g:deoplete#enable_at_startup = 1 " Ctrl-p will open fuzzy file search using fzf plugin. These are the shortcuts available in fzf window let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-x': 'split', \ 'ctrl-v': 'vsplit' } let nvim_conf_root='~/.config/nvim/' " Enable jsdoc comments Highlight for javascript let g:javascript_plugin_jsdoc = 1 let g:MacroManagerDir = g:nvim_conf_root . 'macros' call plug#begin( ) Plug 'tpope/vim-fugitive' " For Git repo management. Plug 'brooth/far.vim' " Interactive Fine & replace on multiple files Plug 'Lokaltog/vim-easymotion' " Quick cursor movement to any where in the screen " Plug 'Lokaltog/vim-distinguished' " Plug 'junegunn/seoul256.vim' " Plug 'whatyouhide/vim-gotham' Plug 'rstacruz/sparkup' " HTML zen-coding helper " Plug 'L9' " Plug 'FuzzyFinder' " Plug 'git://git.wincent.com/command-t.git' " Plug 'git://github.com/vim-scripts/YankRing.vim.git' Plug 'git://github.com/maxbrunsfeld/vim-yankstack.git' " Clipboard histroy management. " " Plug 'tpope/vim-repeat' " Plug 'svermeulen/vim-easyclip' " Plug 'vim-scripts/Auto-Pairs' Plug 'vim-scripts/DoxygenToolkit.vim' " Quickly create Doxygent style comments " Plug 'Raimondi/delimitMate.git' " Plug 'bkad/CamelCaseMotion' " Plug 'vim-scripts/boxdraw' " Plug 'vim-scripts/Vim-JDE' " Plug 'maksimr/vim-jsbeautify' Plug 'scrooloose/syntastic' " Syntax checking pluin Plug 'rust-lang/rust.vim', { 'for': 'rust'} " Plug 'othree/yajs.vim' " Plug 'harish2704/tern_for_vim' , { 'for': 'javascript' } Plug 'harish2704/nerdcommenter' " Code commenting uncommenting Plug 'tomtom/tlib_vim' " Dependency of Snipmate plugin Plug 'MarcWeber/vim-addon-mw-utils' " Dependency of Snipmate plugin Plug 'garbas/vim-snipmate' " Snippet management " Plug 'amiorin/vim-project' " Plug 'nathanaelkane/vim-indent-guides' " Show indentation guides Plug 'Yggdroot/indentLine' " Plug 'flazz/vim-colorschemes' Plug 'vim-scripts/sessionman.vim' " Session manager. Manage projects " Plug 'kien/ctrlp.vim' " Plug 'leshill/vim-json' Plug 'godlygeek/tabular' " Tabularize Text Plug 'majutsushi/tagbar' " Plug 'amirh/HTML-AutoCloseTag' Plug 'tpope/vim-surround' " quickly Insert/remove/change quote/brackes any vim selection. function! DoRemote(arg) UpdateRemotePlugins endfunction Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } "Autocompletion " Plug 'roxma/nvim-completion-manager' " Plug 'mhartington/deoplete-typescript' " Plug 'vim-scripts/AutoComplPop' " Plug 'Shougo/neocomplcache' " Plug 'Valloric/YouCompleteMe' " Plug 'Shougo/eocomplcache' Plug 'Shougo/vimproc.vim' " Plug 'Quramy/tsuquyomi' Plug 'pangloss/vim-javascript' Plug 'mxw/vim-jsx' , { 'for': [ 'javascript.jsx'] } " Plug 'posva/vim-vue' Plug 'leafOfTree/vim-vue-plugin' , { 'for': ['vue']} Plug 'mhartington/nvim-typescript' , { 'for': ['javascript.ts'] } Plug 'spf13/vim-autoclose' " Autoclose brackets/quotes etc Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeFind' } "File tree " My personal utils which does " 1. Open current file in new tab by keeping cursor position " 2. Open all snippet files of current Filetype " 3. Move current window to any tab Plug 'harish2704/harish2704-vim' Plug 'kchmck/vim-coffee-script', { 'for': 'coffee' } Plug 'digitaltoad/vim-jade', { 'for': 'jade' } Plug 'AndrewRadev/vim-eco', { 'for': [ 'ect', 'eco' ] } " Plug 'mustache/vim-mode' Plug 'mustache/vim-mustache-handlebars', { 'for': 'handlebars' } Plug 'chrisbra/NrrwRgn' " Edit a portion file as different buffer " Plug 'heavenshell/vim-jsdoc', { 'for': 'javascript' } " Plug 'vim-scripts/JavaScript-Indent' " Plug 'spf13/PIV' " Plug 'joonty/vim-taggatron' " Plug 'git://github.com/vim-scripts/autoload_cscope.vim.git' " Plug 'int3/vim-taglist-plus' " Plug 'vim-scripts/EasyGrep' Plug 'briancollins/vim-jst', { 'for': 'jst' } Plug 'vim-scripts/matchit.zip' Plug 'harish2704/vim-snippets' " Plug 'vim-scripts/SyntaxRange' " Plug 'harish2704/gtags.vim' " Plug 'vim-scripts/guicolorscheme.vim' " Plug 'vim-scripts/CSApprox' " Plug 'vim-scripts/adt.vim' " Plug 'tpope/eclim' Plug 'tomasr/molokai' " Plug 'joshdick/onedark.vim' " Plug 'mhartington/oceanic-next' " Plug 'joonty/vdebug' Plug 'junegunn/fzf' Plug 'junegunn/fzf.vim' " Plug 'vim-scripts/SyntaxComplete' " Plug 'justinj/vim-react-snippets' " Plug 'othree/javascript-libraries-syntax.vim' Plug 'Glench/Vim-Jinja2-Syntax' " Plug 'kannokanno/previm' Plug 'tyru/open-browser.vim' " Plug 'harish2704/MatchTag' Plug 'Valloric/MatchTagAlways' " Plug 'leafgarland/typescript-vim' Plug 'bogado/file-line' " Plug 'vim-scripts/marvim' Plug 'dohsimpson/vim-macroeditor' Plug 'low-ghost/vim-macro-manager' Plug 'tikhomirov/vim-glsl' Plug 'HerringtonDarkholme/yats.vim' Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } Plug 'ollykel/v-vim' Plug 'sjl/gundo.vim' Plug 'evanleck/vim-svelte', { 'for': 'svelte' } " Plug 'zenbro/mirror.vim' " Plug 'kassio/neoterm' call plug#end() " Source support_function.vim to support vim-snippets. if filereadable(expand( g:nvim_conf_root ."bundle/vim-snippets/snippets/support_functions.vim")) source g:nvim_conf_root . 'bundle/vim-snippets/snippets/support_functions.vim' endif let $FZF_DEFAULT_COMMAND='ag -g ""' " Ctrl-p opens fuzzy file search nmap :Files " Ctrl-b opens current buffers list nmap :Buffers colorscheme molokai " colorscheme OceanicNext " colorscheme onedark " Neovim specific settings " Switch tabs using Alt-1..9 map ± 1gt map ² 2gt map ³ 3gt map ´ 4gt map µ 5gt map ¶ 6gt map · 7gt map ¸ 8gt " Ctrl-l -> Go to end of line imap " Replace grep with silver-searcher " silver-searcher or 'ag' command is much faster than grep command. So use ag command instead of grep command for 'vimgrep' set grepprg=ag\ --nogroup\ --nocolor " set grepprg=grep\ -n\ $*\ /dev/null " Ctrl-Enter on normal mode -> Jump to definition using Tern " autocmd BufEnter *.js nmap :TernDefSplit " Ctrl-/ on normal mode -> Grep word under cursor ( Recursive ) nmap  :Gr nmap :Gr " Open the version of current file using fugitive, where is the string in clipboard. " Eg: copy sha id of git commit to clip board. then press '\go' which open old " version of current file in vsplit using fugitive nmap go :Gvsplit +:% " Open error list. By default, Syntax checking plugin ( syntastic ) will emit errors to vim's error list nmap co :copen nmap cc :cclose nmap lo :lopen nmap lc :lclose " When opening any items in location list, Try current window, othertabs, then new tab set switchbuf=useopen,usetab,newtab " Ctrl-Shift-T -> Open new tab nmap :tabedit " Ctrl-S to save file {{{ nmap :w vmap gv imap " }}} " Alt-q Delete current buffer ( Close file ) nmap :bd " map :TagbarToggle " nmap :waexe "mksession! " . v:this_session " '\\es' or 'es' Open vimrc in a new tab execute( 'nmap es :tabedit '. g:nvim_conf_root .'init.vim ' ) " '\\en' 'en' Open current file's snippets file in a new tab nmap en :execute 'OpenSnippets' " for moving tab {{{ " Ctrl-Shift + Page-Up/Down to rearrange tab nmap :execute 'tabmove ' . (tabpagenr()-2 ) nmap :execute 'tabmove ' . ( tabpagenr()+1 ) nmap :execute 'tabmove ' . (tabpagenr()-2 ) nmap :execute 'tabmove ' . ( tabpagenr()+1 ) " Ctrl-Shift + j/k to move current window in to nearby tab {{{ nmap :execute 'Mt' . (tabpagenr() -1) nmap :execute 'Mt' . (tabpagenr() +1) nmap :execute 'Mt' . (tabpagenr() -1) nmap :execute 'Mt' . (tabpagenr() +1) " }}} " \tr Reset shiftwidth to default value 2 nmap tr :set tabstop=2 " \tt Toggle tab and spaces nmap tt :let &expandtab=!&expandtab " \tj Incraese additional two spaces width for tab nmap tj :let &tabstop=&tabstop-2\|echo 'tabstop=' &tabstop " \tj Decreases two spaces width for tab nmap tk :let &tabstop=&tabstop+2\|echo 'tabstop=' &tabstop " }}} " Session handling {{{ " List saved sessions nmap sl :SessionList " Save and close current session nmap sc :SessionClose " }}} " Ctrl-Enter in insert mode will append ';' to the line and insert a new line imap A; " Ctrl-Enter in normal mode will jump to tag definition using cscope " nmap :vert scs f g " Ctrl-? in normal mode will jump to tag references using cscope " nmap :vert scs f t " Alt + Arrows to Moving cursor to different windows {{{ nmap k nmap j nmap l nmap h " }}} " For terminal mod {{{ tmap tmap tmap k tmap j tmap l tmap h " }}} " For Terminal mode Alt + [1-8] to Switch tabs {{{ tmap 1gt tmap 2gt tmap 3gt tmap 4gt tmap 5gt tmap 6gt tmap 7gt tmap 8gt " }}} " For terminal mod {{{ tmap tmap " }}} "for easy quote/unquote {{{ " \\ + a[add] / d[delete] + q[single quote] / Q [Double quote] " \\dQ remove double quote nmap dQ ds" " \\dQ add double quote nmap aQ ysiw" " \\dQ remove single quote nmap dq ds' " \\dQ remove double quote nmap aq ysiw' " In insert mode, will quote current word imap maysiw"`aa " In insert mode, will quote current word with double quotes imap maysiw'`ai " }}} " format JSON {{{ nmap jt :%!python -m json.tool:set filetype=json " }}} " Alt + [1-8] to Switch tabs {{{ map 1gt map 2gt map 3gt map 4gt map 5gt map 6gt map 7gt map 8gt " }}} " NerdTree {{{ nmap ac ToggleAutoCloseMappings map :NERDTreeToggle:NERDTreeMirror map e :NERDTreeFind nmap nt :NERDTreeFind " }}} " For Open a terminal in current directory nmap t :!gnome-terminal " Open git-gui in current pwd nmap g :!git gui & " -> Reload current file nmap :e! " force Close buffer nmap :bd! " Select a word and press Ctrl-h to replace all its occurance, even if the word is having special chars vmap "fy:%s#f# " Copy current word to 'f' register, search for that word vmap "fy/f " set guicursor=n-c:block,i-ci-ve:ver40,r-cr-v:hor20,o:hor50,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor,sm:block-blinkwait175-blinkoff150-blinkon175 set termguicolors " hi Visual guibg=#603D3D function! CopyMatches(reg) let hits = [] %s//\=len(add(hits, submatch(0))) ? submatch(0) : ''/gne let reg = empty(a:reg) ? '+' : a:reg execute 'let @'.reg.' = join(hits, "\n") . "\n"' endfunction command! -register CopyMatches call CopyMatches() function! Unretab() range execute a:firstline . "," . a:lastline . 's/ \{1,' . &tabstop . '}/\t/g' endfunction command! -register -range=% Unretab ,call Unretab() " highlight Comment guifg=#afafb3