send current line to external command in vim (without capture)
The goal is to use the current line as a TODO and send this to some external program. Something like this:
:! /usr/bin/todo "content of current line"
I know of the filtering command but this implies that I want to edit the current buffer which I do not want (:.! acts as a filter). I know how to get the current file with '%' but isn't there any way to get some other content ? Maybe by开发者_运维知识库 using :execute ...
:.! works as a filter, but :.w ! (mind the space!) just passes the output. See :help :w_c. I.e.
:.w !/usr/bin/todo -
You can insert contents of registers into command line, so doing something like:
"1y$  //yank current row to register 1
: CTRL-R 1  //CTRL-R followed by register id pastes register to command line
should do the trick.
You might like something like these mappings (i.e. saved in your .vimrc or pasted into a : prompt):
cmap <C-R>'           <C-R>=shellescape(getline('.'))<CR>
cmap <C-R><C-R>' <C-R><C-R>=shellescape(getline('.'))<CR>
Once installed, you use them like this:
:!/usr/bin/todo ^R'
(type an actual Control‑R where the above example shows ^R).
You can think of them as command-line mode versions of the registere-based Control‑R and Control‑R Control‑R (see :help c_CTRL-R, and :help c_CTRL-R_CTRL-R) where the “imaginary” register ' always contains the shell-quoted contents of the current line.
Because these mappings use the same prefix as built-in mappings (see the :help topics mentioned above), you must enter the final single quote within timeoutlen milliseconds (see :set timeoutlen?), or it will default to the built-in mapping (see :help map-typing).
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论