We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

13

Exuberant ctags is the simplest way to achieve this. Under GNU/Linux (e.g. Ubuntu or Debian) you should be able to just do sudo apt-get install exuberant-ctags (For OSX "$ brew install ctags" should suffice; for Windows you might want to visit http://ctags.sourceforge.net/ and download the standalone executable) Then navigate to your project's root ...


13

This line should be enough: set tags=./tags;,tags; It tells Vim to look for a tags file in the directory of the current file as well as in the working directory, and up, and up, and…


11

You can't jump to function calls with ctags. For C/C++ and Java there is cscope, and it integrates nicely with Vim (see :help cscope). For other languages you might be able to find a tool that generates / exports cscope-compatible databases (f.i. hscope for Haskell, and starscope for Ruby, Go, and JavaScript). You can also use cscope with GNU global ...


10

If each project is a separate git repo, one can use fugitive.vim which will automatically point tags at .git/tags, allowing easy per-project tags.


8

wildignore had a trailing comma. My vimrc had set wildignore=*.png, which had a trailing comma. Changing it do set wildignore=*.png solved my issue. It turns out, after looking at :set for a while, that ftplugin/python.vim does set wildignore+=*.pyc somewhere, because just set wildignore=*.png, isn't enough to break the tags. So the wildignore that I had, ...


8

You can't do that with ctags. Try a beefier alternative like cscope (which even has its own help section: :help cscope) or global.


7

You could use Vim's grep command to search all the files in your project: :grep! "\<<cword>\>" . -r :copen Let's put that in a keybind: nnoremap <F4> :grep! "\<<cword>\>" . -r<CR>:copen<CR> I find this one-key project-wide search invaluable when I am exploring a large unfamiliar codebase. \< and \> are ...


6

Depending on how you update your ./tags file: If you do not commit your ./tags file to your branch/repository you can use a git hook that calls ctags -R . on each pull/checkout you do - this way your ./tags file will always contain data on all present files in the current version you have checked out. If you do want to commit your ./tags file, you can ...


6

Okay I've done it: It all has to do with ctags: First create two files called foo.c and foo.h to test it: In foo.h write down: int bar(void); In foo.c write down: int bar(void) { /* */ } And in the directory where those two files is, execute: ctags --list-kinds You get a long list of languages with there types of tags. Find C. Notice the following ...


6

There are q few misconceptions here: "Hotkey" is not a thing in Vim. You have "commands", "mappings", "abbreviations"… but no "hotkeys". <C-]>, <C-t> and :tselect are all "commands". There's no such thing as "leader keys". You can create and use "leader" mappings that use the "leader key", if you want, but there's nothing special with them. Ex ...


6

I cannot provide an answer different to the one I gave in other similar questions. While tag-based plugins may present a complete list of existing overloads in a way much more ergonomic than :tselect (they may even provide a filter option like my lh-tags plugin), they cannot help restrict the list of overloads to the one matching the types of the objects ...


5

You could use this to tell Vim to look recursively for tags files under /usr/include/: set tags+=/usr/include/**/tags For the generation part, I'm afraid you will still have to generate tags files manually for each new library… or write a shell script. By the way, Vim comes with what it calls "include-search"; you will probably find the following help ...


5

<c-]> only looks at the keyword under the cursor. Normally : is not defined as a keyword character. To define : as a keyword character you can put setlocal iskeyword+=: in ~/.vim/ftplugin/lua.vim so that this happens automatically for lua files (and only for lua files) Or if you just want to add something to your vimrc, you can add the following ...


5

g<C-]> will display a list of tags only when there is more than one, so you could just train yourself to type g<C-]> instead of <C-]>. But having to type two characters instead of one, especially when one takes a modifier, is a pain, so what I would do is put this mapping in your ~/.vimrc: :nnoremap <C-]> g<C-]>


4

gf The default $VIMRUNTIME/ftplugin/scss.vim sources $VIMRUNTIME/ftplugin/sass.vim which already sets everything for you to do gf over avatar and jump to avatar.css: setlocal suffixesadd=.sass,.scss,.css setlocal includeexpr=substitute(v:fname,'\\%(.*/\\\|^\\)\\zs','_','') See: :help gf :help 'includeexpr' :help 'suffixesadd' definition search It is ...


4

Built-in definition search Vim is able to follow "includes" for completion and for navigation. What constitutes an "include" can be defined with the 'include' option. Sadly, Vim's include mechanism is not flexible enough to work with RequireJS's standard way to define multiple dependencies in a same line: define(foo, ["bar", "module/baz"], function(Bar, ...


4

A variety of methods are at your disposal There are some very useful commands listed here, most notably [I, which will display all lines in the current and all included files containing the keyword under the cursor. See :h [I and :h include-search. You can :grep or :vimgrep to search for occurrences of a particular symbol (or any pattern for that matter), ...


4

So far I can name two solutions to the problem of finding either the declaration or the definition of a function. I know there is another well know tags based solution, but as I don't use it, I'll let others give it to you. The more trendy one first: YouCompleteMe has a :GoToDefinition and a :GoToDeclaration pair of commands. The one I use (it's hard to ...


4

The documentation (:help ctrl-]) says: When there are several matching tags for {ident}, jump to the [count] one. When no [count] is given the first one is jumped to. g] may not be what you are looking for but that's the best you can get in Vim. Basically, you can't expect ctags and Vim to understand your code, so you'll have to look for a smarter ...


4

As @romainl said, It is indeed an FS(file system) case-sensitivity issue. My project file is mounted from Window 7 to my Fedora using: mount {Windows 7 Dir} {Fedora Dir} /local_folder -t cifs -o username=xxxx,password=xxxx From the mount.cifs man page: case sensitive is the default if the server supports it. It means that the Mount will preserve the ...


4

To see all the files that Vim sourced during launch, I typed :scriptnames. I found that: When launching vim with the command $vim --noplugin or $vim, there is a /etc/vimrc file which is sourced; When launching vim with $vim -u NONE or $vim -u NORC, this /etc/vimrc file is gone. There are other differences in the list of sourced files, but only /etc/vimrc ...


4

:g/func/# gives you an actionable outline of the current JavaScript buffer without installing any third party plugin or requiring any external program. Use func\|var to include variable declarations.


4

based on the prompt from @Cometsong I added wrote the regex expression below and added to my ~/.ctags --regex-sh=/^[ \t]*(local)?[ \t]*([A-Za-z0-9_-]+)=/\2/v,variable,variables/ So far it seems to be working quite nicely


4

First, the command to jump to a tag is <C-]>, not ]. Second, :ptag doesn't care about the word under your cursor. It works just like :tag but uses the preview window instead of jumping directly to the tag. :tag and :ptag, without argument, are used to jump to the first tag in the tag stack. You'll obviously get an error if the tag stack is empty, or ...


3

A regex can be built to find variable declarations like [A-z]…=[A-z0-9] Another for variable usage to include a \$ in the front My own yaml-specific .ctags example is: --regex-c=/^( YAML langdef config )/\1/k,t/ --langdef=yaml --langmap=yaml:.yml.yaml --regex-yaml=/^[ \t]*-[ \t]*.*:[ \t]*(.+)/\1/k,tasks/ --languages=+yaml Modified for bash-isms of course....


3

You could use a mapping from Ctrl+] to a custom function, similar to the one described at :help CursorHold-example: A nice addition is to highlight the found tag, avoid the ":ptag" when there is no word under the cursor, and a few other things: > :au! CursorHold *.[ch] nested call PreviewWord() :func PreviewWord() : if &previewwindow ...


3

There are few alternatives. The first one is ctags. If you need a more advanced indexer then cscope is a better alternative. For instance it will allow you to list all callers of given function. These tools will index your code without really understanding it properly (they do have a simple grammar definition to know what given symbol means). It's also ...


3

Vim is a powerful text editor. The tags feature is based on a simple foundation: Vim can read one or several tags databases, which contain line-based records consisting of a tag (basically a string), a corresponding file and address (search pattern) to locate it, and optional additional information. That's what you get: If you build a tags file covering ...


3

You can use :tnext to jump to the next matching tag. If you have four tags foo, these commands will let you jump to each tag sequentially: $ vim -t foo :tn :tn :tn You can use :tp[revious] to jump to the previous tag, :tl[ast] to jump to the last one, :tf[irst] to jump to the first one. And you can use :ts[elect] to list all matching tags. You can also ...


3

What's happening When there are multiple matches for a tag, Vim uses the following list of priorities (listed at :help tag-priority). "FSC" A full matching static tag for the current file. "F C" A full matching global tag for the current file. "F " A full matching global tag for another file. "FS " A full matching static tag for another ...


Only top voted, non community-wiki answers of a minimum length are eligible