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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With