Skip to content

Instantly share code, notes, and snippets.

@susliko
Created August 1, 2021 10:51
Show Gist options
  • Save susliko/e2c373ae05c7c90bc56e810612747990 to your computer and use it in GitHub Desktop.
Save susliko/e2c373ae05c7c90bc56e810612747990 to your computer and use it in GitHub Desktop.
" basics
set encoding=utf-8
set number
filetype plugin on
syntax on
set relativenumber
set tabstop=4
set shiftwidth=4
set expandtab
set smartcase
set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
highlight lCursor guifg=NONE guibg=Cyan
" language switch
inoremap <C-l> <C-^>
" windows switch
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" plugins
call plug#begin('~/.vim/plugged')
Plug 'lervag/vimtex'
Plug 'tpope/vim-surround'
Plug 'morhetz/gruvbox'
Plug 'chrisbra/Colorizer'
Plug 'sheerun/vim-polyglot'
Plug 'preservim/nerdtree'
Plug 'dense-analysis/ale'
Plug 'kien/ctrlp.vim'
Plug 'mechatroner/rainbow_csv'
Plug 'florentc/vim-tla'
Plug 'JamshedVesuna/vim-markdown-preview'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'vim-airline/vim-airline'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
if has('nvim')
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'rmagatti/auto-session'
endif
call plug#end()
" theme
let g:gruvbox_guisp_fallback = "bg"
colorscheme gruvbox
set background=dark
" NERDTree file navigator
nnoremap <C-n> :NERDTreeToggle<CR>
" pretty TLA+ expressions
:set conceallevel=2
" Find files using Telescope command-line sugar.
nnoremap <space>ff <cmd>Telescope find_files<cr>
nnoremap <space>fg <cmd>Telescope live_grep<cr>
nnoremap <space>fb <cmd>Telescope buffers<cr>
nnoremap <space>fh <cmd>Telescope help_tags<cr>
" Using Lua functions
nnoremap <space>ff <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <space>fg <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <space>fb <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <space>fh <cmd>lua require('telescope.builtin').help_tags()<cr>
" Configuration for coc.nvim
" If hidden is not set, TextEdit might fail.
set hidden
" Some servers have issues with backup files
set nobackup
set nowritebackup
" You will have a bad experience with diagnostic messages with the default 4000.
set updatetime=300
" Don't give |ins-completion-menu| messages.
set shortmess+=c
" Always show signcolumns
set signcolumn=yes
" Help Vim recognize *.sbt and *.sc as Scala files
au BufRead,BufNewFile *.sbt,*.sc set filetype=scala
" 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>"
" Used in the tab autocompletion for coc
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
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <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)
" Used to expand decorations in worksheets
nmap <Leader>ws <Plug>(coc-metals-expand-decoration)
" Use K to either doHover or 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 symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
augroup mygroup
autocmd!
" 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)
" 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>)
" Trigger for code actions
" Make sure `"codeLens.enable": true` is set in your coc config
nnoremap <leader>cl :<C-u>call CocActionAsync('codeLensAction')<CR>
nnoremap <leader>l call CocAction<CR>
" 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>
" Notify coc.nvim that <enter> has been pressed.
" Currently used for the formatOnType feature.
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Toggle panel with Tree Views
nnoremap <silent> <space>t :<C-u>CocCommand metals.tvp<CR>
" Toggle Tree View 'metalsPackages'
nnoremap <silent> <space>tp :<C-u>CocCommand metals.tvp metalsPackages<CR>
" Toggle Tree View 'metalsCompile'
nnoremap <silent> <space>tc :<C-u>CocCommand metals.tvp metalsCompile<CR>
" Toggle Tree View 'metalsBuild'
nnoremap <silent> <space>tb :<C-u>CocCommand metals.tvp metalsBuild<CR>
" Reveal current current class (trait or object) in Tree View 'metalsPackages'
nnoremap <silent> <space>tf :<C-u>CocCommand metals.revealInTreeView metalsPackages<CR>
if has('nvim')
" With this function you can reuse the same terminal in neovim.
" You can toggle the terminal and also send a command to the same terminal.
let s:monkey_terminal_window = -1
let s:monkey_terminal_buffer = -1
let s:monkey_terminal_job_id = -1
let s:monkey_terminal_window_size = -1
function! MonkeyTerminalOpen()
" Check if buffer exists, if not create a window and a buffer
if !bufexists(s:monkey_terminal_buffer)
" Creates a window call monkey_terminal
new monkey_terminal
" Moves the window to the bottom
wincmd J
resize 15
let s:monkey_terminal_job_id = termopen($SHELL, { 'detach': 1 })
" Change the name of the buffer to "Terminal 1"
silent file Terminal\ 1
" Gets the id of the terminal window
let s:monkey_terminal_window = win_getid()
let s:monkey_terminal_buffer = bufnr('%')
" The buffer of the terminal won't appear in the list of the buffers
" when calling :buffers command
set nobuflisted
else
if !win_gotoid(s:monkey_terminal_window)
sp
" Moves to the window below the current one
wincmd J
execute "resize " . s:monkey_terminal_window_size
buffer Terminal\ 1
" Gets the id of the terminal window
let s:monkey_terminal_window = win_getid()
endif
endif
" insert mode in terminal
startinsert
endfunction
function! MonkeyTerminalToggle()
if win_gotoid(s:monkey_terminal_window)
call MonkeyTerminalClose()
else
call MonkeyTerminalOpen()
endif
endfunction
function! MonkeyTerminalClose()
if win_gotoid(s:monkey_terminal_window)
let s:monkey_terminal_window_size = winheight(s:monkey_terminal_window)
" close the current window
hide
endif
endfunction
function! MonkeyTerminalExec(cmd)
if !win_gotoid(s:monkey_terminal_window)
call MonkeyTerminalOpen()
endif
" clear current input
call jobsend(s:monkey_terminal_job_id, "clear\n")
" run cmd
call jobsend(s:monkey_terminal_job_id, a:cmd . "\n")
normal! G
wincmd p
endfunction
" With this maps you can now toggle the terminal
nnoremap <C-T> :call MonkeyTerminalToggle()<cr>
tnoremap <C-T> <C-\><C-n>:call MonkeyTerminalToggle()<cr>
tnoremap <Esc> <C-\><C-n>
endif
" resize windows
nnoremap <Left> :vertical resize -6<CR>
nnoremap <Right> :vertical resize +6<CR>
nnoremap <Up> :resize -2<CR>
nnoremap <Down> :resize +2<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment