Skip to content

Instantly share code, notes, and snippets.

Last active October 25, 2020 13:06
Show Gist options
  • Save priyanshu219/7aed182c506e44a190486b46bd8ab765 to your computer and use it in GitHub Desktop.
Save priyanshu219/7aed182c506e44a190486b46bd8ab765 to your computer and use it in GitHub Desktop.
syntax on
filetype plugin indent on
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
set noshowmatch
set ignorecase
set relativenumber
set nohlsearch
set hidden
set noerrorbells
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab
" set autoindent
set smartindent
set nu
set nowrap
set smartcase
set noswapfile
set nobackup
set undodir=~/.nvim/undodir
set undofile
set incsearch
set termguicolors
set scrolloff=8
set completeopt=menuone,noinsert,noselect
set noshowmode
set signcolumn=yes
"set clipboard=unnamed
set clipboard+=unnamedplus
set cmdheight=2
set updatetime=50
set shortmess+=c
set colorcolumn=70
highlight ColorColumn ctermbg=0 guibg=lightgrey
call plug#begin()
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/completion-nvim'
Plug 'nvim-lua/diagnostic-nvim'
Plug 'tjdevries/nlua.nvim'
Plug 'tjdevries/lsp_extensions.nvim'
Plug 'rust-lang/rust.vim'
Plug 'mattn/webapi-vim'
Plug 'tweekmonster/gofmt.vim'
Plug 'tpope/vim-fugitive'
Plug 'vim-utils/vim-man'
Plug 'mbbill/undotree'
Plug 'sheerun/vim-polyglot'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'jremmen/vim-ripgrep'
Plug 'lyuts/vim-rtags'
Plug 'vuciv/vim-bujo'
Plug 'tpope/vim-dispatch'
Plug 'machakann/vim-sandwich'
"Plug 'euclio/vim-markdown-composer', { 'do': function('BuildComposer') }
Plug 'gruvbox-community/gruvbox'
Plug 'colepeters/spacemacs-theme.vim'
Plug 'sainnhe/gruvbox-material'
Plug 'phanviet/vim-monokai-pro'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'flazz/vim-colorschemes'
"Plug 'ThePrimeagen/vim-be-good', {'do': './'}
Plug 'tpope/vim-eunuch'
Plug 'chriskempson/base16-vim'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'vim-jp/vim-cpp'
Plug 'preservim/nerdcommenter'
Plug 'jiangmiao/auto-pairs'
Plug 'google/vim-maktaba'
Plug 'google/vim-codefmt'
Plug 'google/vim-glaive'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-lua/telescope.nvim'
call plug#end()
call glaive#Install()
runtime macros/sandwich/keymap/surround.vim
let base16colorspace=256
let g:gruvbox_contrast_dark = 'hard'
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
let g:gruvbox_invert_selection='0'
" telescope
let g:telescope_cache_results = 1
let g:telescope_prime_fuzzy_find = 1
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
let g:cpp_posix_standard = 1
let g:cpp_concepts_highlight = 1
" rust
let g:rustfmt_autosave = 1
let g:rust_clip_command = 'xclip -selection clipboard'
let g:NERDSpaceDelims = 1
let g:NERDCompactSexyComs = 1
let g:NERDTrimTrailingWhitespace = 1
let g:NERDToggleCheckAllLines = 1
let g:NERDCommentEmptyLines = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='gruvbox'
colorscheme gruvbox
set background=dark
if executable('rg')
let g:rg_derive_root='true'
let loaded_matchparen = 1
let mapleader = " "
let g:netrw_browse_split = 2
let g:netrw_banner = 0
let g:netrw_winsize = 25
let g:netrw_localrmdir='rm -r'
let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } }
let $FZF_DEFAULT_OPTS='--reverse'
nmap <C-_> <leader>c<space>
vmap <C-_> <leader>cs
imap <C-_> <ESC><leader>c<space>i
imap <C-z> <ESC>:u<CR>i
inoremap jj <C-[>:w<CR>
nnoremap <leader>vd :lua vim.lsp.buf.definition()<CR>
nnoremap <leader>vi :lua vim.lsp.buf.implementation()<CR>
nnoremap <leader>vsh :lua vim.lsp.buf.signature_help()<CR>
nnoremap <leader>vrr :lua vim.lsp.buf.references()<CR>
nnoremap <leader>vrn :lua vim.lsp.buf.rename()<CR>
nnoremap <leader>vh :lua vim.lsp.buf.hover()<CR>
nnoremap <leader>vca :lua vim.lsp.buf.code_action()<CR>
nnoremap <leader>vsd :lua vim.lsp.util.show_line_diagnostics(); vim.lsp.util.show_line_diagnostics()<CR>
nnoremap <leader>gc :GBranches<CR>
nnoremap <leader>ga :Git fetch --all<CR>
nnoremap <leader>grum :Git rebase upstream/master<CR>
nnoremap <leader>grom :Git rebase origin/master<CR>
nnoremap <leader>ghw :h <C-R>=expand("<cword>")<CR><CR>
nnoremap <leader>prw :CocSearch <C-R>=expand("<cword>")<CR><CR>
nnoremap <leader>pw :lua require('telescope.builtin').grep_string { search = vim.fn.expand("<cword>") }<CR>
nnoremap <leader>ps :lua require('telescope.builtin').grep_string()<CR>
nnoremap <leader>bs /<C-R>=escape(expand("<cWORD>"), "/")<CR><CR>
" nnoremap <leader>pw :Rg <C-R>=expand("<cword>")<CR><CR>
" nnoremap <leader>phw :h <C-R>=expand("<cword>")<CR><CR>
nnoremap <leader>h :wincmd h<CR>
nnoremap <leader>j :wincmd j<CR>
nnoremap <leader>k :wincmd k<CR>
nnoremap <leader>l :wincmd l<CR>
nnoremap <leader>u :UndotreeShow<CR>
nnoremap <leader>pv :wincmd v<bar> :Ex <bar> :vertical resize 30<CR>
nnoremap <leader>ps :lua require('telescope.builtin').grep_string({ search = vim.fn.input("Grep For >") })<CR>
nnoremap <C-p> :lua require('telescope.builtin').git_files()<CR>
nnoremap <C-o> :Files
nnoremap <Leader>pf :GFiles
nnoremap <Leader><CR> :so ~/.config/nvim/init.vim<CR>
nnoremap <Leader>+ :vertical resize +5<CR>
nnoremap <Leader>- :vertical resize -5<CR>
nnoremap <Leader>rp :resize 100<CR>
nnoremap <Leader>ee oif err != nil {<CR>log.Fatalf("%+v\n", err)<CR>}<CR><esc>kkI<esc>
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" greatest remap ever
vnoremap <leader>p "_dP
" vim TODO
nmap <Leader>tu <Plug>BujoChecknormal
nmap <Leader>th <Plug>BujoAddnormal
let g:bujo#todo_file_path = $HOME . "/.cache/bujo"
nnoremap <Leader>ww ofunction wait(ms: number): Promise<void> {<CR>return new Promise(res => setTimeout(res, ms));<CR>}<esc>k=i{<CR>
" Vim with me
nnoremap <leader>vwm :colorscheme gruvbox<bar>:set background=dark<CR>
nmap <leader>vtm :highlight Pmenu ctermbg=gray guibg=gray
inoremap <C-c> <esc>
let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy']
lua require'nvim_lsp'.clangd.setup{ on_attach=require'completion'.on_attach }
lua require'nvim_lsp'.rust_analyzer.setup{ on_attach=require'completion'.on_attach }
nmap <leader>gh :diffget //3<CR>
nmap <leader>gu :diffget //2<CR>
nmap <leader>gs :G<CR>
" Terminal commands
" ueoa is first through fourth finger left hand home row.
" This just means I can crush, with opposite hand, the 4 terminal positions
nmap <leader>tu :call GotoBuffer(0)<CR>
nmap <leader>te :call GotoBuffer(1)<CR>
nmap <leader>to :call GotoBuffer(2)<CR>
nmap <leader>ta :call GotoBuffer(3)<CR>
nmap <leader>tsu :call SetBuffer(0)<CR>
nmap <leader>tse :call SetBuffer(1)<CR>
nmap <leader>tso :call SetBuffer(2)<CR>
nmap <leader>tsa :call SetBuffer(3)<CR>
fun! EmptyRegisters()
let regs=split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"', '\zs')
for r in regs
call setreg(r, [])
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
" ES
com! W w
fun! Kratos_LspHighlighter()
lua print("Testing")
lua package.loaded["my_lspconfig"] = nil
lua require("my_lspconfig")
fun! GotoBuffer(ctrlId)
if (a:ctrlId > 9) || (a:ctrlId < 0)
echo "CtrlID must be between 0 - 9"
let contents = g:win_ctrl_buf_list[a:ctrlId]
if type(l:contents) != v:t_list
echo "Nothing There"
let bufh = l:contents[1]
call nvim_win_set_buf(0, l:bufh)
" How to do this but much better?
let g:win_ctrl_buf_list = [0, 0, 0, 0]
fun! SetBuffer(ctrlId)
if has_key(b:, "terminal_job_id") == 0
echo "You must be in a terminal to execute this command"
if (a:ctrlId > 9) || (a:ctrlId < 0)
echo "CtrlID must be between 0 - 9"
let g:win_ctrl_buf_list[a:ctrlId] = [b:terminal_job_id, nvim_win_get_buf(0)]
fun! SendTerminalCommand(ctrlId, command)
if (a:ctrlId > 9) || (a:ctrlId < 0)
echo "CtrlID must be between 0 - 9"
let contents = g:win_ctrl_buf_list[a:ctrlId]
if type(l:contents) != v:t_list
echo "Nothing There"
let job_id = l:contents[0]
call chansend(l:job_id, a:command)
com! SetLspVirtualText call Kratos_LspHighlighter()
augroup highlight_yank
autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank({timeout = 40})
augroup END
let s:clip = '/mnt/c/Windows/System32/clip.exe' " change this path according to your mount point
if executable(s:clip)
augroup WSLYank
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
augroup END
augroup darknight
autocmd BufWritePre * :call TrimWhitespace()
autocmd BufEnter,BufWinEnter,TabEnter .*cpp :lua require 'lsp_extensions'.inlay_hints{}
" autocmd BufEnter,BufWinEnter,TabEnter *.rs :lua require 'lsp_extensions'.inlay_hints{}
autocmd FileType c,cpp,proto,javascript AutoFormatBuffer clang-format
augroup END
Copy link

priyanshu219 commented Jun 25, 2020

First install the plugins, after this execute the statements after call plug#end()
This means write statements after plug#end(), after the installation of the plugin, then write the statements below plug#end()

If :CocInstall coc-clangd not work then

  1. use Plug 'clangd/coc-clangd'
  2. go to the plugin directory, then go to coc-clangd directory
  3. yarn config set "strict-ssl" false -g (In case of no user certificate) (After completion make it true)
  4. yarn install --frozen-lockfile

With npm, you can use (in case of ssl failure)

sudo npm config set strict-ssl true

Set this false after use

This yarn method works for other coc (same as it works for coc-clangd) commands and may also work for other plugins (depending on the presence of yarn.lock file)

Copy link

priyanshu219 commented Jun 25, 2020

Also create ~/.config/nvim/init.vim
Install clang
For indentation of 4, type ->

clang-format -style='{IndentWidth: 4}' -dump-config > .clang-format

For more information, see clang-official-docs

Also check :checkheath and install all the extensions with cross sign

Copy link

priyanshu219 commented Jul 6, 2020

Use <C-_> as vim treat as <C-_>
So ultimately when you type <C - /> it will treat it as <C-_> as comment works
Stupid machine XD

Copy link

priyanshu219 commented Jul 8, 2020

curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs

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