Skip to content

Instantly share code, notes, and snippets.

@kshivang
Last active January 19, 2024 05:02
Show Gist options
  • Save kshivang/83d59eb20729dda7e52a9cf4cff1ebce to your computer and use it in GitHub Desktop.
Save kshivang/83d59eb20729dda7e52a9cf4cff1ebce to your computer and use it in GitHub Desktop.
My vimrc
let g:python_host_prog='/usr/bin/python'
call plug#begin('~/.nvim/plugged')
Plug 'ryanoasis/vim-devicons' " For auto iconify vim
"Plug 'hsanson/vim-android' " For android development
Plug 'scrooloose/nerdcommenter' " Comment fast and professionally
Plug 'scrooloose/nerdtree' , {'on': 'NERDTreeToggle'} " Proper file explorer inside vim
"Plug 'justinmk/vim-dirvish'
Plug 'flazz/vim-colorschemes' " All popular Colorscheme
Plug 'tpope/vim-surround' " Quick Surround with tags or Brackets
Plug 'octol/vim-cpp-enhanced-highlight' " Enhanced syntax highlight for CPP files
Plug 'Lokaltog/vim-easymotion' " Quick jumping between lines
Plug 'myusuf3/numbers.vim' " Auto Toggle between relative and normal numbering
Plug 'sjl/gundo.vim' " Graphical undo tree
Plug 'marcweber/vim-addon-mw-utils' " Vim Addons
Plug 'garbas/vim-snipmate' " Snippets for reusable code
Plug 'tpope/vim-fugitive' " Git Wrapper
Plug 'tomtom/tlib_vim' " Needed for SnipMate :(
Plug 'vim-scripts/auto-pairs-gentle' " Auto insert matching brackets
Plug 'vim-scripts/autoswap.vim' " Make vim stop with swap messages intelligently
Plug 'godlygeek/tabular' " Beautiful Alignment when needed
Plug 'plasticboy/vim-markdown' " Better Markdown support for vim (NEEDS TABULAR)
Plug 'jceb/vim-orgmode' " Add OrgMode support like Emacs
Plug 'vim-scripts/cmdalias.vim' " Set up alias for accidental commands
Plug 'vim-scripts/Python-Syntax-Folding' " Proper syntax folding for python
Plug 'nvie/vim-flake8' " Point out PEP8 inconsistencies
Plug 'vim-airline/vim-airline' " Who doesn't know about vim airline plugin
Plug 'kien/ctrlp.vim' " Fast fuzzy file searching
Plug 'terryma/vim-multiple-cursors' " Multiple Cursors like Sublime Text
Plug 'kchmck/vim-coffee-script' " Highlighting and syntax for coffeescript
Plug 'fatih/vim-go' " Go completion and features
"Plug 'KabbAmine/zeavim.vim' " Direct documentation access
Plug 'Superbil/llvm.vim', { 'for': 'llvm' } " LLVM highlighting
Plug 'rhysd/vim-clang-format'
Plug 'gko/vim-coloresque'
Plug 'scrooloose/syntastic'
Plug 'artur-shaik/vim-javacomplete2'
Plug 'majutsushi/tagbar'
Plug 'thinca/vim-quickrun'
Plug 'vim-scripts/camelcasemotion'
Plug 'Shougo/neocomplcache.vim'
Plug 'ervandew/supertab'
"Plug 'daeyun/vim-matlab'
"Plug 'rizzatti/dash.vim'
call plug#end() " plug ends here
set shiftwidth=2 " Indentation
syntax on
filetype plugin indent on
filetype plugin on
set background=dark
set t_Co=256
colorscheme molokai_dark
" start commands with ; not :
nnoremap ,; ;
" Turn word to uppercase in insert mode
inoremap <c-u> <Esc>viwUea
" Toggle NERDTree without python compile files
inoremap <F2> <Esc>:NERDTreeToggle<CR>a
" Toggle NERDTree without python compile files
nnoremap <F2> :NERDTreeToggle<CR>
"nnoremap <F3> <Plug>(dirvish_up)<CR>
" Turn on/off wrapping
nnoremap <F4> :set wrap!<CR>
" Open current emulator
map <c-c> :sh<cr>
nmap <F5> <ESC>:Gradle assembleDebug<CR>
nmap <leader>jsi <Plug>(JavaComplete-Imports-AddSmart)
nmap <leader>ji <Plug>(JavaComplete-Imports-Add)
nmap <leader>jim <Plug>(JavaComplete-Imports-AddMissing)
nmap <leader>jir <Plug>(JavaComplete-Imports-RemoveUnused)
command Carg execute "normal mm:w<CR>:!gcc<Space>%<Space>-o<Space>%<<Space>&&<Space>./%<<Space><CR>"
nnoremap <F6> :only<CR>
nnoremap <F7> :TagbarToggle<CR>
nnoremap <F8> :buffers<CR>:buffer<Space>
" Turn on/off current line highlight
nnoremap <F9> :set cul!<CR>
" Indent everything in insert mode
inoremap <F10> <Esc>mmgg=G`ma
" Indent everything in normal mode
nnoremap <F10> <Esc>mmgg=G`m
" comment current line with //
nmap // <leader>ci
" comment current selection with //
vmap // <leader>ci
" w!! force write with sudo even if forgot sudo vim
cmap w!! w !sudo tee > /dev/null %
" Easy Motion shortcut. Try it!
nmap ,, <leader><leader>s
cnoremap q! wq
inoremap jk <Esc>
cnoremap jk <Esc>
nnoremap <CR> o<Esc>
nnoremap <silent> <tab> mq:bnext<CR>`q
nnoremap <silent> <s-tab> mq:bprevious<CR>`q
" Switch buffers with Tab and Shift-Tab
inoremap <// </<C-X><C-O><C-[>m'==`'
nnoremap Q !!sh<CR>
" Replace current line with output of shell
"command! -nargs=1 Web vnew|call termopen('lynx -scrollbar '.shellescape(<q-args>))|call <SID>init_lynx()
" --------------------------------CONFIGS----------------------------- "
let g:syntastic_html_tidy_ignore_errors=["<ion-", "discarding unexpected </ion-", " proprietary attribute \"ng-"]
let g:android_sdk_path="/Users/kshivang/Library/Android/sdk/"
let g:gradle_path="/usr/local/bin/gradle"
"let NERDTreeIgnore=['\.pyc$', '__pycache__'] " Ignoring .pyc files and __pycache__ folder
let g:go_fmt_command = "goimports" " Rewrite go file with correct imports
set encoding=utf-8
set laststatus=2
set wildignore+=*/bin/*,main,*/__pycache__/*,*.pyc,*.swp
set backspace=indent,eol,start " Make backspace work with end of line and indents
set foldmethod=syntax " Auto Add folds - Trigger with za
set foldlevel=9999 " Keep folds open by default
set scrolloff=10 " Scroll Offset below and above the cursor
set expandtab " Replace tab with spaces
set tabstop=4 " Tab = 4 Space
set softtabstop=4 " Act like there are tabs not spaces
set hidden " Hide abandoned buffers without message
set wildmenu " Tab command completion in vim
set ignorecase " Ignore case while searching
set smartcase " Case sensitive if Capital included in search
set incsearch " Incremental Searching - Search as you type
set autoindent " Self explained
set smartindent
set relativenumber " relative numbering (Current line in line 0)
set number " Line numbers - Hybrid mode when used with rnu
set nowrap " I don't like wrapping statements
set foldenable
set laststatus=2 " Show status line for even 1 file
set tags=~/.mytags " Path to generated tags
set mouse=nv " Allow mouse usage in normal and visual modes
set nohlsearch " Do not highlight all search suggestions.
set omnifunc=syntaxcomplete#Complete
let g:airline_powerline_fonts = 1 " Powerline fonts
let g:airline#extensions#tabline#enabled = 1 " Show buffers above
let g:matlab_auto_mappings = 1 "automatic mappings enabled
let g:matlab_server_launcher = 'tmux' "launch the server in a tmux split
let g:matlab_server_split = 'vertical' "launch the server in a horizontal split
call airline#parts#define_function('vim-gradle-status', 'gradle#statusLine')
let g:airline_section_x= airline#section#create_right(['tagbar', 'filetype', 'vim-gradle-status'])
let g:gradle_glyph_error=''
let g:gradle_glyph_warning=''
let g:gradle_glyph_gradle=''
let g:gradle_glyph_android=''
let g:gradle_glyph_building=''
" to run gradle task in background in nvim
let g:gradle_quickfix_show=1
let g:android_sdk_tags="~/.gradle_tags"
let g:gradle_daemon=1
" Lint Configs
" Lint Configs
let g:clang_format#style_options = {
\ "AccessModifierOffset" : -4,
\ "IndentWidth" : 4,
\ "TabWidth" : 4,
\ "AllowShortIfStatementsOnASingleLine" : "false",
\ "AllowShortBlocksOnASingleLine" : "false",
\ "AllowShortLoopsOnASingleLine" : "false",
\ "AlwaysBreakTemplateDeclarations" : "true",
\ "PointerAlignment" : "Right",
\ "DerivePointerAlignment" : "false",
\ "ColumnLimit" : 90,
\ "Standard" : "C++11" }
"---------------------------SMART CLIPBOARD----------------------------"
vnoremap ,y "+yy
nnoremap ,y "+yy
vnoremap ,d "+dd
nnoremap ,d "+dd
vnoremap ,p "+p
nnoremap ,p "+p
vnoremap ,P "+P
nnoremap ,P "+P
nnoremap <space> za
"----------------------------ABBREVIATIONS-----------------------------"
iabbrev @@g shivang.iitk@gmail.com
iabbrev @@i kshivang@iitk.ac.in
"----------------------------GVIM SPECIFIC-----------------------------"
set directory=.,$TEMP " Gets rid of a windows specific error
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
set guifont=DroidSansMonoForPowerline\ Nerd\ Font:h13
"--------------------------------HOOKS---------------------------------"
augroup filetype_compile
autocmd!
autocmd FileType tex nmap <F3> mm:w<CR>:!pdflatex<Space>%<CR><CR><Return>`m
autocmd BufWritePre *.c,*.cpp,*.objc,*.h,*.java ClangFormat
"autocmd FileType c,cpp nmap <F3> mm:w<CR>:!gcc<Space>%<Space>-o<Space>%<<Space>&&<Space>./%<<Space><CR>
augroup END
nmap <F3> :call CompileRunGcc()<CR>
func! CompileRunGcc()
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 -cp %:p:h %:t:r"
elseif &filetype == 'sh'
exec "!time bash %"
elseif &filetype == 'python'
exec "!time python2.7 %"
elseif &filetype == 'html'
exec "!open -a Firefox %"
elseif &filetype == 'go'
exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'markdown'
exec "!~/.nvim/markdown.pl % | browser"
endif
endfunc
autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_firefox()
function! Refresh_firefox()
if &modified
write
silent !echo 'vimYo = content.window.pageYOffset;
\ vimXo = content.window.pageXOffset;
\ BrowserReload();
\ content.window.scrollTo(vimXo,vimYo);
\ repl.quit();' |
\ nc -w 1 localhost 4242 2>&1 > /dev/null
endif
endfunction
command! -nargs=1 Repl silent !echo
\ "repl.home();
\ content.location.href = '<args>';
\ repl.enter(content);
\ repl.quit();" |
\ nc localhost 4242
nmap <leader>mh :Repl http://
" mnemonic is MozRepl Http
nmap <silent> <leader>ml :Repl file:///%:p<CR>
" mnemonic is MozRepl Local
nmap <silent> <leader>md :Repl http://localhost/
" mnemonic is MozRepl Development
autocmd FileType *.jpg,*.gif,*.jpeg,*.png :<Space>!open<Space>%
"augroup my_dirvish_events
"autocmd!
"Map t to open in new tab".
"autocmd FileType dirvish
"\ nnoremap <buffer> t :call dirvish#open('tabedit', 0)<CR>
"\ |xnoremap <buffer> t :call dirvish#open('tabedit', 0)<CR>
"Enable :Gstatus and friends.
"autocmd FileType dirvish call fugitive#detect(@%)
"Map CTRL-R to reload the Dirvish buffer.
"autocmd FileType dirvish nnoremap <buffer> <C-R> :<C-U>Dirvish %<CR>
"Map `gh` to hide dot-prefixed files.
"To toggle" this, just press `R` to reload.
"autocmd FileType dirvish nnoremap <buffer>
"\ gh :keeppatterns g@\v/\.[^\/]+/?$@d<cr>
"augroup END
"---------------------------OPERATOR-PENDING---------------------------"
" Operate inside next block
onoremap in( :<c-u>normal! f(vi(<CR>
onoremap in{ :<c-u>normal! f{vi{<CR>
onoremap in" :<c-u>normal! f"vi"<CR>
onoremap in' :<c-u>normal! f'vi'<CR>
onoremap in` :<c-u>normal! f`vi`<CR>
" Operate inside previous block
onoremap ip( :<c-u>normal! F)vi(<CR>
onoremap ip{ :<c-u>normal! F}vi{<CR>
onoremap ip" :<c-u>normal! F"vi"<CR>
onoremap ip' :<c-u>normal! F'vi'<CR>
onoremap ip` :<c-u>normal! F`vi`<CR>
" Operate around next block
onoremap an( :<c-u>normal! f(va(<CR>
onoremap an{ :<c-u>normal! f{va{<CR>
onoremap an" :<c-u>normal! f"va"<CR>
onoremap an' :<c-u>normal! f'va'<CR>
onoremap an` :<c-u>normal! f`va`<CR>
" Operate around previous block
onoremap ap( :<c-u>normal! F)va(<CR>
onoremap ap{ :<c-u>normal! F}va{<CR>
onoremap ap" :<c-u>normal! F"va"<CR>
onoremap ap' :<c-u>normal! F'va'<CR>
onoremap ap` :<c-u>normal! F`va`<CR>
" Set scripts to be executable from the shell
au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile>
"Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 1
" Use smartcase.
let g:neocomplcache_enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
" Enable heavy features.
" Use camel case completion.
let g:neocomplcache_enable_camel_case_completion = 1
" Use underbar completion.
let g:neocomplcache_enable_underbar_completion = 1
" Define dictionary.
let g:neocomplcache_dictionary_filetype_lists = {
\ 'default' : '',
\ 'vimshell' : $HOME.'/.vimshell_hist',
\ 'scheme' : $HOME.'/.gosh_completions'
\ }
" Define keyword.
if !exists('g:neocomplcache_keyword_patterns')
let g:neocomplcache_keyword_patterns = {}
endif
let g:neocomplcache_keyword_patterns['default'] = '\h\w*'
" Plugin key-mappings.
inoremap <expr><C-g> neocomplcache#undo_completion()
inoremap <expr><C-l> neocomplcache#complete_common_string()
" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return neocomplcache#smart_close_popup() . "\<CR>"
" For no inserting <CR> key.
"return pumvisible() ? neocomplcache#close_popup() : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><C-y> neocomplcache#close_popup()
inoremap <expr><C-e> neocomplcache#cancel_popup()
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? neocomplcache#close_popup() : "\<Space>"
" For cursor moving in insert mode(Not recommended)
"inoremap <expr><Left> neocomplcache#close_popup() . "\<Left>"
"inoremap <expr><Right> neocomplcache#close_popup() . "\<Right>"
"inoremap <expr><Up> neocomplcache#close_popup() . "\<Up>"
"inoremap <expr><Down> neocomplcache#close_popup() . "\<Down>"
" Or set this.
"let g:neocomplcache_enable_cursor_hold_i = 1
" Or set this.
"let g:neocomplcache_enable_insert_char_pre = 1
" AutoComplPop like behavior.
"let g:neocomplcache_enable_auto_select = 1
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplcache_enable_auto_select = 1
"let g:neocomplcache_disable_auto_complete = 1
"inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
" Enable omni completion.
augroup omni_func
autocmd!
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType java setlocal omnifunc=javacomplete#Complete
augroup END
autocmd BufNewFile *.java
\ exe "normal Oclass " . expand('%:t:r') . "{\n\tpublic static void main(String[] argc) {\n\n\treturn;\n\t}\n}\<Esc>1G"
autocmd BufNewFile *.c
\ exe "normal O#include<stdio.h>\n\nint main(int argv, char **argc) {\n\n\treturn 0;\n}\<Esc>5G"
" Enable heavy omni completion.
if !exists('g:neocomplcache_force_omni_patterns')
let g:neocomplcache_force_omni_patterns = {}
endif
let g:neocomplcache_force_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
let g:neocomplcache_force_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplcache_force_omni_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
"| endif | endif
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"place ''~/.nvimrc''
"vim: nowrap:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment