Skip to content

Instantly share code, notes, and snippets.

@SpandanBG
Last active August 15, 2023 13:59
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 SpandanBG/78a4d2fa8aff764786679bc4c0e59337 to your computer and use it in GitHub Desktop.
Save SpandanBG/78a4d2fa8aff764786679bc4c0e59337 to your computer and use it in GitHub Desktop.
My Vim Configuration
syntax on
set number " Show line number
set ruler " Show the line and column number of the cursor
set textwidth=0 " Hard warp long lines as you type them
set modeline " Enable modeline
set linespace=0 " Set line spacing to minium
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
set splitbelow " Horizontal split below current
set splitright " Vertical split to right of current
if !&scrolloff
set scrolloff=3 " Show next 3 lines while scrolling
endif
if !&sidescrolloff
set sidescrolloff=5 " Show next 5 columns while side-scrolling
endif
set display+=lastline
set nostartofline " Do not jump to first character with page commands
set noerrorbells " No beeps
set backspace=indent,eol,start " Makes backspace key more powerful
set showcmd " Show me what I'm typing
set showmode " Show current mode
set noswapfile " Don't use swapfile
set nobackup " Don't create backup files
set nowritebackup " Don't write to backup files
set fileformats=unix,dos,mac " prefer Unix over Windows over OS 9 formats
set showmatch " Do not show matching brackets by flickering
set incsearch " Show the match while typing
set hlsearch " Highlight found searches
set ignorecase " Search case insensitive ...
set smartcase " ... but not when search pattern contains upper case characters
set autoindent
set tabstop=2 shiftwidth=2 expandtab
set expandtab " Convert tabs to whitespace
set cc=120 " Set an 120 column border for good coding style
set cmdheight=2 " Better hight to messages
set signcolumn=yes " Always show sign column
highlight SignColumn guibg=blue ctermbg=black
set updatetime=100 " Set quicker screen update time
set mouse=a " Enable mouse click
" Copy to clipboard
vnoremap <leader>y "+y
nnoremap <leader>Y "+yg_
nnoremap <leader>y "+y
nnoremap <leader>yy "+yy
" Paste from clipboard
nnoremap <leader>p "+p
nnoremap <leader>P "+P
vnoremap <leader>p "+p
vnoremap <leader>P "+P
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
"
" inoremap <silent><expr> <TAB>
" \ pumvisible() ? "\<C-n>" :
" \ <SID>check_back_space() ? "\<TAB>" :
" \ coc#refresh()
" inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
"
inoremap <silent><expr> <CR>
\ coc#pum#visible() ? coc#pum#confirm() :
\ "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
inoremap <silent><expr> <C-x><C-z>
\ coc#pum#visible() ? coc#pum#stop() : "\<C-x>\<C-z>"
" remap for complete to use tab and <cr>
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
inoremap <silent><expr> <c-space> coc#refresh()
hi CocSearch ctermfg=12 guifg=#06379A
hi CocMenuSel ctermbg=109 guibg=#13354A
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use `[c` and `]c` to navigate diagnostics
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)
" Remap keys for gotos
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>')
else
call CocAction('doHover')
endif
endfunction
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Remap for format selected region
vmap <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
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
vmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Using CocList
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
" Set keyboard shortcuts
nnoremap <C-j> :tabprevious<CR>
nnoremap <C-k> :tabnext<CR>
" Use <C-L> to clear the highlighting of :set hlsearch
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
endif
" Plugins here
call plug#begin('~/.config/nvim/plugged')
" ---------- COC ----------
" coc for tslinting, auto complete and prettier
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}
" coc extensions
let g:coc_global_extensions = ['coc-tslint-plugin', 'coc-tsserver', 'coc-emmet', 'coc-html', 'coc-json', 'coc-yank', 'coc-prettier']
" ---------- TSX ----------
" by default, if you open tsx file, neovim does not show syntax colors
" vim-tsx will do all the coloring for jsx in the .tsx file
Plug 'ianks/vim-tsx'
" typescript-fim will do all the coloring for typescript keywords
Plug 'leafgarland/typescript-vim'
" ---------- THEME ----------
" good color scheme to write good code :D
Plug 'dikiaap/minimalist'
" Auto complete backets and quotes and rainbow them
Plug 'chun-yang/auto-pairs'
Plug 'luochen1990/rainbow'
" View color or HEXs/RGBs
Plug 'ap/vim-css-color'
" ---------- AUTO COMPLETE FROM BUFFER ----------
Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'
" ---------- YOU COMPLETE ME ----------
" Plug 'Valloric/YouCompleteMe'
" ---------- SEARCH IN ALL FILES ----------
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" ---------- RENAME TABS ----------
Plug 'gcmt/taboo.vim'
set guioptions-=e
" ---------- GOLANG SUPPORT ----------
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
" disable vim-go :GoDef short cut (gd)
" this is handled by LanguageClient [LC]
let g:go_def_mapping_enabled=0
" ---------- GIT ----------
" Plug 'mhinz/vim-signify'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
" ---------- GQL ----------
Plug 'jparise/vim-graphql'
" ---------- RUST ----------
Plug 'rust-lang/rust.vim'
call plug#end()
" by default .ts file are not identified as typescript and .tsx files are not
" identified as typescript react file. so add follower
au BufNewFile,BufRead *.ts setlocal filetype=typescript
au BufNewFIle,BufRead *.tsx setlocal filetype=typescript.tsx
@SpandanBG
Copy link
Author

To install vim-plug to install plugins for Neovim: curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

@SpandanBG
Copy link
Author

SpandanBG commented Feb 3, 2022

@SpandanBG
Copy link
Author

To install and use FzF follow: https://github.com/junegunn/fzf

@SpandanBG
Copy link
Author

SpandanBG commented Feb 3, 2022

To add support for C/C++ install ccls LSP on your system and add the following config in :CocConfig

{
    "languageserver": {
        "ccls": {
            "command": "ccls",
            "filetypes": [
                "c",
                "cpp",
                "objc",
                "objcpp"
            ],
            "rootPatterns": [
                ".ccls",
                "compile_commands.json",
                ".vim/",
                ".git/",
                ".hg/"
            ],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/ccls"
                }
            }
        }
    }
}

To tell ccls compile options, generate compile_commands.json via CMake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment