tags:

views:

73

answers:

2


1. How can I execute a command in vim, under the cursor. (word)

We know that Shift+k is used to open a man page under the cursor. I want to execute the

command instead of opening the man page.

[OR]

2. How can I take the current word under the cursor in VIM?

+3  A: 

How can I take the current word under the cursor in VIM?

echo expand("<cword>")

or

let l:WordValue = expand("<cword>")

How can I execute the command under the cursor? I am not exactly sure what kind of commands you're refering to, but since you mentioned man pages, I'd assume that you want to execute unix and or cmd commands. If this is the case you'll want something like

fu ExecuteCommand()
   let l:Command = expand("<cword>")
   execute "!" . l:Command
endfu 

Alternatively, you might want to change the value of keywordprg:

:set keywordprg=!
René Nyffenegger
Ok Thank you. It's working fine.
ungalnanban
A: 

another tip: if you want to put the word under current cursor into the command-line mode, you can use "CTRL+r+w" to do so.

Zhaojun
The CTRL+r+w is not working for me.
ungalnanban