Vim: Add Interactive Tag

I know that some kind of "interactive text" can be inserted into emacs. That is, you can insert text that, when the user clicks on it, opens another file.

Is there something like this for vim?

+7
source share
3 answers

It is possible, but specific to files. The best example would be vim's own help system, which is no more interesting than an unmodifiable buffer with certain mappings.

See vimwiki and vimorgmode for examples have such links.

+4
source

For simple random cases, you can write a function that opens a specific file based on the word under the cursor. You can then map this function to a double-click event.

For example:

function! CustomLoad() let word = expand("<cword>") let path = "/path/to/file/to/be/opened" if ( word == "special_keyword" && filereadable(path) ) sil exe "split " . path endif endfunction 

And map it using:

 nnoremap <2-LeftMouse> :call CustomLoad()<CR> 

Thus, double-clicking (in normal mode) the word special_keyword will open the file /path/to/file/to/be/opened , if it is available for reading. You can add several cases for different keywords or do some text processing of the keyword to generate a file name, if necessary. (Note that the filereadable condition filereadable not necessary, but probably a good idea.)

Hope this helps.

+4
source

Another simple solution is to write down the file name and use gf to go to the file Ctrl+w,f to open the file in a split window or Ctrl+w,f,g to open it in a tab. Note that the file must already exist. See this vim wikia entry for some other tips.

+1
source

All Articles