Is it possible to use word under cursor in shell command? Say:
Elvis ^ cursor here then :r! echo <word_under_cursor>
and get "Elvis" read in.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
If you are typing interactively in the vim command line you can hit CtrlrCtrlw to include the current word or CtrlrCtrla to include the current WORD.
If you are writing a function or a command you can use
expand('<cWORD>') for the current WORD version.
function! Hello() echo 'The current word is: ' . expand('<cword>') echo 'The current WORD is: ' . expand('<cWORD>') endfunction
There is something to remember: Vim treats the commands differently. Some of them accept literals and cmdline-specials, so you can do
:r !echo <cword>
While others accept VimScript expressions, so it could look as, for example,
:put=system('echo ' .. expand('<cword>'))
So the syntax of VimScript is heavily context-dependent.