Skip to content

Instantly share code, notes, and snippets.

@narimiran
Created October 22, 2021 17:56
Show Gist options
  • Save narimiran/7b155482930cec4aa7141e5a28e82023 to your computer and use it in GitHub Desktop.
Save narimiran/7b155482930cec4aa7141e5a28e82023 to your computer and use it in GitHub Desktop.
call plug#begin()
""" Aesthetics
Plug 'luochen1990/rainbow' " rainbow parenthesis
Plug 'morhetz/gruvbox' " gruvbox colorscheme
Plug 'Yggdroot/indentLine' " toggle line indentation markers
Plug 'arcticicestudio/nord-vim'
""" Functionalities
Plug 'tpope/vim-commentary' " easier commenting out
Plug 'tpope/vim-fugitive' " git
Plug 'tpope/vim-repeat' " use `.` for more stuff
Plug 'tpope/vim-surround' " easily modify surrounding objects
Plug 'tpope/vim-unimpaired' " toggle various options, e.g. yob, [os
Plug 'tpope/vim-vinegar' " enhance built-in file browser
Plug 'kassio/neoterm'
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim' " fuzzy find with lots of goodies
Plug 'junegunn/vim-easy-align' " easy align multiple lines
Plug 'junegunn/vim-slash' " better search with automatic :noh
Plug 'prabirshrestha/vim-lsp' " async LSP plugin
Plug 'prabirshrestha/asyncomplete.vim' " code completion engine
Plug 'prabirshrestha/asyncomplete-lsp.vim' " lsp
Plug 'prabirshrestha/asyncomplete-buffer.vim' " buffer completion
Plug 'ishitaku5522/asyncomplete-omni.vim' " a fork of 'yami-beta/asyncomplete-omni.vim'
Plug 'prabirshrestha/asyncomplete-ultisnips.vim' " utilsnips completion
Plug 'thomasfaingnaert/vim-lsp-snippets'
Plug 'thomasfaingnaert/vim-lsp-ultisnips'
Plug 'airblade/vim-gitgutter' " show changes in the gutter
" Plug 'alaviss/nim.nvim', { 'branch': 'indent-rewrite' }
Plug 'alaviss/nim.nvim',
Plug 'dense-analysis/ale' " linter
Plug 'ervandew/supertab' " tab completion
Plug 'honza/vim-snippets' " various snippets, needs 'SirVer/ultisnips'
Plug 'SirVer/ultisnips' " snippets engine, uses 'honza/vim-snippets'
Plug 'lervag/vimtex' " LaTeX plugin
Plug 'machakann/vim-highlightedyank' " short highlight of a yank
Plug 'machakann/vim-swap' " easy swapping of arguments/elements
Plug 'mbbill/undotree' " see and navigate a tree of previous edits
Plug 'moll/vim-bbye' " delete buffers without closing their window
Plug 'let-def/ocp-indent-vim' " better indentation rules for OCaml
" Plug 'glacambre/firenvim', { 'do': function('firenvim#install') }
Plug 'kovisoft/slimv'
Plug 'wlangstroth/vim-racket'
Plug 'mbal/swank-racket'
call plug#end()
""" Configuration
filetype plugin indent on
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab
set autoindent smartindent
set incsearch ignorecase smartcase hlsearch
set list listchars=trail:»,tab:»-
set fillchars+=vert:\
set encoding=utf-8
set termguicolors " use 24-bit color
set wrap breakindent " indent wrapped lines
set number " show line numbers
set relativenumber " line numbers relative to the current one
set showtabline=1 " show tabline only when more than one tab
set title " show window title
set hidden " allows changing buffers without warning
set linebreak " do not break words when wrapping
set splitbelow splitright " default split to the right and below
set inccommand=split " show effects of a command (e.g. substitute (:%s)) incrementally
set mouse=a " activate mouse
set diffopt+=vertical " vertical diff-split by default
set ruler " show line:col numbers
set laststatus=2 " always show status bar
set showcmd showmode " show partial comand and editor mode
set synmaxcol=500 " smaller max col for syntax highlighting, faster redraw
set lazyredraw " do not redraw in the middle of a macro; faster macros
set suffixesadd=.nim,.ml,.c,.py " for `gf` to try adding a suffix when matching file under cursor
set path+=** " add all subdirectories to the path for file searches
set virtualedit=block " allow positioning cursor beyond last character (rectangles)
set nofoldenable " leave all folds open when opening a file
set showmatch " shortly highlight matching parenthesis
set matchtime=1 " the length of the highlight ^
set undofile " have persistent undo
set undodir=~/.cache/nvim-undo " location for undo history
set switchbuf=useopen " jump to window that contains the specified buffer
set clipboard+=unnamed " use register '*' for all yanks and deletes
syntax on
"" Status line
set statusline=
set statusline+=%02n\ %y " buffer, filetype(syntax)
set statusline+=\ %f\ %m%r " filename, modified, read-only
set statusline+=%= " left - right separator
set statusline+=\ %4l:%2c\ %3p%%\ " line, column, percent
"" Neovim :Terminal
tnoremap <Esc> <C-\><C-n>
tnoremap <C-v><Esc> <Esc>
tmap <C-w> <Esc><C-w>
autocmd TermOpen * setlocal nonumber norelativenumber
""" Custom Functions
"" trim whitespaces
function! TrimWhitespace()
let l:save = winsaveview()
%s/\\\@<!\s\+$//e
call winrestview(l:save)
endfunction
"" Ocaml multiline comments
function! MultiComments()
'<s/\(.*\)/(\* \1/
'<+1,'>-1s/\(.*\)/ \* \1/
'>s/\(.*\)/ \* \1 \*)/
endfunction
function! DisableMultiComments()
'<,'>s/[( ]\* //
'>s/ \*)//
endfunction
"" nvr closes on ZZ (useful for interactive rebase)
autocmd FileType gitcommit set bufhidden=delete
"" better latex syntax highlighting
let g:tex_flavor = "context"
autocmd FileType tex set syntax=context
""" Custom Mappings
let mapleader="\<space>"
nmap <leader>rr :so ~/.config/nvim/init.vim<CR>
nmap <leader>tw :call TrimWhitespace()<CR>
nmap <leader>tl <C-w>v:Tnew<CR>
nmap <leader>tj <C-w>s:Tnew<CR>
nmap <silent> <leader>/ :noh<CR>
" use mouse with faster scrolling
map <ScrollWheelUp> 12<C-Y>
map <ScrollWheelDown> 12<C-E>
" uppercase U is redo
nmap U <C-r>
" uppercase Y is similar to D, C, etc.
nmap Y y$
" search visual selection with *:
vnoremap * y/<C-R>"<CR>
" toggle comments with Ctrl+/
nmap <C-_> gcc
xmap <C-_> gc
" repeat last command:
nmap <F2> @:
" save with Ctrl+s:
nmap <C-s> :w<CR>
" paste from clipboard (selection) in insert mode with ctrl+v (not needed with clipboard+=unnamedplus),
" remap using literals to ctrl+l
inoremap <C-l> <C-v>
imap <C-v> <Esc>"+p
cmap <C-v> <C-r>+
" copy to clipboard in visual mode: (not needed with clipboard+=unnamedplus)
xmap <C-c> "+y
" remap inc from C-a to C-b, so C-a can be used for select all (dec is still C-x)
nnoremap <C-b> <C-a>
" select all
nmap <C-a> ggVG
" open a file from the same directory as current file
nmap <leader>ce :e <C-R>=expand("%:h")."/"<CR>
" save as in the same directory as current file
nmap <leader>we :saveas <C-R>%
" change working directory for current tab to the current file (and print it)
nnoremap <leader>cd :tcd %:p:h<CR>:pwd<CR>
" put search result in the middle of the screen (not needed with vim-slash plugin)
" nmap n nzz
" nmap N Nzz
" list all matches for a previous search (/)
nmap <C-f> :vimgrep /<C-r>//g %<CR> \| !:copen <Enter>
" save session and quit (load session with `nvim -S`)
nmap <leader>qss :mksession!<CR>:qall<CR>
" enable/disable highlighted column
nnoremap <silent> <leader>l8 :execute "set colorcolumn=" . (&colorcolumn == "" ? "81,101,121" : "")<CR>
" open/close quickfix list
nmap <leader>cc :copen<CR>
nmap <leader>co :cclose<CR>
" open/close location list
nmap <leader>ll :lopen<CR>
nmap <leader>lo :lclose<CR>
" older/newer quickfix entries
nmap [C :colder<CR>
nmap ]C :cnewer<CR>
" run spell checker for a file (also toggled with `yos`)
nmap <leader>sc :setlocal spell spelllang=en<CR>
nmap <leader>so :set nospell<CR>
" bbye plugin: delete buffer, keep window open
nmap <leader>bd :Bdelete<CR>
nmap <leader>ww <C-w>c
" create X number of windows, with terminal in bottom-right window
nmap <leader>3w <C-w>v<C-w>v<C-w>s:Tnew<CR>
nmap <leader>6w <C-w>v<C-w>v<C-w>s:Tnew<CR><C-w>h<C-w>s<C-w>h<C-w>s<C-w>k
" easier start and end of a line
nmap H ^
vmap H ^
nmap L $
vmap L $
" go to a filename:line in a vertical split
nnoremap <C-w><C-f> <C-w>vgF
" move by displayed (wrapped) lines
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
nnoremap j gj
nnoremap k gk
nnoremap <Down> gj
noremap <Up> gk
" faster `:diffget <window>` for merge conflicts
nmap <leader>doo :diffget //2<CR>
nmap <leader>don :diffget //3<CR>
" replace current word
nnoremap <leader>ra :%s/\<<C-r><C-w>\>/
vnoremap <leader>ra y:%s/\V<C-r>"/
nnoremap <leader>rA :%s/\<<C-r><C-w>\>/<C-r><C-w>
vnoremap <leader>rA y:%s/\V<C-r>"/<C-r>"
" toggle wrapping
nmap <leader>= :set wrap!<CR>
" json prettify
nmap <leader>jq :%!jq '.'<CR>
" ctrl+click follows links
nmap <C-LeftMouse> gx
""" Make configurations
" run make
nmap <leader>mm :w<CR>:make<CR>
" Nim
autocmd FileType nim setlocal makeprg=nim\ c\ --listFullPaths\ --hints:off\ -r\ %
nmap <leader>nm :setlocal makeprg=nim\ c\ --listFullPaths\ --hints:off\ -r\ %<CR>
" OCaml
autocmd FileType ocaml setlocal makeprg=dune\ exec\ %\:.:r.exe
nmap <leader>om :setlocal makeprg=dune\ exec\ %:.:r.exe<CR>
" Python
autocmd FileType python setlocal makeprg=python\ %
nmap <leader>pm :setlocal makeprg=python\ %<CR>
" Racket
autocmd FileType racket setlocal makeprg=racket\ %
nmap <leader>rm :setlocal makeprg=racket\ %<CR>
""" Plugin Configurations
"" gruvbox settings
"" https://github.com/morhetz/gruvbox/wiki/Configuration
let g:gruvbox_contrast_dark='medium'
let g:gruvbox_contrast_light='soft'
let g:gruvbox_vert_split='bg1'
let g:gruvbox_sign_column='bg0'
let g:gruvbox_number_column='bg0'
let g:gruvbox_italic=1
" color gruvbox
let g:nord_bold_vertical_split_line = 1
let g:nord_italic=1
let g:nord_italic_comments = 1
color nord
"" fugitive
nmap <leader>gs :Git<CR>
nmap <leader>gd :Gvdiffsplit<CR>
nmap <leader>gpp :Gvdiffsplit HEAD^<CR>
nmap <leader>gpd :Gvdiffsplit devel<CR>
nmap <leader>gw :Gwrite<CR>
nmap <leader>gr :Gread<CR>
nmap <leader>gc :Git commit<CR>
nmap <leader>gb :Git blame<CR>
"" LSP stuff
nmap <leader>lr :LspRename<CR>
nmap <leader>lh :LspHover<CR>
let g:lsp_highlight_references_delay = 100
let g:lsp_semantic_enabled = 1
"" Neoterm
nmap <leader>tr :TREPLSetTerm 1
nmap <leader>rl :TREPLSendLine<CR>
nmap <leader>rf :TREPLSendFile<CR>
vmap <leader>rv :TREPLSendSelection<CR>
nmap <leader>rp vip:TREPLSendSelection<CR>
"" gitgutter
set updatetime=250 " faster update times
nmap <leader>hs <Plug>(GitGutterStageHunk)
nmap <leader>hu <Plug>(GitGutterUndoHunk)
"" Supertab
let g:SuperTabDefaultCompletionType = "context"
" au FileType ocaml call SuperTabSetDefaultCompletionType("<c-x><c-o>")
"" EasyAlign
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
xmap <leader>a gaip*
nmap <leader>a gaip*
" undotree
nnoremap <leader>u :UndotreeToggle<cr>
let g:undotree_SetFocusWhenToggle = 1
let g:undotree_DiffpanelHeight = 16
"" highlightedyank
let g:highlightedyank_highlight_duration = 300
"" netrw (`-`)
" hide dot-files, toggle with `gh`
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
" ignore case
let g:netrw_sort_options="i"
"" fzf-vim
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'Type'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Character'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
let g:fzf_layout = {'down': '25%'}
let g:fzf_history_dir = '~/.cache/fzf-history'
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(green)(%ar) %C(bold blue)<%an>%C(reset)"'
nmap <leader>ff :Files<CR>
nmap <leader>gg :GFiles<CR>
nmap <leader>gl :Commits<CR>
nmap <leader>gh :BCommits<CR>
nmap <leader>rg :Rg<CR>
nmap <leader>ee :Colors<CR>
nmap <leader>bb :Buffers<CR>
nmap <leader>wi :Windows<CR>
" nmap <leader>tt :Windows<CR>1 term://<cr>
" nmap <leader>tt fzf#vim#windows
nmap <leader>ma :Marks<CR>
"" rainbow
let g:rainbow_conf = {
\ 'guifgs': ['lightblue3', 'darkorange3', 'seashell2', 'RosyBrown2', 'seagreen3', 'orchid1'],
\ 'ctermfgs': ['green', 'yellow', 'darkblue', 'magenta'],
\ 'separately': {
\ 'pascal': {
\ 'parentheses': ['start=/(\ze[^*]/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\[|/ end=/|\]/ fold', 'start=/{/ end=/}/ fold'],
\ },
\ 'racket': {
\ 'parentheses': ["start=/(/ end=/)/ fold", "start=/`(/ end=/)/ fold", "start=/'(/ end=/)/ fold", 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\} } }
let g:rainbow_active = 1
nmap <leader>hh :RainbowToggle<CR>
" autocmd BufEnter * RainbowToggleOn
"" UltiSnips
let g:UltiSnipsSnippetsDir="~/.config/nvim/my_snippets"
let g:UltiSnipsSnippetDirectories=["UltiSnips", "my_snippets"]
let g:UltiSnipsListSnippets="<F8>"
let g:UltiSnipsExpandTrigger="<c-e>"
"" indentLine
let g:indentLine_enabled = 0
" let g:indentLine_char_list = [' ', '┊']
let g:indentLine_char = '┊'
nmap <leader>il :IndentLinesToggle<CR>
" vim-unimpaired shortcuts:
" https://github.com/tpope/vim-unimpaired/blob/master/doc/unimpaired.txt
"" vim-slash
" put search match in the center of the window
" noremap <plug>(slash-after) zz
"" OCaml stuff
" let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
" execute "set rtp+=" . g:opamshare . "/merlin/vim"
autocmd FileType ocaml setlocal commentstring=\(\*\ %s\ \*\)
" merlin docs: https://github.com/ocaml/merlin/blob/master/vim/merlin/doc/merlin.txt
" nmap <leader>mt :MerlinTypeOf<CR>
xmap <leader>mt :MerlinTypeOfSel<CR>
nmap <leader>mg :MerlinGrowEnclosing<CR>
nmap <leader>mx :MerlinDestruct<CR>
nmap <leader>md :MerlinDocument<CR>
nmap <leader>mr <Plug>(MerlinRename)
nmap <leader>mR <Plug>(MerlinRenameAppend)
nmap <LocalLeader>* <Plug>(MerlinSearchOccurrencesForward)
nmap <LocalLeader># <Plug>(MerlinSearchOccurrencesBackward)
nmap <leader>occ :call MultiComments()<CR>
xmap <leader>occ <Esc> :call MultiComments()<CR>
nmap <leader>oco :call DisableMultiComments()<CR>
xmap <leader>oco <Esc> :call DisableMultiComments()<CR>
" nmap <leader>of :!ocamlformat --enable-outside-detected-project --ocp-indent-compat --profile conventional -i %<CR>
"" Nim stuff
nmap <leader>nr :NimReferences<CR>
nmap <leader>nt :NimTypeOf<CR>
function s:doTypeOf() abort
if &filetype == 'nim'
NimTypeOf
elseif &filetype == 'ocaml'
MerlinTypeOf
endif
endfunction
nmap <silent> <leader>tt :call <SID>doTypeOf()<CR>
"" Common Lisp stuff
let g:slimv_leader=','
let g:lisp_rainbow=1
" set runtimepath^=~/.config/nvim/plugged/slimv
" let g:slimv_swank_cmd = '! sbcl --load ~/.config/nvim/plugged/slimv/slime/start-swank.lisp &'
"" Racket stuff
" let g:slimv_swank_cmd = '! racket ~/.config/nvim/plugged/swank-racket/server.rkt &'
"" ALE
" toggle ALE
nmap <leader>lt :ALEToggle<CR>
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
let g:ale_sign_error = ' ×'
let g:ale_sign_warning = " '"
let g:ale_linters_explicit = 0
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_enter = 1
let g:ale_lint_on_save = 1
let g:ale_fix_on_save = 1
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%severity%] %linter%: %s'
let g:ale_linters = {
\ 'ocaml': ['merlin'],
\ 'python': ['pyls'],
\}
" let g:ale_fixers = {
" \ 'ocaml': ['ocamlformat'],
" \}
""" asyncomplete
set completeopt+=menuone,noselect
" disable preview window with documentation
set completeopt-=preview
" use this if 'preview' is not disabled in the line above
" autocmd! CompleteDone * if pumvisible() == 0 | pclose | endi
" disable short messages about completion:
set shortmess+=c
let g:asyncomplete_smart_completion = 1
let g:asyncomplete_auto_popup = 1
let g:asyncomplete_auto_completeopt = 0
let g:asyncomplete_min_chars = 2
imap <c-space> <Plug>(asyncomplete_force_refresh)
au User asyncomplete_setup call asyncomplete#register_source(
\ asyncomplete#sources#buffer#get_source_options({
\ 'name': 'buffer',
\ 'whitelist': ['*'],
\ 'blacklist': ['nim', 'python', 'racket'],
\ 'completor': function('asyncomplete#sources#buffer#completor'),
\ }))
au User asyncomplete_setup call asyncomplete#register_source({
\ 'name': 'nim',
\ 'whitelist': ['nim'],
\ 'completor': {opt, ctx -> nim#suggest#sug#GetAllCandidates(
\ {start, candidates -> asyncomplete#complete(opt['name'], ctx, start, candidates)})}
\ })
au User asyncomplete_setup call asyncomplete#register_source(
\ asyncomplete#sources#omni#get_source_options({
\ 'name': 'omni',
\ 'whitelist': ['*'],
\ 'blacklist': ['c', 'cpp', 'html', 'nim', 'python'],
\ 'completor': function('asyncomplete#sources#omni#completor')
\ }))
au User asyncomplete_setup call asyncomplete#register_source(
\ asyncomplete#sources#ultisnips#get_source_options({
\ 'name': 'ultisnips',
\ 'whitelist': ['*'],
\ 'completor': function('asyncomplete#sources#ultisnips#completor'),
\ }))
if executable('pyls')
au User lsp_setup call lsp#register_server({
\ 'name': 'pyls',
\ 'cmd': {server_info->['pyls']},
\ 'whitelist': ['python'],
\ })
endif
if executable('ocaml-language-server')
au User lsp_setup call lsp#register_server({
\ 'name': 'ocaml-language-server',
\ 'cmd': {server_info->[&shell, &shellcmdflag, 'opam config exec -- ocaml-language-server --stdio']},
\ 'whitelist': ['reason', 'ocaml'],
\ })
endif
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> <f2> <plug>(lsp-rename)
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment