Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Hot answers tagged

102

Vim comes with an exhaustive and fully indexed documentation that contains the answers to most of the questions you may have on using Vim. But the documentation is huge and may look to the neophyte as an impenetrable maze. Here are a few guidelines to help you find what you need… The :help command is your gateway to Vim's documentation. Read the first ...


11

Say hello to knowledge fragmentation: https://stackoverflow.com/q/6932702/520162 This question was already asked and answered on StackOverflow. The key is to press CTRL and the key that is located where the ] lives on the US keyboard. I had the issue with a QUERTZ German keyboard and have to press CTRL-+ Compare: US keyboard: German keyboard: Another ...


8

You don't necessarily have to install a plugin like ctags (although this would be reliable and allow many more great features, because you have semantic knowledge of your code, of course). Vim has a built in function to go to the definition by doing a clever search: With the cursor over a keyword, press gd or gD. I recommend reading the help page on these,...


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

let &path += fnamemodify(tagfiles()[0], ':p:h') should add the path of your tags file's parent directory to the path option. Updating path each time you enter a buffer is probably a good idea: augroup UpdatePath autocmd! autocmd BufNewFile,BufRead,BufEnter * set path&vim | let &path += fnamemodify(tagfiles()[0], ':p:h') augroup END


8

The tag is useful for two things: When using the :help command, the tag is the exact phrase which will let you distinguish between similar terms. {subject} E149 E661 :h[elp] {subject} Like ":help", additionally jump to the tag {subject}. For example, <c-A> is available in insert, normal and ...


7

ctrl-] uses the word under the cursor, (as opposed to a WORD) which means that any punctuation is excluded. From :h word: A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, ). This can be changed with the 'iskeyword' option. An empty line is ...


7

The results from :VimwikiSearchTags are populated in the location-list window, so you can navigate using :lnext and :lprevious, or you can check all the results using :lopen. To be honest, despite I have been using Vimwiki for several years, I didn't know about the tags. Maybe it is because my wikis are not that large (~2 MB at most), but I find it easier ...


6

The g:current_file is evaluated in your ~/.vimrc at startup, i.e. before any file has been loaded. You need to do the evaluation inside the :autocmd; either with :execute, but for options, it's more elegant to use :let &optionname = ... instead: au Bufread,BufNewfile *tags setlocal filetype=tags | let &tags = expand("%:t")


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 ...


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

-0.1 make notes about vim in a file. Use it as reference and container. fast way to find vim help of key | :cmd | 'option' | etc :h gi or :h g; for gi or g; in normal mode :h ^i for Ctrl-i in normal mode :h ^w^w for Ctrl-wCtrl-w in normal mode :h ^wf for Ctrl-wf in normal mode :h i^n for insert mode Ctrl-n :h c^r^r for cmdline mode Ctrl-r Ctrl-r :h :pu for ...


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

Put this in your vimrc: map <C-]> :TabExpand 1<CR> command -nargs=1 TabExpand call HandleTabTagExpand( <f-args> ) let s:commentchar = """ function HandleTabTagExpand(tagnumber) let tagident = expand("<cword>") redir @a try sil exe "tselect ".tagident catch /^Vim(\a\+):E433:/ " no tag file echom "No ...


5

The answer for this is :h file-searching: 11. File Searching file-searching {not available when compiled without the |+path_extra| feature} The file searching is currently used for the 'path', 'cdpath' and 'tags' options, for finddir() and findfile(). Other commands use wildcards which is slightly different. There ...


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

I think the functionality you want is very useful, but it is already provided with the K mapping. This runs a program to lookup the keyword under the cursor. By default, it uses man. You can set it to ':help' (or to '') to open vim help files with K. Note that this is very useful, as it can be used to set a different lookup program for different file types. ...


4

Does it have to be dictionary completion, triggered via i_CTRL-X_CTRL-K? If another trigger key is fine (e.g. i_CTRL-X_CTRL-@), you can do this: Save the 'dictionary' option value Change it to point to your tags file Install an :autocmd CompleteDone handler that resets the option value Trigger dictionary completion Alternative If you don't actually need ...


4

You can obtain the filename and the line number (/search command) from the selected tag. let tag = taglist()[42] exe 'e '. (tag.filename) exe ':'.(tag.cmd) However, this won't push your 'open-and-go-to-the-right-place' into the tag stack as :tag would have. I've been able to trick vim into doing it in my lh-tags plugin. The current version of the (GPLv3) ...


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

You will have to use a program like ctags to generate a tag file. It is recommended to use exuberant ctags. Once you installed this program, go to the root directory of you project in a shell and generate a tagfile with: $ctags This will create a text file which contains the lines corresponding to the definition of each of your functions. Vim is able 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

Disclaimer: I don't have ripper-tags installed, this is my best guess on browsing the documentation. In the documentation it says that the typical usage is: ripper-tags -R --exclude=vendor This parses all *.rb files in the current project, excluding ones in vendor/ directory, and saves tags in Vim format to a file named ./tags. Using this with an ...


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 ...


4

To close the quickfix window, you use :cclose, as @statox mentioned in the comments. This won't affect which code buffer you're viewing, though. Vim doesn't distinguish between the buffer you were looking at originally and the buffers you navigated to via the quickfix, so to go back you are going to have to use Vim's regular buffer switching commands. If ...


3

vi was designed for use with glass terminals, the protocols of which often use many of the control-x commands down at the low end of ASCII. Others were reassigned in the move from paper terminals, such as Ctrl-L (form feed), which vi reinterprets from "form feed" to mean "repaint display" instead, that being more appropriate to a text editor. Commands like "...


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

I understand that you prefer to avoid changing 'isk' permanently, but what about changing it during the autocompletion? function! CustomComplTag() setlocal isk+=: call feedkeys("\<c-x>\<c-]>", "n") endfunction augroup CustomComplTagAutcmd au! autocmd CompleteDone * setlocal isk-=: augroup END inoremap <C-x><C-]> <C-o&...


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

I've implemented something like this using Exuberant Ctags and a .ctags file in the directory (should also work with .ctags in the home directory). You can read up on using Ctags with arbitrary regex, but the gist of it is that you'll be able to use that same Ctrl-] to go to these tags. The contents of my .ctags: --langdef=markdown --langmap=markdown:.md -...


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