Мне не удалось заставить завершение ключевых слов vim вести себя так, как я хочу, поэтому я просмотрел документацию по vim (:h tag, popup, popup_atcursor
) и пришел к выводу, что создание моего собственного простого всплывающего окна должно сработать.
Код
" get the parameters of a function and put it in a popup using ctags
func GetFuncParamsFromTag()
silent write
" jump to tag under cursor
silent execute "normal \<c-]>"
" if there is '(' on the same line, it may be a function
if search('(', "n") == winsaveview()["lnum"]
" yank the function's name and parameters
silent execute "normal v/)\<cr>y\<c-t>"
" remove any previously present popup
call popup_clear()
" make the popup spawn above/below the cursor
call popup_atcursor(getreg('0'), #{moved: [0, 80], highlight: 'WildMenu'})
endif
endfunc
nnoremap <silent> <leader>? :call GetFuncParamsFromTag()<cr>
Предварительный просмотр
Это выглядит так:
![screenshot](https://i.stack.imgur.com/IDrHW.png)
You just have to press ?
on a function's name in Normal mode and you get a nice little popup showing only the prototype of the function.
EDIT:
I found a workaround to get this to work when i use vim completion.
autocmd CompleteDone * execute "normal ^,?" | call feedkeys("\<esc>:autocmd! InsertLeave * ++once call popup_clear()\<cr>A")
Этот autocmd вызывает всплывающее окно всякий раз, когда вы завершаете слово, поэтому, если вы наберете myImcompleteFunctionTag<c-]><c-y>
, он завершит ваш тег, затем откроет всплывающее окно и оставит вас в режиме вставки в конце строки. Остальная часть autocmd закрывает всплывающее окно при следующем выходе из режима вставки.