Last active
March 2, 2025 18:45
-
-
Save sigzegv/d2e39e51e23c8b25817aa56c0c1c8c8d to your computer and use it in GitHub Desktop.
vimrc for vim9+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim9script | |
# https://vimhelp.org/vim9.txt.html | |
set nocompatible | |
if has("mac") | |
set clipboard=unnamed | |
else | |
set clipboard=unnamedplus # requires vim-gui-common | |
endif | |
set directory=/tmp | |
set nobackup | |
set mouse=a | |
set nowritebackup | |
set sessionoptions-=options | |
set hidden | |
set showcmd | |
set pumheight=15 | |
set wildmenu | |
set wildoptions=pum,fuzzy | |
set colorcolumn=80 | |
set nocursorline | |
set display=truncate | |
set encoding=utf-8 | |
set fileencoding=utf-8 | |
set fillchars=stl:\ ,stlnc:\ ,vert:\|,fold:-,diff:-,eob:\ | |
set helplang=fr | |
set history=2048 | |
set hlsearch | |
set incsearch | |
set langnoremap | |
set laststatus=2 | |
set nolangremap | |
set nomodeline | |
set nrformats=bin,hex | |
set number | |
set omnifunc=syntaxcomplete#Complete | |
set printoptions=paper:a4 | |
set ruler | |
set scrolloff=2 | |
set sidescroll=1 | |
set sidescrolloff=2 | |
set ttimeout | |
set ttimeoutlen=100 | |
set ttymouse=sgr | |
set viewoptions-=options | |
set viminfo^=! | |
set nowrap | |
set splitbelow | |
set splitright | |
set smartindent | |
set autoindent | |
set expandtab | |
set shiftwidth=4 | |
set softtabstop=4 | |
set tabstop=4 | |
set smarttab | |
filetype on | |
filetype plugin on | |
filetype indent on | |
syntax on | |
runtime! macros/matchit.vim | |
runtime! ftplugin/man.vim | |
set backspace=indent,eol,start | |
g:mapleader = 'ù' | |
tnoremap <C-i> <C-\><C-n> | |
nnoremap <leader>: :20Lex<CR> | |
nnoremap <leader>p :register<cr> | |
## custom shortcuts | |
# delete without copying | |
nnoremap x "_x | |
nnoremap X "_X | |
# new lines | |
# nnoremap <cr> o<esc> | |
nnoremap <leader><cr> O<esc> | |
# pane switch | |
nmap <silent> <C-down> :wincmd w<cr> | |
# tab movements | |
nnoremap <tab> >>_ | |
nnoremap <S-tab> <<_ | |
inoremap <S-tab> <c-d> | |
vnoremap <tab> >gv | |
vnoremap <S-tab> <gv | |
inoremap <expr> <tab> pumvisible() ? "\<c-n>" : "\<Tab>" | |
inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<c-d>" | |
inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<cr>" | |
# quick save without going back to normal mode | |
inoremap <silent> :w <esc>:w<cr> | |
# unhighlight | |
nmap <silent> µ :nohlsearch<cr> | |
# leave insert mode alternate | |
inoremap ii <esc> | |
nnoremap <pageup> <c-u> | |
nnoremap <pagedown> <c-d> | |
# https://www.reddit.com/r/vim/comments/1er93oq/cursor_in_vim/ | |
# Todo convert to vim9script | |
&t_SI = "\<Esc>[5 q" | |
&t_SR = "\<Esc>[4 q" | |
&t_EI = "\<Esc>[2 q" | |
## kinds icons for LSPs | |
g:Kinds = { | |
"Class": " ", | |
"Color": " ", | |
"Constant": " ", | |
"Constructor": " ", | |
"Enum": " ", | |
"EnumMember": " ", | |
"Event": "", | |
"Field": " ", | |
"File": " ", | |
"Folder": " ", | |
"Function": " ", | |
"Interface": " ", | |
"Keyword": " ", | |
"Method": "ƒ ", | |
"Module": "", | |
"Operator": "", | |
"Property": " ", | |
"Snippet": " ", | |
"Reference": " ", | |
"Struct": " ", | |
"Text": " ", | |
"TypeParameter": " ", | |
"Unit": " ", | |
"Value": " ", | |
"Variable": " " | |
} | |
g:polyglot_disabled = ['autoindent'] | |
plug#begin() | |
Plug 'sainnhe/gruvbox-material' | |
Plug 'tpope/vim-sleuth' | |
Plug 'sheerun/vim-polyglot' | |
Plug 'moll/vim-bbye' | |
Plug 'jlanzarotta/bufexplorer' | |
Plug 't9md/vim-quickhl' | |
Plug 'vim-scripts/argtextobj.vim' | |
Plug 'romainl/vim-qf' | |
Plug 'MarcWeber/vim-addon-qf-layout' | |
Plug 'tmsvg/pear-tree' | |
Plug 'tpope/vim-vinegar' | |
Plug 'tpope/vim-commentary' | |
Plug 'tpope/vim-surround' | |
Plug 'easymotion/vim-easymotion' | |
Plug 'lervag/wiki.vim' | |
Plug 'kshenoy/vim-signature' | |
Plug 'prabirshrestha/vim-lsp' | |
Plug 'mattn/vim-lsp-settings' | |
Plug 'prabirshrestha/asyncomplete.vim' | |
Plug 'prabirshrestha/asyncomplete-lsp.vim' | |
Plug 'prabirshrestha/asyncomplete-file.vim' | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' | |
plug#end() | |
# list loaded plugins: :echo keys(g:plugs) | |
legacy if exists(':PlugInstall') | |
command! PI so ~/.vim/vimrc | PlugInstall | |
endif | |
legacy if exists(':PlugUpdate') | |
command! PU so ~/.vim/vimrc | PlugUpdate | |
endif | |
legacy if exists(':PlugClean') | |
command! PC so ~/.vim/vimrc | PlugClean | |
endif | |
def PlugList() | |
echo keys(g:plugs) | |
enddef | |
command! -bang PlugList PlugList() | |
def IsPluginLoaded(p: string): bool | |
return len(filter(keys(g:plugs), 'v:val == "' .. p .. '"')) > 0 | |
enddef | |
def g:SyntaxInfo() | |
var l = line(".") | |
var c = col(".") | |
var id = synID(l, c, 1) | |
var name = synIDattr(id, "name") | |
var idt = synID(l, c, 0) | |
var namet = synIDattr(idt, "name") | |
var id2 = synIDtrans(id) | |
var name2 = synIDattr(id2, "name") | |
echom "Syn [" .. name .. " " .. namet .. " " .. name2 .. "]" | |
enddef | |
command! -bang SyntaxInfo g:SyntaxInfo() | |
def YankCursorPositionInfo() | |
@* = expand('%') .. ":" .. line('.') | |
enddef | |
command! -bang YankCursorPositionInfo YankCursorPositionInfo() | |
nnoremap yp :YankCursorPositionInfo<CR> | |
def YankCursorLineInfo() | |
@* = expand('%') .. ":" .. line('.') .. ": " .. getline('.') | |
enddef | |
command! -bang YankCursorLineInfo YankCursorLineInfo() | |
nnoremap yl :YankCursorLineInfo<CR> | |
def GitBlame() | |
var l = line('.') | |
var output = system(printf("git blame -L %d,%d %s", l, l, expand('%'))) | |
echom output | |
enddef | |
command! -bang GitBlame GitBlame() | |
## https://github.com/sainnhe/gruvbox-material | |
if IsPluginLoaded("gruvbox-material") | |
g:gruvbox_material_background = 'medium' | |
g:gruvbox_material_better_performance = 1 | |
g:gruvbox_material_disable_italic_comment = 1 | |
g:gruvbox_material_transparent_background = 1 | |
augroup GruvboxMaterialCustom | |
autocmd! | |
autocmd ColorScheme gruvbox-material { | |
highlight! CursorLine guibg=#202020 | |
highlight! Visual guibg=#101010 | |
highlight! StatusLine guifg=#87ff87 guibg=#161b1c | |
highlight! StatusLineNc guifg=#228855 guibg=#161b1c | |
highlight! User1 guifg=#d7af87 guibg=#161b1c | |
highlight! User2 guifg=#87ff87 guibg=#161b1c | |
highlight! User3 guifg=#ffaf00 guibg=#161b1c | |
highlight! User4 guifg=#808080 guibg=#161b1c | |
highlight! User5 guifg=#ff0000 guibg=#161b1c | |
highlight! LspErrorText gui=NONE guifg=#FF3333 | |
highlight! LspWarningText gui=NONE guifg=#FFBB00 | |
highlight! LspHintText gui=NONE guifg=#00CCFF | |
highlight! LspInformationText gui=NONE guifg=#CCFFCC | |
highlight! ScopeMenuMatch gui=NONE guifg=LimeGreen | |
highlight! ScopeMenuVirtualText gui=NONE guifg=#FF0000 | |
# highlight! ScopeMenuSubtle gui=NONE guifg=NONE | |
} | |
augroup END | |
augroup goSyntax | |
autocmd! | |
autocmd BufReadPost,BufNewFile *.go { | |
hi! goBuiltins gui=NONE guifg=#d25d5d | |
hi! goType gui=NONE guifg=#d7875f | |
hi! goParen guifg=#FFAA00 | |
syn match goParen /[({})]/ | |
} | |
augroup END | |
set background=dark | |
set termguicolors | |
colorscheme gruvbox-material | |
endif | |
## https://github.com/moll/vim-bbye | |
if IsPluginLoaded("vim-bbye") | |
nnoremap <silent> <leader>x :Bdelete!<cr> | |
endif | |
## https://github.com/jlanzarotta/bufexplorer | |
if IsPluginLoaded("bufexplorer") | |
g:bufExplorerDefaultHelp = 0 | |
g:bufExplorerDisableDefaultKeyMapping = 1 | |
g:bufExplorerShowDirectories = 1 | |
g:bufExplorerSplitOutPathName = 0 | |
g:bufExplorerShowRelativePath = 1 | |
nnoremap <silent> <leader>! :ToggleBufExplorer<CR> | |
endif | |
## https://github.com/t9md/vim-quickhl | |
if IsPluginLoaded("vim-quickhl") | |
nnoremap <silent> * <Plug>(quickhl-manual-this-whole-word) | |
nnoremap <silent> g* <Plug>(quickhl-manual-this) | |
xnoremap <silent> g* <Plug>(quickhl-manual-this) | |
nnoremap <silent> µ <Plug>(quickhl-manual-reset):nohlsearch<Bar>:echo<cr> | |
nnoremap <silent> <S-µ> <Plug>(quickhl-manual-reset):nohlsearch<Bar>:echo<cr> | |
nnoremap <silent> n <Plug>(quickhl-manual-go-to-next) | |
nnoremap <silent> <S-n> <Plug>(quickhl-manual-go-to-prev) | |
endif | |
## https://github.com/romainl/vim-qf | |
if IsPluginLoaded("vim-qf") | |
g:qf_auto_open_quickfix = 0 | |
g:qf_auto_open_loclist = 0 | |
g:qf_mapping_ack_style = 1 | |
g:qf_max_height = 15 | |
g:qf_auto_resize = 1 | |
g:qf_shorten_path = 3 | |
nmap ,l <Plug>(qf_loc_next) | |
nmap ,, <Plug>(qf_qf_switch) | |
endif | |
## https://github.com/MarcWeber/vim-addon-qf-layout | |
if IsPluginLoaded("vim-addon-qf-layout") | |
g:vim_addon_qf_layout = {} | |
g:vim_addon_qf_layout.quickfix_formatters = [ | |
'vim_addon_qf_layout#DefaultFormatter', | |
'vim_addon_qf_layout#FormatterNoFilename', | |
'vim_addon_qf_layout#Reset', | |
] | |
endif | |
### https://github.com/vim-scripts/argtextobj.vim | |
# if IsPluginLoaded("argtextobj.vim") | |
# endif | |
## https://github.com/tmsvg/pear-tree | |
if IsPluginLoaded("pear-tree") | |
g:pear_tree_repeatable_expand = 0 | |
g:pear_tree_smart_openers = 1 | |
g:pear_tree_smart_closers = 1 | |
g:pear_tree_smart_backspace = 1 | |
endif | |
### https://github.com/tpope/vim-vinegar | |
# alternative lambdalisue/vim-fern | |
# if IsPluginLoaded("tpope/vim-vinegar") | |
# endif | |
### https://github.com/tpope/vim-commentary | |
# if IsPluginLoaded("vim-commentary") | |
# endif | |
### https://github.com/tpope/vim-surround | |
# todo: check https://github.com/machakann/vim-sandwich | |
# if IsPluginLoaded("vim-surround") | |
# endif | |
## https://github.com/sheerun/vim-polyglot | |
# if IsPluginLoaded("vim-polyglot") | |
# g:polyglot_disabled = ['autoindent'] | |
# endif | |
## https://github.com/easymotion/vim-easymotion | |
if IsPluginLoaded("vim-easymotion") | |
nmap s <Plug>(easymotion-overwin-f2) | |
nmap <Leader>l <Plug>(easymotion-overwin-line) | |
nmap <Leader>w <Plug>(easymotion-bd-w) | |
endif | |
## https://github.com/sebdah/vim-delve | |
if IsPluginLoaded("vim-delve") | |
nmap <leader>b :DlvToggleBreakpoint<CR> | |
endif | |
## https://github.com/junegunn/fzf.vim | |
## had to build the vim plugged fzf to have correct binary version | |
## !rg --column --line-number --no-heading --color=always --smart-case ./* LspCodeAction | |
if IsPluginLoaded("fzf.vim") | |
g:fzf_vim = { | |
preview_window: [], | |
} | |
$FZF_DEFAULT_OPTS = '--reverse' | |
if !exists('*FzfLspDiagnostics') | |
def FzfLspDiagnostics() | |
if !exists('*LspSendRequest') | |
echo "FzfLspDiagnostic error: LspSendRequest: function missing" | |
return | |
endif | |
var items = LspDiagnostics((d) => { | |
return FormatDiagnostic(d) | |
}) | |
if len(items) == 0 | |
echo "No diagnostics found" | |
return | |
endif | |
fzf#run(fzf#wrap({ | |
source: items, | |
sink: (m) => { | |
var parts = split(m, ':') | |
execute "e " .. fnameescape(parts[0]) | |
cursor(str2nr(parts[1]), str2nr(parts[2])) | |
}, | |
#down: len(items) + 3, | |
options: [ | |
'--ansi', | |
'--prompt', 'Diagnostics> ', | |
'--delimiter', ':', | |
# '--preview', 'batcat -p --color=always {1}', | |
# '--preview-window', '+{2}-/2', | |
] | |
})) | |
enddef | |
command! -bang Diagnostics FzfLspDiagnostics() | |
nmap <silent> gz :Diagnostics<CR> | |
endif | |
if !exists('FzfLspReferences') | |
def FzfLspReferences() | |
if !exists('*LspSendRequest') | |
echo "FzfLspReferences error: LspSendRequest: function missing" | |
return | |
endif | |
def PopupSel(ctx: dict<any>, server: string, operation: string, data: any) | |
echo "Retrieving references..." | |
if has_key(data['response'], 'error') | |
echo "No references found: " .. data['response']['error']['message'] | |
return | |
endif | |
var items = [] | |
for r in data["response"]["result"] | |
var filename = lsp#utils#uri_to_path(r["uri"]) | |
var ftxt = readfile(filename) | |
var msg = trim(ftxt[r["range"]["start"]["line"]]) | |
add(items, printf( | |
"\e[32m%s\e[0m:\e[35m%s\e[0m:\e[34m%s\e[0m %s", | |
substitute(filename, getcwd() .. "/", "", ""), | |
r["range"]["start"]["line"] + 1, | |
r["range"]["start"]["character"], | |
msg | |
)) | |
endfor | |
if empty(items) | |
echo "No references found." | |
return | |
endif | |
fzf#run(fzf#wrap({ | |
source: items, | |
sink: (m) => { | |
var parts = split(m, ':') | |
execute "e " .. fnameescape(parts[0]) | |
cursor(str2nr(parts[1]), str2nr(parts[2])) | |
}, | |
#down: len(items) + 3, | |
options: [ | |
'--ansi', | |
'--prompt', 'References> ', | |
'--delimiter', ':', | |
] | |
})) | |
enddef # LspSendRequest | |
LspSendRequest('references', PopupSel) | |
enddef # FzfLspReferences | |
command! -bang References FzfLspReferences() | |
nmap <silent> gr :References<CR> | |
endif | |
if !exists('FzfLspImplementations') | |
def FzfLspImplementations() | |
def PopupSel(ctx: dict<any>, server: string, operation: string, data: any) | |
echo "Retrieving implementations..." | |
if has_key(data['response'], 'error') | |
echo "No implementations found: " .. data['response']['error']['message'] | |
return | |
endif | |
var items = [] | |
for r in data["response"]["result"] | |
var filename = lsp#utils#uri_to_path(r["uri"]) | |
var ftxt = readfile(filename) | |
var msg = trim(ftxt[r["range"]["start"]["line"]]) | |
add(items, printf( | |
"\e[32m%s\e[0m:\e[35m%s\e[0m:\e[34m%s\e[0m %s", | |
substitute(filename, getcwd() .. "/", "", ""), | |
r['range']['start']['line'] + 1, | |
r['range']['start']['character'], | |
msg, | |
)) | |
endfor | |
if len(items) == 0 | |
echo "No implementations found" | |
return | |
endif | |
fzf#run(fzf#wrap({ | |
source: items, | |
sink: (m) => { | |
var parts = split(m, ':') | |
cursor(str2nr(parts[1]), 1) | |
}, | |
options: [ | |
'--ansi', | |
'--reverse', | |
'--prompt', 'Implementations> ', | |
] | |
})) | |
enddef | |
LspSendRequest('implementation', PopupSel) | |
enddef | |
command! -bang Implementations FzfLspImplementations() | |
nmap <silent> gR :Implementations<CR> | |
endif | |
g:vimlspkinds = { | |
13: 'variable', | |
14: 'const', | |
} | |
if !exists('FzfLspDocumentSymbols') | |
def FzfLspDocumentSymbols() | |
def PopupSel(ctx: dict<any>, server: string, operation: string, data: any) | |
var items = [] | |
for r in data["response"]["result"] | |
add(items, printf( | |
"\e[35m%s\e[0m\t%-50s \e[33m%s\e[0m", | |
r['range']['start']['line'] + 1, | |
r['name'], | |
has_key(r, 'detail') ? r['detail'] : g:vimlspkinds[r['kind']] | |
)) | |
if has_key(r, 'children') | |
for r2 in r['children'] | |
var cname = printf(" %s.%s", r['name'], r2['name']) | |
add(items, printf( | |
"\e[35m%s\e[0m\t%-50s \e[33m%s\e[0m", | |
r2['range']['start']['line'] + 1, | |
cname, | |
has_key(r2, 'detail') ? r2['detail'] : g:vimlspkinds[r['kind']] | |
)) | |
endfor | |
endif | |
endfor | |
if len(items) == 0 | |
echo "No symbols found" | |
return | |
endif | |
fzf#run(fzf#wrap({ | |
source: items, | |
sink: (m) => { | |
var parts = split(m, ':') | |
cursor(str2nr(parts[0]), 0) | |
}, | |
down: 10, | |
options: [ | |
'--ansi', | |
'--reverse', | |
'--prompt', 'DocumentSymbols> ', | |
'--delimiter', ':', | |
] | |
})) | |
enddef | |
LspSendRequest('documentSymbol', PopupSel) | |
enddef | |
command! -bang DocumentSymbols FzfLspDocumentSymbols() | |
nmap <silent> gs :DocumentSymbols<CR> | |
endif | |
def PrepareCalls(ctx: dict<any>, server: string, operation: string, data: any) | |
def PopupSel(sctx: dict<any>, s: string, soperation: string, sdata: any) | |
if has_key(sdata['response'], 'error') && sdata['response']['error']['code'] != 0 | |
echom "ERR: " .. sdata['response']['error']['message'] | |
return | |
endif | |
var items = [] | |
for r in sdata["response"]["result"] | |
add(items, sctx['rowformat'](r)) | |
endfor | |
if len(items) == 0 | |
echo "No " .. ctx["prompt"] .. " found" | |
return | |
endif | |
fzf#run(fzf#wrap({ | |
source: items, | |
sink: (m) => { | |
var fp = split(m, ']') | |
var parts = split(fp[1], ':') | |
execute "e " .. fnameescape(trim(parts[0])) | |
cursor(str2nr(parts[1]) + 1, 1) | |
}, | |
down: 10, | |
options: [ | |
'--ansi', | |
'--reverse', | |
'--prompt', ctx["prompt"] .. " > ", | |
] | |
})) | |
enddef | |
if data['response']['result'] == null | |
echom "No calls found for method " .. ctx['method'] | |
return | |
endif | |
var capabilities_func = printf('lsp#capabilities#has_call_hierarchy_provider(v:val)') | |
var servers = filter(lsp#get_allowed_servers(), capabilities_func) | |
if len(servers) == 0 | |
echo printf('WARN: LSP: call_hierarchy for outgoing call is not supported') | |
return | |
endif | |
var method = "callHierarchy/" .. ctx['method'] | |
var subctx = ctx | |
var params = { 'item': data['response']['result'][0] } | |
for s in servers | |
lsp#send_request(s, { | |
'method': method, | |
'params': params, | |
'on_notification': function(PopupSel, [subctx, s, method]), | |
}) | |
endfor | |
enddef | |
if !exists('FzfLspOutgoingCalls') | |
def FzfLspOutgoingCalls() | |
LspSendRequest('prepareCallHierarchy', PrepareCalls, { | |
ctx: { | |
method: "outgoingCalls", | |
prompt: "outgoing calls", | |
rowformat: (r) => { | |
var filename = lsp#utils#uri_to_path(r["to"]["uri"]) | |
return printf("\e[35m%-4d\e[0m %-20s \e[33m[%s] \e[32m%s:%d\e[0m", | |
r['fromRanges'][0]["start"]["line"], | |
r['to']['name'], | |
r['to']['detail'], | |
filename, | |
r["to"]["range"]["start"]["line"], | |
) | |
}, | |
} | |
}) | |
enddef | |
command! -bang OutgoingCalls FzfLspOutgoingCalls() | |
nmap <silent> go :OutgoingCalls<CR> | |
endif | |
if !exists('FzfLspIncomingCalls') | |
def FzfLspIncomingCalls() | |
LspSendRequest('prepareCallHierarchy', PrepareCalls, { | |
ctx: { | |
method: "incomingCalls", | |
prompt: "incoming calls", | |
rowformat: (r) => { | |
var filename = lsp#utils#uri_to_path(r["from"]["uri"]) | |
return printf("\e[35m%-4d\e[0m %-20s \e[33m[%s] \e[32m%s:%d\e[0m", | |
r['fromRanges'][0]["start"]["line"], | |
r['from']['name'], | |
r['from']['detail'], | |
filename, | |
r["from"]["range"]["start"]["line"], | |
) | |
}, | |
} | |
}) | |
enddef | |
command! -bang IncomingCalls FzfLspIncomingCalls() | |
nmap <silent> gi :IncomingCalls<CR> | |
endif | |
nmap <leader>! :Buffers<cr> | |
nmap <leader>: :Files<cr> | |
nmap <leader>; :GFiles<cr> | |
nmap <leader>c :BCommits<cr> | |
nmap <leader>m :Marks<cr> | |
nmap <leader>j :Jumps<cr> | |
nmap <leader>* :Rg <c-r><c-w><cr> | |
endif | |
## https://github.com/prabirshrestha/vim-lsp | |
## https://github.com/mattn/vim-lsp-settings | |
## https://github.com/prabirshrestha/asyncomplete.vim | |
## https://github.com/prabirshrestha/asyncomplete-lsp.vim | |
## completion alternative : 'girishji/vimcomplete' | |
if IsPluginLoaded("vim-lsp") | |
g:lsp_peek_alignment = 'top' | |
g:lsp_document_code_action_signs_enabled = 0 | |
g:lsp_document_highlight_enabled = 0 | |
g:lsp_diagnostics_echo_cursor = 0 | |
g:lsp_diagnostics_echo_delay = 200 | |
g:lsp_diagnostics_float_cursor = 0 | |
g:lsp_diagnostics_float_delay = 400 | |
g:lsp_diagnostics_virtual_text_enabled = 0 | |
g:lsp_diagnostics_virtual_text_prefix = "## " | |
g:lsp_diagnostics_virtual_text_align = "right" | |
g:lsp_diagnostics_highlights_enabled = 1 | |
g:lsp_diagnostics_signs_error = { 'text': "" } | |
g:lsp_diagnostics_signs_warning = { 'text': "" } | |
g:lsp_diagnostics_signs_information = { 'text': "" } | |
g:lsp_diagnostics_signs_hint = { 'text': "" } | |
g:lsp_preview_max_height = 15 | |
g:lsp_settings_servers_dir = "~/.vim/lspservers" | |
g:lsp_settings_root_markers = [ | |
'.git', | |
'.git/', | |
'.svn', | |
'.hg', | |
'.bzr', | |
'go.mod', | |
] | |
g:lsp_settings = { | |
'vim-language-server': {'disabled': true}, | |
'rls': {'disabled': true}, | |
} | |
if IsPluginLoaded("asyncomplete-file.vim") | |
au User asyncomplete_setup asyncomplete#register_source(asyncomplete#sources#file#get_source_options({name: 'file', allowlist: ['*'], priority: 10, completor: function('asyncomplete#sources#file#completor')})) | |
endif | |
augroup lsp_install | |
autocmd! | |
autocmd User lsp_buffer_enabled { | |
setlocal omnifunc=lsp#complete | |
setlocal signcolumn=yes | |
nmap <buffer> ge <plug>(lsp-peek-definition) | |
nmap <buffer> gE <plug>(lsp-definition) | |
nmap <buffer> gf <plug>(lsp-peek-type-definition) | |
nmap <buffer> gF <plug>(lsp-type-definition) | |
nmap <buffer> gd <plug>(lsp-hover) | |
if IsPluginLoaded("vim-lspfuzzy") && IsPluginLoaded("fzf.vim") | |
nmap <buffer> gr :FzfLspReferences<CR> | |
endif | |
} | |
augroup END | |
augroup LspBufWriteFmt | |
autocmd! | |
autocmd BufWritePre *.go execute('LspDocumentFormatSync') | execute('LspCodeActionSync source.organizeImports') | |
augroup END | |
## manual tab completion | |
# g:asyncomplete_auto_popup = 0 | |
# g:asyncomplete_auto_completeopt = 0 | |
# def g:Check_back_space(): bool | |
# var col = col('.') - 1 | |
# return !col || getline('.')[col - 1] =~ '\s' | |
# enddef | |
# inoremap <silent><expr> <TAB> | |
# \ pumvisible() ? "\<C-n>" : | |
# \ g:Check_back_space() ? "\<TAB>" : | |
# \ asyncomplete#force_refresh() | |
#### LSP additions | |
# bulk lsp request function over vim-lsp | |
if !exists('*LspSendRequest') | |
def LspSendRequest(op: string, Callback: func(dict<any>, string, string, any), conf: dict<any> = {}) | |
var operations = { | |
'references': { | |
provider: 'references', | |
command: 'textDocument/references', | |
params: {context: {'includeDeclaration': v:true }}, | |
}, | |
'documentSymbol': { | |
provider: 'document_symbol', | |
command: 'textDocument/documentSymbol', | |
}, | |
'diagnostic': { | |
provider: 'diagnostic', | |
command: 'textDocument/diagnostic', | |
}, | |
'publishDiagnostics': { | |
provider: 'publish_diagnostics', | |
command: 'textDocument/publishDiagnostics', | |
}, | |
'implementation': { | |
provider: 'implementation', | |
command: 'textDocument/implementation', | |
}, | |
'workspaceSymbol': { | |
provider: 'document_symbol', | |
command: 'workspace/symbol', | |
}, | |
'prepareCallHierarchy': { | |
provider: 'call_hierarchy', | |
command: 'textDocument/prepareCallHierarchy', | |
}, | |
'incomingCalls': { | |
provider: 'call_hierarchy', | |
command: 'callHierarchy/incomingCalls', | |
}, | |
'outgoingCalls': { | |
provider: 'call_hierarchy', | |
command: 'callHierarchy/outgoingCalls', | |
} | |
} | |
var capabilities_func = printf('lsp#capabilities#has_%s_provider(v:val)', operations[op].provider) | |
var servers = filter(lsp#get_allowed_servers(), capabilities_func) | |
if len(servers) == 0 | |
echo printf('Lsp %s not supported', op) | |
return | |
endif | |
if lsp#_new_command() != lsp#_last_command() | |
return | |
endif | |
var ctx = { | |
'list': [], | |
'jump_if_one': 1, | |
'mods': '', | |
'in_preview': 0, | |
} | |
var params = { | |
'textDocument': lsp#get_text_document_identifier(), | |
'position': lsp#get_position(), | |
} | |
if !empty(conf) | |
if has_key(conf, "ctx") | |
extend(ctx, conf["ctx"]) | |
endif | |
if has_key(conf, "params") | |
extend(params, conf["params"]) | |
endif | |
endif | |
for server in servers | |
lsp#send_request(server, { | |
'method': operations[op].command, | |
'params': params, | |
'on_notification': function(Callback, [ctx, server, op]), | |
}) | |
endfor | |
enddef # LspSendRequest | |
endif | |
if !exists('*LspDiagnostics') | |
# extract vimlsp diagnostics | |
def LspDiagnostics(FormatFn: func(dict<any>): any): list<any> | |
var bufnr = bufnr() | |
if !lsp#internal#diagnostics#state#_is_enabled_for_buffer(bufnr) | |
return [] | |
endif | |
var items = [] | |
var uri = lsp#utils#get_buffer_uri(bufnr) | |
for [_, response] in items(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(uri)) | |
for d in lsp#utils#iteratable(response['params']['diagnostics']) | |
# add(items, d) | |
add(items, FormatFn(d)) | |
endfor | |
endfor | |
return items | |
enddef | |
endif | |
if !exists('*FormatDiagnostic') | |
# format a single diagnostic to common vimgrep format | |
def FormatDiagnostic(d: dict<any>): string | |
var code = '' | |
if exists('d.code') | |
code = printf("[%s]", d.code) | |
endif | |
return printf( | |
"%s:%d:%d\t%s %s", | |
bufname(), | |
d.range.start.line + 1, | |
d.range.start.character + 1, | |
code, | |
d.message | |
) | |
enddef | |
endif | |
endif | |
#### | |
## Statusbar | |
def g:LspNbErrors(): string | |
var errNb = 0 | |
if exists('lsp#get_buffer_diagnostics_counts') | |
errNb = lsp#get_buffer_diagnostics_counts()['error'] | |
endif | |
return errNb > 0 ? '[' .. errNb .. ']' : '' | |
enddef | |
# status line conf | |
set statusline=%1*%n | |
set statusline+=%4*\ ::\ | |
set statusline+=%2*%f | |
set statusline+=%5*\ %{g:LspNbErrors()} | |
set statusline+=%3*\ %m | |
set statusline+=%*%=\ | |
set statusline+=%1*%y | |
set statusline+=%4*\ ::\ | |
set statusline+=%1*%{strlen(&fenc)?&fenc:&enc} | |
set statusline+=%4*\ ::\ | |
set statusline+=%1*%l,%c\ %3*%p%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment