Skip to content

Instantly share code, notes, and snippets.

@saiqulhaq
Last active February 7, 2023 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saiqulhaq/e1caf79c21c0912c84d997a2725fbcff to your computer and use it in GitHub Desktop.
Save saiqulhaq/e1caf79c21c0912c84d997a2725fbcff to your computer and use it in GitHub Desktop.
My Vim config
"set termguicolors
call plug#begin('~/.local/share/nvim/plugged')
Plug 'wakatime/vim-wakatime'
Plug 'hashivim/vim-terraform'
" Colorscheme
Plug('flazz/vim-colorschemes')
Plug('arcticicestudio/nord-vim')
Plug('mhartington/oceanic-next')
"Plug('mhinz/vim-janah')
" End colorscheme
" C-g o
" C-g O
Plug('hecal3/vim-leader-guide')
let g:leaderGuide_max_size = 15
" nerdtree
Plug('scrooloose/nerdtree')
Plug('jistr/vim-nerdtree-tabs')
Plug('Xuyuanp/nerdtree-git-plugin')
Plug('ctrlpvim/ctrlp.vim')
" leader be
Plug('jlanzarotta/bufexplorer')
" Open recent files
" C-o
Plug('yegappan/mru')
" Save session => :SSave, :SDelete
Plug('mhinz/vim-startify')
Plug('ntpeters/vim-better-whitespace')
" inserting quotes
Plug('Raimondi/delimitMate')
" MixedCase (crm), camelCase (crc), snake_case (crs), UPPER_CASE (cru),
" dash-case (cr-), dot.case (cr.), space case (cr<space>), and Title Case (crt)
Plug('tpope/vim-abolish')
Plug('tpope/vim-repeat')
" relative number
Plug 'ericbn/vim-relativize'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tpope/vim-dispatch'
" call with F8
Plug('majutsushi/tagbar')
" comment :gc
" uncomment :gcc
Plug('tpope/vim-commentary')
Plug('tpope/vim-fugitive')
Plug('airblade/vim-gitgutter')
Plug('mattn/webapi-vim')
Plug('mattn/vim-gist')
Plug('vim-airline/vim-airline')
Plug('vim-airline/vim-airline-themes')
" :FixWhitespace
Plug('bronson/vim-trailing-whitespace')
" :nnoremap <leader>rap :RAddParameter<cr>
" :nnoremap <leader>rcpc :RConvertPostConditional<cr>
" :nnoremap <leader>rel :RExtractLet<cr>
" :vnoremap <leader>rec :RExtractConstant<cr>
" :vnoremap <leader>relv :RExtractLocalVariable<cr>
" :nnoremap <leader>rit :RInlineTemp<cr>
" :vnoremap <leader>rrlv :RRenameLocalVariable<cr>
" :vnoremap <leader>rriv :RRenameInstanceVariable<cr>
" :vnoremap <leader>rem :RExtractMethod<cr>
Plug('ecomba/vim-ruby-refactoring')
Plug('rainerborene/vim-reek')
Plug('noprompt/vim-yardoc')
" :TestNearest :TestFile :TestSuite :TestLast :TestVisit
" :RSpec --tag ~slow
Plug('janko-m/vim-test')
" Dependency to run ruby rspec
Plug 'benmills/vimux'
" :Dash setTimeout javascript
Plug('rizzatti/dash.vim')
" html
Plug('mattn/emmet-vim')
Plug('othree/html5.vim')
Plug('mustache/vim-mustache-handlebars')
" <C-k> :MBEbb
" <C-j> :MBEbf
" <leader>d :MBEbd
Plug('fholgado/minibufexpl.vim')
Plug('Yggdroot/indentLine')
let g:indentLine_char = '.'
Plug('tpope/vim-markdown')
" :InstantMarkdownPreview
Plug('suan/vim-instant-markdown')
" :Delete: Delete a buffer and the file on disk simultaneously.
" :Unlink: Like :Delete, but keeps the now empty buffer.
" :Move: Rename a buffer and the file on disk simultaneously.
" :Rename: Like :Move, but relative to the current file's containing directory.
" :Chmod: Change the permissions of the current file.
" :Mkdir: Create a directory, defaulting to the parent of the current file.
" :Find: Run find and load the results into the quickfix list.
" :Locate: Run locate and load the results into the quickfix list.
" :Wall: Write every open window. Handy for kicking off tools like guard.
" :SudoWrite: Write a privileged file with sudo.
" :SudoEdit: Edit a privileged file with sudo.
" File type detection for sudo -e is based on original file name.
" New files created with a shebang line are automatically made executable.
" New init scripts are automatically prepopulated with /etc/init.d/skeleton.
Plug('tpope/vim-eunuch')
Plug('elzr/vim-json')
Plug('editorconfig/editorconfig-vim')
" :Ack [options] {pattern} [{directories}]
Plug('mileszs/ack.vim')
" place, toggle and display marks.
Plug('kshenoy/vim-signature')
" icons
Plug('ryanoasis/vim-devicons')
" visualize undo
" :UndotreeToggle
Plug 'mbbill/undotree'
call plug#end()
cnoreabbrev W w
cnoreabbrev Q q
noremap <F12> <Esc>:syntax sync fromstart<CR>
inoremap <F12> <C-o>:syntax sync fromstart<CR>
nmap <C-g>o <Plug>leaderguide-global
nmap <C-g>O <Plug>leaderguide-buffer
nmap cp :let @+=@%<CR>
filetype plugin indent on
" Use true colors
" if (empty($TMUX))
" let $NVIM_TUI_ENABLE_TRUE_COLOR=1
" if (has('termguicolors'))
" set termguicolors
" endif
" endif
" set background=light
" colorscheme codeschool
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set termguicolors
autocmd ColorScheme nord highlight Normal ctermbg=235
colorscheme nord
set completeopt=longest,menuone
" Enable italic
let g:nord_italic_comments=1
let &t_ZH="\e[3m"
let &t_ZR="\e[23m"
" Use Tab instead of % to switch
nmap <Tab> %
vmap <Tab> %
" oceanic-next config
if (has("termguicolors"))
set termguicolors
endif
syntax enable
set t_Co=256
let g:oceanic_next_terminal_bold = 1
let g:oceanic_next_terminal_italic = 1
set ruler
set relativenumber
set number relativenumber
set numberwidth=3
let mapleader = ","
set history=1000
set foldmethod=indent
set nofoldenable "dont fold by default
" `za` - toggles
" `zc` - closes
" `zo` - opens
" `zR` - open all
" `zM` - close all
"" dont enter Ex mode
nnoremap Q <nop>
set hidden
set noswapfile
set nobackup
set nowb
""" Whitespace
set nowrap " don't wrap lines
set linebreak " Wrap lines at convenient points
set backspace=indent,eol,start " backspace through everything in insert mode
set list listchars=tab:\ \ ,trail:· "Display whitespace
" file will be ignored by NerdTREE
let g:NERDTreeChDirMode=2
let g:NERDTreeIgnore=['\.rbc$', '\~$', '\.pyc$', '\.db$', '\.sqlite$', '__pycache__','.class$', '\~$', '^cscope']
let g:NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
let g:NERDTreeShowBookmarks=1
let g:nerdtree_tabs_focus_on_files=1
let g:NERDTreeMapOpenInTabSilent = '<RightMouse>'
let g:NERDTreeWinSize = 50
let g:NERDTreeQuitOnOpen = 0
let g:NERDTreeAutoDeleteBuffer = 1
let g:NERDTreeMinimalUI = 0
let g:NERDTreeDirArrows = 1
map <C-n> <plug>NERDTreeTabsToggle<CR>
nnoremap <silent> <Leader>n :NERDTreeFind<CR>
autocmd FileType nerdtree cnoreabbrev <buffer>bd<nop>
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.db,*.sqlite
set pastetoggle=<F2>
" Recent files
let MRU_Max_Menu_Entries = 20
let MRU_Use_Current_Window = 1
""" Searching
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
if exists('+colorcolumn')
set colorcolumn=81
endif
" vim-airline
let g:airline#extensions#tagbar#enabled = 1
let g:airline_skip_empty_sections = 1
" let g:airline_theme='papercolor'
let g:airline_theme='oceanicnext'
"" Abbreviations
cnoreabbrev W! w!
cnoreabbrev Q! q!
cnoreabbrev Qall! qall!
cnoreabbrev Wq wq
cnoreabbrev Wqa wqa
cnoreabbrev Wa wa
cnoreabbrev wQ wq
cnoreabbrev wQa wqa
cnoreabbrev WQ wq
cnoreabbrev WQa wqa
cnoreabbrev W w
cnoreabbrev Q q
cnoreabbrev Qall qall
" quick command
nmap ; :
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
nmap <C-k> :MBEbb<cr>
nmap <C-j> :MBEbf<cr>
map <leader>d :MBEbd<CR>
" imap zz <ESC>:w<CR>i
map zz <ESC>:w<CR>
map <ESC><ESC><ESC> :noh<CR>
" Help
autocmd FileType help :nnoremap <buffer> <silent> q :q<cr>
" Insert new line
map <Enter> o<ESC>
" Mini Buffer Explorer
let g:miniBufExplBuffersNeeded = 1
let g:miniBufExplCycleArround = 1
" Go to home and end using capitalized directions
noremap H ^
noremap L $
nmap <F8> :TagbarToggle<CR>
let g:tagbar_autofocus = 1
set tags=tags
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
noremap <C-p> :CtrlPMixed<cr>
noremap <C-o> :MRU<cr>
noremap <C-u> :Tags
" The Silver Searcher
if executable('ag')
let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -g ""'
set grepprg=ag\ --nogroup\ --nocolor
endif
"" Copy/Paste/Cut
set clipboard=unnamed
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
if has('macunix')
" pbcopy for OSX copy/paste
vmap <C-x> :!pbcopy<CR>
vmap <C-c> :w !pbcopy<CR><CR>
endif
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
" Ruby refactory
nnoremap <leader>rap :RAddParameter<cr>
nnoremap <leader>rcpc :RConvertPostConditional<cr>
nnoremap <leader>rel :RExtractLet<cr>
vnoremap <leader>rec :RExtractConstant<cr>
vnoremap <leader>relv :RExtractLocalVariable<cr>
nnoremap <leader>rit :RInlineTemp<cr>
vnoremap <leader>rrlv :RRenameLocalVariable<cr>
vnoremap <leader>rriv :RRenameInstanceVariable<cr>
vnoremap <leader>rem :RExtractMethod<cr>
" Git gutter
let g:gitgutter_map_keys = 0
nmap <silent> ]c <Plug>GitGutterNextHunk
nmap <silent> [c <Plug>GitGutterPrevHunk
hi Normal ctermbg=NONE guibg=NONE
" Vim Test
let test#strategy = "dispatch"
let test#ruby#rspec#options = { 'nearest': '--backtrace --color', 'file': ' --color --format documentation' }
nmap <silent> <leader>t :TestNearest<CR>
nmap <silent> <leader>T :TestFile<CR>
nmap <silent> <leader>a :TestSuite<CR>
nmap <silent> <leader>l :TestLast<CR>
nmap <silent> <leader>g :TestVisit<CR>
" Vim Instant Markdown
let g:instant_markdown_slow = 1
let g:instant_markdown_autostart = 0
" startify config
"
" prevent blank buffer to be loaded
set sessionoptions-=blank
let g:startify_enable_special = 0
let g:startify_files_number = 8
let g:startify_relative_path = 1
let g:startify_change_to_dir = 0
let g:startify_update_oldfiles = 1
let g:startify_session_autoload = 1
let g:startify_session_persistence = 1
" vim-devicons config
set encoding=utf8
" set guifont=Fira\ Code:h12
" set guifont=DroidSansMono\ Nerd\ Font:h11
set guifont=JetBrains\ Mono\ NL:h11
let g:airline_powerline_fonts = 1
let g:webdevicons_enable_nerdtree = 0
let g:WebDevIconsOS = 'Darwin'
if exists("g:loaded_webdevicons")
call webdevicons#refresh()
endif
" Reek
let g:reek_always_show = 1
let g:reek_line_limit = 1000
let g:reek_on_loading = 0 "1
" :RunReek
set mmp=5000
" COC setting
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
" END COC setting
" Generate mindmap
nmap <silent> <leader>map :CocCommand markmap.create<CR>
if has("persistent_undo")
let target_path = expand('~/undodir')
" create the directory and any parent directories
" if the location does not exist.
if !isdirectory(target_path)
call mkdir(target_path, "p", 0700)
endif
let &undodir=target_path
set undofile
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment