Ver Fonte

Use vim-lsp for completion and ALE solely for linting and fixing

Viktor Grahn há 3 anos atrás
pai
commit
85367f7515
1 ficheiros alterados com 117 adições e 86 exclusões
  1. 117 86
      .vimrc

+ 117 - 86
.vimrc

@@ -1,5 +1,3 @@
-" Run the following git commands to get the plugins
-
 " Plugin manager
 if empty(glob('~/.vim/autoload/plug.vim'))
   silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
@@ -7,11 +5,6 @@ if empty(glob('~/.vim/autoload/plug.vim'))
   autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
 endif
 
-" Pre-plugin calls
-let g:ale_completion_enabled = 1
-let g:ale_hover_to_floating_preview = 1
-let g:ale_floating_preview = 1
-
 " Plugins
 call plug#begin('~/.vim/plugged')
 Plug 'preservim/nerdtree'
@@ -30,6 +23,8 @@ Plug 'junegunn/fzf.vim'
 Plug 'airblade/vim-gitgutter'
 Plug 'mxw/vim-jsx'
 Plug 'pangloss/vim-javascript'
+Plug 'natebosch/vim-lsc'
+Plug 'tpope/vim-surround'
 call plug#end()
 		
 filetype plugin indent on
@@ -38,7 +33,7 @@ syntax on
 set autoindent
 set backspace=2
 set background=dark
-set completeopt=menu,popup
+set completeopt=menu,popup,noselect
 set cursorcolumn
 set cursorline
 set expandtab
@@ -59,101 +54,81 @@ set showmatch
 set smartindent
 set smarttab
 set splitright
+set switchbuf+=usetab,newtab
 set termguicolors
 set tabstop=2
 set whichwrap+=<,>,[,],h,l 
 set undofile
 set undodir=~/.vim/undo
 
