Reputation: 36071
I know that in emacs it is possible to insert some kind of "clickable text". I.e. you can insert a text, that, when the user presses enter on it, opens another file.
Is there something like this for vim?
Upvotes: 8
Views: 2485
Reputation: 6690
Another simple solution is to write the filename 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.
Upvotes: 1
Reputation: 15735
For simple ad hoc cases you could write a function to which opens a certain file based on the word under the cursor. You could then map this function to the 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) on the word special_keyword
will open the file /path/to/file/to/be/opened
if it is readable. You could add multiple cases for different keywords, or do some text-processing of the keyword to generate the filename if required. (Note that the filereadable
condition is not necessary, but probably a good idea.)
Hope this helps.
Upvotes: 4
Reputation: 17537
It is possible, but is filetype-specific. A best example will be vim's own help system that is nothing fancier than an unmodifiable buffer with specific mappings.
See vimwiki and vimorgmode for examples to have such links.
Upvotes: 4