Jump to function definition in vim

后端 未结 11 2617
独厮守ぢ
独厮守ぢ 2020-11-27 08:53

How can I jump to to a function definition using vim? For example with Visual Assist, I can type Alt+g under a function and it opens a context menu lis

11条回答
  •  余生分开走
    2020-11-27 09:29

    g* does a decent job without ctags being set up.

    That is, type g,* (or just * - see below) to search for the word under the cursor (in this case, the function name). Then press n to go to the next (or Shift-n for previous) occurrence.

    It doesn't jump directly to the definition, given that this command just searches for the word under the cursor, but if you don't want to deal with setting up ctags at the moment, you can at least save yourself from having to re-type the function name to search for its definition.

    --Edit-- Although I've been using g* for a long time, I've recently discovered two shortcuts for these shortcuts!

    (a) * will jump to the next occurrence of the word under the cursor. (No need to type the g, the 'goto' command in vi).

    (b) # goes to the previous occurrence, in similar fashion.

    N and n still work, but '#' is often very useful to start the search initially in the reverse direction, for example, when looking for the declaration of a variable under the cursor.

提交回复
热议问题