From 32c1044d90189afa7ee5233f08700732d6a8c6c0 Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Thu, 6 Aug 2020 21:20:51 +0200 Subject: [PATCH] Cleanup vim --- coc-settings.json | 1 + init.vim | 199 ++++++++++++++++++++++++++++++++++++++++++++- lsp.vim | 60 ++++++++++++++ plugins.vim | 93 +++++++++++++++++++++ whichkeyConfig.vim | 86 ++++++++++++++++++++ 5 files changed, 436 insertions(+), 3 deletions(-) create mode 120000 coc-settings.json create mode 100644 lsp.vim create mode 100644 plugins.vim create mode 100644 whichkeyConfig.vim diff --git a/coc-settings.json b/coc-settings.json new file mode 120000 index 0000000..d6b7482 --- /dev/null +++ b/coc-settings.json @@ -0,0 +1 @@ +../../.vim/coc-settings.json \ No newline at end of file diff --git a/init.vim b/init.vim index b42c8d9..63d1843 100644 --- a/init.vim +++ b/init.vim @@ -1,3 +1,196 @@ -set runtimepath^=~/.vim runtimepath+=~/.vim/after -let &packpath=&runtimepath -source ~/.vimrc + +" __ _(_)_ __ ___ _ __ ___ +" \ \ / / | '_ ` _ \| '__/ __| +" \ V /| | | | | | | | | (__ +" \_/ |_|_| |_| |_|_| \___| + +source ~/.config/nvim/plugins.vim + + +if &shell =~# 'fish$' + set shell=bash +endif + +let mapleader ="\" + + +" Vanilla VIM configuration ------------------------------------ {{{ + +filetype plugin indent on +syntax on + +set foldmethod=marker +set undodir=~/.vim/undo-dir +set undofile +set shortmess+=c " Don't give completion messages like 'match 1 of 2' or 'The only match' +set hidden +set encoding=utf-8 +set nonumber norelativenumber +set nocompatible +set cursorline + +" May cause problems! +if (has("termguicolors")) + set termguicolors +endif + +" Indentation +set shiftwidth=2 +set tabstop=2 +set backspace=indent,eol,start +set autoindent smartindent noet expandtab +set nowrap +set noshowmode " hide the mode as shown by vim, because the status line does it better! + +set completeopt=longest,menuone " Enable autocompletion +set laststatus=2 +set noshowmode + + + +set background=dark +colorscheme gruvbox +let g:onedark_terminal_italics=1 +hi LineNr ctermbg=NONE guibg=NONE +hi Comment cterm=italic +let &t_ut='' + +" hide empty line ~'s +highlight EndOfBuffer ctermfg=black ctermbg=black + +if !has("nvim") + set term=xterm-256color +endif + +" Clipboard support in WSL +func! GetSelectedText() + normal gv"xy + let result = getreg("x") + return result +endfunc + +if !has("clipboard") && executable("clip.exe") + vnoremap :call system('clip.exe', GetSelectedText()) + vnoremap :call system('clip.exe', GetSelectedText())gvx +endif + + +" Mouse config +set mouse=a +if !has("nvim") + if has("mouse_sgr") + set ttymouse=sgr + else + set ttymouse=xterm2 + end +end + +if !has('gui_running') + set t_Co=256 +endif + +augroup basics + autocmd! + autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o "Disables automatic commenting on newline: + autocmd FileType vim setlocal foldmethod=marker + + " file type assignments + autocmd BufRead,BufNewFile *.ddl setlocal filetype=sql +augroup END + +highlight Pmenu ctermbg=black guibg=black + + +" =============== +" Basic remapping +" =============== + +" Split configs +nnoremap +nnoremap +nnoremap +nnoremap +set splitbelow splitright + +" Buffer switching +noremap l :bnext +noremap h :bprevious + +" Disable default K mapping (would open man page of hovered word) +nnoremap K +vnoremap K + +" }}} + +" Plugin configuration --------------------------------------------------- {{{ + + +" Misc configuration ----------------------------------------------------- {{{ + + +autocmd BufReadPost * :DetectIndent +let g:detectindent_preferred_expandtab = 1 +let g:detectindent_preferred_indent = 2 + + +let g:sneak#label = 1 +nmap Sneak_s +nmap Sneak_S +omap Sneak_s +omap Sneak_S + +" FZF showing previews +command! -bang -nargs=? -complete=dir Files + \ call fzf#vim#files(, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline']}), 0) + +command! -bang -nargs=? -complete=dir HFiles + \ call fzf#vim#files(, {'source': 'ag --hidden --ignore .git -g ""'}, 0) + +let g:rust_clip_command = 'xclip -selection clipboard' +let g:rustfmt_autosave = 1 + +let g:user_emmet_leader_key='e' +let g:user_emmet_settings = { 'javascript.jsx' : { 'extends' : 'jsx' }, 'typescript.jsx' : { 'extends' : 'jsx' } } + +let g:qs_highlight_on_keys = ['f', 'F', 't', 'T'] +let g:qs_lazy_highlight = 1 + + +nnoremap :Files + +map f (easymotion-bd-f) +map s (easymotion-overwin-f2) +let g:EasyMotion_smartcase = 1 + +nmap / (incsearch-forward) +nmap ? (incsearch-backward) + +let g:signify_sign_delete = '-' + +" Airline {{{ + +let g:airline#extensions#tabline#enabled = 1 +let g:airline_powerline_fonts = 0 + +let g:airline_section_a = '%#__accent_bold#%{airline#util#wrap(airline#parts#mode(),0)}%#__restore__#%{airline#util#append(airline#parts#iminsert(),0)}' +let g:airline_section_b = '' +let g:airline_section_c = '%<%<%#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_bold#%{airline#util#wrap(airline#extensions#coc#get_status(),0)}%#__restore__#' +let g:airline_section_y = '' +let g:airline_section_z = '%4l% %3v' +let g:airline_section_warning = '%{airline#extensions#whitespace#check()}%{airline#util#wrap(airline#extensions#coc#get_warning(),0)}' + +let airline#extensions#coc#error_symbol = '' +let airline#extensions#coc#warning_symbol = '' +let airline#extensions#coc#stl_format_err = '%E{[%e(#%fe)]}' +let airline#extensions#coc#stl_format_warn = '%W{[%w(#%fw)]}' + + +let g:airline_theme='elkowars_gruvbox' + +" }}} + +" }}} + +source ~/.config/nvim/whichkeyConfig.vim +source ~/.config/nvim/lsp.vim +" }}} diff --git a/lsp.vim b/lsp.vim new file mode 100644 index 0000000..b2fa364 --- /dev/null +++ b/lsp.vim @@ -0,0 +1,60 @@ +" vim-jsx +autocmd! BufRead,BufNewFile *.tsx setlocal syntax=javascript.jsx + + +" make emmet behave well with JSX in JS and TS files +let g:user_emmet_settings = { 'javascript': { 'extends': 'jsx' }, 'typescript': { 'extends': 'tsx' }} +let g:user_emmet_mode='n' + + + +" ? idk +inoremap pumvisible() ? "\" : check_back_space() ? "\" : coc#refresh() +inoremap pumvisible() ? "\" : "\" + + +function! Show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + else + call CocAction('doHover') + endif +endfunction + +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + + +" Show all diagnostics. +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~ '\s' +endfunction + + +" Add `:Format` command to format current buffer. +command! -nargs=0 Format :call CocAction('format') +command! -nargs=0 Prettier :CocCommand prettier.formatFile + +"Close preview window when completion is done. +autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif + +setlocal formatprg=floskell\ --style\ chris-done + +set signcolumn=yes +set cmdheight=1 +set updatetime=300 + +" maybe helps coc? +set nobackup +set nowritebackup + + +hi CocUnderline gui=undercurl term=undercurl +hi CocErrorHighlight ctermfg=red guifg=#c4384b gui=undercurl term=undercurl +hi CocWarningHighlight ctermfg=yellow guifg=#c4ab39 gui=undercurl term=undercurl +autocmd CursorHold * silent call CocActionAsync('highlight') +autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') + diff --git a/plugins.vim b/plugins.vim new file mode 100644 index 0000000..0fea84c --- /dev/null +++ b/plugins.vim @@ -0,0 +1,93 @@ +if empty(glob('~/.vim/autoload/plug.vim')) + silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs + \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + autocmd VimEnter * PlugInstall --sync | source $MYVIMRC +endif + + +call plug#begin('~/.vim/plugged') + + Plug 'tpope/vim-repeat' + + Plug 'junegunn/goyo.vim', {'on': 'Goyo'} + Plug 'osyo-manga/vim-over', {'on': 'OverCommandLine'} " Substitute preview + + Plug 'liuchengxu/vim-which-key' + + if has('nvim') || has('patch-8.0.902') + Plug 'mhinz/vim-signify' + else + Plug 'mhinz/vim-signify', { 'branch': 'legacy' } + endif + + Plug 'tpope/vim-fugitive' + + Plug 'preservim/nerdcommenter' + + Plug 'vim-airline/vim-airline-themes' + Plug 'vim-airline/vim-airline' + + Plug 'morhetz/gruvbox' + + Plug 'godlygeek/tabular' " :Tab /regex can align code on occurrences of the given regex. I.e. :Tab /= aligns all = signs in a block. + Plug 'tpope/vim-surround' + + Plug 'easymotion/vim-easymotion' " press f [somekey] to have quick-movement to any occurrence of the key + Plug 'christoomey/vim-tmux-navigator' " good integration with tmux pane switching + Plug 'nathanaelkane/vim-indent-guides' " Can be toggled using ig (intent-guides) + + " to select current word. to select next occurrence. + " with multiple lines selected in Visual mode, to insert cursor in each line. I not i to insert in Visual-mode. + Plug 'terryma/vim-multiple-cursors' + Plug 'hauleth/sad.vim' " Use siw instead of ciw. when using . afterwards, will find the next occurrence of the changed word and change it too + Plug 'wellle/targets.vim' " more text objects. IE: cin) (change in next parens). generally better handling of surrounding objects. + Plug 'haya14busa/incsearch.vim' " Show search result-highlights whilst typing the query + + Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Fuzzy file opener, use: :FZF or :FZF! for fullscreen + Plug 'junegunn/fzf.vim' + + Plug 'unblevable/quick-scope' " highlight targets when pressing f + Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } } " :MarkdownPreview for live markdown preview + + Plug 'jiangmiao/auto-pairs' + + Plug 'junegunn/vim-peekaboo' " highlight jump points (f, t) + + Plug 'machakann/vim-highlightedyank' + + Plug 'ciaranm/detectindent' + Plug 'pechorin/any-jump.vim' + Plug 'justinmk/vim-sneak' + Plug 'psliwka/vim-smoothie' + " Language Plugins ----------------------------------------------------- {{{ + + Plug 'LnL7/vim-nix' + + + Plug 'ap/vim-css-color' + Plug 'pangloss/vim-javascript' " syntax highlighting JS + Plug 'ianks/vim-tsx' + Plug 'leafgarland/typescript-vim' + Plug 'sheerun/vim-polyglot' " Syntax highlighting for most languages + Plug 'mattn/emmet-vim' + + Plug 'udalov/kotlin-vim' + + Plug 'purescript-contrib/purescript-vim' + + Plug 'HerringtonDarkholme/yats.vim' " typescript syntax highlighting + Plug 'mxw/vim-jsx' + + "" Haskell + Plug 'neovimhaskell/haskell-vim' + Plug 'Twinside/vim-hoogle', {'on': 'Hoogle'} + + " Rust + Plug 'rust-lang/rust.vim' + Plug 'mattn/webapi-vim' + + + + Plug 'neoclide/coc.nvim', {'branch': 'release'} + " }}} +call plug#end() diff --git a/whichkeyConfig.vim b/whichkeyConfig.vim new file mode 100644 index 0000000..2a13139 --- /dev/null +++ b/whichkeyConfig.vim @@ -0,0 +1,86 @@ +nnoremap :WhichKey '' +vnoremap :'WhichKeyVisual '' +let g:which_key_map = {} +call which_key#register('', "g:which_key_map") + +let g:which_key_map = { + \ 'h' : 'which_key_ignore', 'l' : 'which_key_ignore', + \ 'f' : 'which_key_ignore', 's': 'which_key_ignore' , + \ 'c' : { 'name': '+comment_out' }, + \ 'e' : { 'name': '+emmet' }, + \ 'z' : { 'name': '+folds', 'c': ['foldclose', 'close fold'], + \ 'o': ['foldopen', 'open fold'] , + \ } + \ } + + +" Maps for code actions +let g:which_key_map['m'] = { + \ 'name' : '+Code-actions' , + \ 'd' : [ ':call Show_documentation()' , 'show documentation' ] , + \ 's' : [ ':CocList -I symbols' , 'list symbols' ] , + \ 'o' : [ ':CocList outline' , 'show outline' ] , + \ 'c' : [ ':CocList commands' , 'show all coc-commands' ] , + \ 'g' : [ '(coc-definition)' , 'go to definition' ] , + \ 't' : [ '(coc-type-definition)' , 'show type definition' ] , + \ 'i' : [ '(coc-implementation)' , 'show implementation' ] , + \ 'r' : [ '(coc-references)' , 'show references' ] , + \ 'n' : [ '(coc-rename)' , 'rename' ] , + \ 'F' : [ '(coc-format-selected)' , 'format selection' ] , + \ 'f' : [ '(coc-format)' , 'format file' ] , + \ 'v' : [ '(coc-codeaction)' , 'apply codeaction' ] , + \ 'V' : [ '(coc-fix-current)' , 'apply quickfix' ] , + \ 'e' : [ ':CocList diagnostics' , 'list all errors' ] , + \ 'L' : [ '(coc-diagnostics-next)' , 'go to next error' ] , + \ 'H' : [ '(coc-diagnostics-prev)' , 'go to prev error' ] , + \} + + +let g:which_key_map['a'] = { + \ 'name': '+Bookmarks', + \ ' ' : ['(coc-bookmark-toggle)' , 'toggle bookmark' ] , + \ 'a' : ['(coc-bookmark-annotate)' , 'annotate bookmark' ] , + \ 'j' : ['(coc-bookmark-next)' , 'next bookmark' ] , + \ 'k' : ['(coc-bookmark-prev)' , 'prev bookmark' ] , + \ 'l' : [':CocList bookmark' , 'list bookmarks' ] , + \ 'c' : [':CocCommand bookmark.clearForCurrentFile' , 'clear for current file' ] , + \ 'C' : [':CocCommand bookmark.clearForAllFiles' , 'clear for all files' ] + \} + +" mappings for view and layout +let g:which_key_map['v'] = { + \ 'name' : '+view-and-layout', + \ 'n' : [':set relativenumber!' , 'toggle relative numbers' ] , + \ 'm' : [':set nonumber! norelativenumber' , 'toggle numbers'] , + \ 'g' : [':Goyo | set linebreak' , 'toggle focus mode' ] , + \ 'i' : [':IndentGuidesToggle' , 'toggle indent guides' ] , + \ } + +let g:which_key_map['b'] = { + \ 'name': '+buffers' , + \ 'o' : ['Buffers' , 'select open buffer' ] , + \ 'c' : [':bdelete!' , 'close open buffer' ] , + \ 'w' : [':bwipeout!' , 'wipeout open buffer' ] , + \ } + +let g:which_key_map['x'] = { + \ 'name' : '+other', + \ 'f' : ['NERDTreeToggle' , ' show file tree'], + \ 'p' : ['FZF' , ' search file (c-v/c-x to open in split)' ] , + \ 'h' : [':History:' , 'search command history'], + \ 'c' : [':Commands' , 'search through commands'], + \ 's' : ['OverCommandLine', 'Substitute with preview'], + \ 'y' : [':CocList -A --normal yank', 'Show yank history'] + \ } + +" CocList -A --normal yank needs :CocInstall coc-yank + + + +"nnoremap m :WhichKey 'm' + autocmd! VimEnter * :unmap ig + autocmd! FileType which_key + autocmd! FileType which_key set laststatus=0 noshowmode noruler + \| autocmd! BufLeave set laststatus=2 showmode ruler +set timeoutlen=200 +