-" ALE
-" ALE linters
-let g:ale_use_global_executables = 1
-let g:ale_linters_explicit = 1
-let g:ale_linters = {}
-let g:ale_linters.javascript = [ 'eslint', 'tsserver' ]
-let g:ale_linters.php = [ 'intelephense', 'phpcs' ]
-
-let g:ale_phpcs_standard = "PSR2"
-
-" ALE fixers
-let g:ale_fixers = {}
-let g:ale_fixers.javascript  = [ 'prettier', 'eslint' ]
-
-" ALE completion
-let g:ale_completion_autoimport = 1
-set omnifunc=ale#completion#OmniFunc
-
-" ALE messages
-let g:ale_echo_msg_error_str = 'E'
-let g:ale_echo_msg_warning_str = 'W'
-let g:ale_echo_msg_format = '[%linter%] %s'
-
-" Ale keymaps
-nnoremap <C-a>g :ALEGoToDefinition -tab<CR>
-nnoremap <C-a>G :ALEGoToDefinition<CR>
-nnoremap <C-a>h :ALEHover<CR>
-nnoremap <C-a>f :ALEFindReferences<CR>
-
-" ALE navigation
-nmap <silent> <C-k> <Plug>(ale_previous_wrap)
-nmap <silent> <C-j> <Plug>(ale_next_wrap)
-let g:material_theme_style = 'darker'
-let g:material_terminal_italics = 1
-colorscheme material
+" Colorscheme
+colorscheme minimalist
+highlight Comment cterm=italic
 
 " Lightline
 set laststatus=2 
 set noshowmode
 let g:lightline = {
-  \ 'colorscheme': 'material_vim',
-  \ 'separator': { 'left': '', 'right': '' },
+  \ 'colorscheme': 'minimalist',
+  \ 'tabline_subseparator': { 'left': '', 'right': '' },
   \ 'active': {
   \   'left': [
   \     [ 'mode', 'paste' ],
-  \     [ 'gitbranch', 'readonly', 'filename', 'tagbar', 'modified' ]
+  \     [ 'filestate' ],
+  \     [ 'gitbranch', 'tagbar' ],
   \   ],
   \   'right': [ 
-  \     [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ], 
-  \     [ 'percent', 'lineinfo', 'offset' ], 
-  \     [ 'fileformat', 'fileencoding', 'filetype' ]
+  \     [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
+  \     [ 'fileformat', 'fileencoding', 'filetype', 'percent', 'lineinfo', 'offset' ], 
   \   ]
   \ },
+  \ 'tabline': {
+  \ 	'left': [ [ 'tabs' ] ],
+  \   'right': [ ],
+  \ },
   \ 'component': {
   \   'tagbar': '%{tagbar#currenttag("%s", "", "f", "nearest-stl")}',
   \ },
   \ 'component_function': {
-  \   'gitbranch': 'FugitiveHead',
-  \   'offset': 'FileOffset'
+  \   'filestate': 'LightlineFileState',
+  \   'offset': 'LightlineFileOffset',
   \ },
   \ 'component_expand': {
+  \   'gitbranch': 'FugitiveHead',
   \   'linter_checking': 'lightline#ale#checking',
   \   'linter_infos': 'lightline#ale#infos',
   \   'linter_warnings': 'lightline#ale#warnings',
   \   'linter_errors': 'lightline#ale#errors',
-  \   'linter_ok': 'lightline#ale#ok'
+  \   'linter_ok': 'lightline#ale#ok',
   \ },
   \ 'component_type': {
-  \   'linter_checking': 'right',
-  \   'linter_infos': 'right',
   \   'linter_warnings': 'warning',
   \   'linter_errors': 'error',
-  \   'linter_ok': 'right'
+  \   'linter_ok': 'ok',
+  \   'linter_infos': 'info',
   \ }
 \ }
 
-function! FileOffset()
+" Lightline helper (concatenate readonly state, filename and modified state)
+function! LightlineFileState()
+  if @% == "" | return "[No name]" | endif
+  let s = expand('%:t')
+  if &modified | let s = s . "+" | endif
+  if &readonly | let s = "[RO] " . s | endif
+  return s
+endfunction
+
+" Lightline helper (get cursor line and character position in file)
+function! LightlineFileOffset()
     return line2byte(line('.')) + col('.') - 1
 endfunction
 
 " NERDtree
-" Close NERDTree on opening file
 let NERDTreeQuitOnOpen=1
-" Show hidden files
 let NERDTreeShowHidden=1
 
+" NERDTree helper (toggle in current buffer)
 function! NERDTreeToggleCustom()
-
-  " If NERDTree is open in the current buffer
   if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
     exe ":NERDTreeClose"
   elseif bufname('%') != ""
@@ -161,16 +136,52 @@ function! NERDTreeToggleCustom()
   else
     exe ":NERDTreeCWD"
   endif
-
 endfunction
 
-" Toggle NERDTree on <space>-o
+" NERDTREE Toggle NERDTree on <space>-o
 map <Space>o :call NERDTreeToggleCustom()<CR>
 
+" ALE Configuration
+let g:ale_completion_enabled = 0
+let g:ale_sign_column_always = 1
+let g:ale_set_signs = 1
+let g:ale_set_highlights = 0
+let g:ale_disable_lsp = 1
+
+" ALE linters
+let g:ale_use_global_executables = 1
+let g:ale_linters_explicit = 1
+let g:ale_linters = {}
+let g:ale_linters.javascript = [ 'eslint' ]
+let g:ale_linters.php = [ 'intelephense', 'phpcs' ]
+let g:ale_linters.go = [ 'gopls', 'gofmt', 'gobuild' ]
+
+let g:ale_phpcs_standard = "PSR2"
+
+" ALE fixers
+let g:ale_fixers = { '*': [ 'remove_trailing_lines', 'trim_whitespace' ] }
+let g:ale_fixers.javascript  = [ 'prettier', 'eslint' ]
+let g:ale_fixers.go = [ 'gofmt' ]
+
+" ALE message should include responsible linter
+let g:ale_echo_msg_format = '[%linter%] %s'
+
+" Ale keymaps
+nnoremap <C-a>l :ALELint<CR>
+nnoremap <C-a>f :ALEFix<CR>
+nnoremap <C-a>i :ALEInfo<CR>
+
+" ALE styling
+highlight ALEErrorSign ctermbg=237 ctermfg=167
+highlight ALEWarningSign ctermbg=237 ctermfg=215
+highlight ALEInfoign ctermbg=237 ctermfg=117
+" ALE Configuration end
+
 " Tagbar
 let g:tagbar_autoclose = 1
 let g:tagbar_autofocus = 1
 let g:tagbar_map_showproto = ''
+nmap <Space>t :TagbarToggle<CR>
 
 " Toggle transparent background
 let g:is_transparent = 0
@@ -186,13 +197,13 @@ function! Toggle_transparent()
 endfunction
 nnoremap <Space>T :call Toggle_transparent()<CR>
 
-" Location list
-autocmd BufEnter * if !exists("b:location_list") | let b:location_list = 0 | endif
-let b:location_list = 0
+" Location list toggle
 function! Toggle_location_list()
-  if b:location_list == 0
-    lopen
-    let b:location_list = 1
+  if get(b:, 'location_list', 0) == 0
+    silent! lopen
+    if get(getloclist(0, { 'winid': 0 }), 'winid')
+      let b:location_list = 1
+    endif
   else
     lclose
     let b:location_list = 0
@@ -200,13 +211,13 @@ function! Toggle_location_list()
 endfunction
 nnoremap <Space>l :call Toggle_location_list()<CR>
 
-" Location list
-autocmd BufEnter * if !exists("b:quick_list") | let b:quick_list = 0 | endif
-let b:quick_list = 0
+" Quickfix list toggle
 function! Toggle_quick_list()
-  if b:quick_list == 0
-    copen
-    let b:quick_list = 1
+  if get(b:, 'quick_list', 0) == 0
+    silent! copen
+    if get(getqfist(0, { 'winid': 0 }), 'winid')
+      let b:quick_list = 1
+    endif
   else
     cclose
     let b:quick_list = 0
@@ -218,7 +229,7 @@ nnoremap <Space>c :call Toggle_quick_list()<CR>
 autocmd BufEnter * if !exists("b:git_blame") | let b:git_blame = 0 | endif
 function! Toggle_git_blame()
   if b:git_blame == 0
-    :Git blame
+    :silent! Git blame
     let b:git_blame = 1
   else
     let winIndex = 1
@@ -233,19 +244,14 @@ function! Toggle_git_blame()
     endwhile
     let b:git_blame = 0
   endif
-
 endfunction
 nnoremap <Space>b :call Toggle_git_blame()<CR>
 
-" Key mappings
-map <C-l>n :cnext<CR>
-map <C-l>p :cprevious<CR>
-nnoremap <C-l>c :cclose<CR>
-
-nmap <Space>t :TagbarToggle<CR>
+" Fuzzy search 
 nmap <Space>f :Files<CR>
-nmap <Space>r :Rg<CR>
+nmap <Space>s :Rg<CR>
 
+" Git gutter
 nmap <Space>n :GitGutterNextHunk<CR>
 nmap <Space>p :GitGutterPrevHunk<CR>
 
@@ -260,21 +266,46 @@ function UpdateTmuxWindow()
   call system("tmux rename-window '" . title . "'")
 endfunction
 
+" Format XML pretty
 function! PrettyXML()
   set filetype=xml
   silent %!xmllint --format --encode UTF-8 --recover - 2>/dev/null
 endfunction
 
+" Format json pretty
 function! PrettyJSON()
   set filetype=json
   silent %!python3 -m json.tool
 endfunction
 
-command! PrettyXml call PrettyXML()
-command! PrettyJson call PrettyJSON()
-
 nmap <Space>x :call PrettyXML()<CR>
 nmap <Space>j :call PrettyJSON()<CR>
 
 " Disable bad default keybindings
 inoremap <C-w> <Nop>
+
+" LSP configuration
+let g:lsc_enable_diagnostics = v:false
+let g:lsc_auto_map = v:true
+let g:lsc_autocomplete_length=1
+set omnifunc=lsc#complete#complete
+
+" LSP keymappings
+nnoremap <C-l>f :LSClientFindReferences<CR>
+nnoremap <C-l>g :tab LSClientGoToDefinitionSplit<CR>
+nnoremap <C-l>G :LSClientGoToDefinition<CR>
+nnoremap <C-l>h :LSClientShowHover<CR>
+
+" LSP servers
+let g:lsc_server_commands = {}
+let g:lsc_server_commands = {
+ \  'javascript':     { 'command': 'typescript-language-server --stdio', 'log_level': -1, 'suppress_stderr': v:true },
+ \  'javascript.jsx': { 'command': 'typescript-language-server --stdio', 'log_level': -1, 'suppress_stderr': v:true },
+ \  'go':             { 'command': 'gopls serve', 'log_level': -1, 'suppress_stderr': v:true },
+ \  'php':            { 'command': 'intelephense --stdio', 'message_hooks': {'initialize': { 'initializationOptions': {'storagePath': '/tmp/intelephense'} } } },
+ \}
+
+" LSP close preview after selecting completion
+autocmd CompleteDone * silent! pclose
+" LSP close quickfix list after selection
+autocmd BufLeave * cclose