Reputation: 15872
suppose I have a line like this: hello foo bar
and my cursor is on foo
. I want to map a key that will call a function with foo
without me having to first select it visually. How would I do this in vim?
Upvotes: 4
Views: 1219
Reputation: 3917
Another solution...
nnoremap <leader>f yw:call fun(@")<cr>
Better solution...
nnoremap <leader>f :call fun(<c-r><c-w>)<cr>
Upvotes: 1
Reputation: 195059
you are looking for function expand(expression)
here your expression would be '<cword>'
If you love to put it as function argument, you could :yourFunction(expand('<cword>'))
:h expand(
for more details.
Upvotes: 4
Reputation: 35314
Perhaps something like this:
nnoremap \print :echo printf('word under cursor: %s',expand('<cword>'))<CR>
Upvotes: 3