Vim: How to go to the declaration (of a class, method, function, variable, etc)

前端 未结 3 1083
不思量自难忘°
不思量自难忘° 2021-01-31 08:33

Right now I am working on a file which uses many classes, methods, functions, variables, etc. Is it possible to go to the declaration of all of them? Please, take into account t

3条回答
  •  日久生厌
    2021-01-31 09:14

    I use the you complete me (ycm) plugin for this, which is

    a fast, as-you-type, fuzzy-search code completion engine for Vim

    It works with a bunch of languages and is very powerful. Check this section for how to install it on your system.

    When e.g. using it with a Java Maven project, open the desired file from the folder that contains your pom.xml file and the plugin scans all your files and dependencies.

    I do have the following key mappings in my ~/.vimrc for convenient use of your requested feature:

    let g:ycm_key_list_select_completion = ['', '']
    let g:ycm_key_list_previous_completion = ['', '']
    let g:SuperTabDefaultCompletionType = ''
    nnoremap jd :YcmCompleter GoToDefinitionElseDeclaration
    nnoremap ji :YcmCompleter GoToImplementation
    nnoremap jr :YcmCompleter GoToReferences
    

    Assuming your is mapped to , with let mapleader = "," as in my case the following commands work:

    • ,jd go to definition or declaration
    • ,ji go to implementation
    • ,jr go to references
    • Ctrl+n/Ctrl+p move down/up in a list that pops up for autocompletion

提交回复
热议问题