I am trying to make elinks dump the web-page at the URL which starts at the current buffer position in vim (and ends at EOL), by mapping this keyboard shortcut and putting it in my .vimrc:
nmap owp :norm yE \| new \| .!elinks -dump @"<CR>
This yanks the rest开发者_如何学Go of the line into the " register. Then it's supposed to open a new buffer and invoke elinks which should dump the rendered web-page into this new buffer. When I run the command the URL gets yanked, and that's it. New buffer does not open and elinks does not get invoked.
- What am I doing wrong here?
- Is there a smarter way to yank URLs under the cursor? This method won't work for URLs which occur in the middle of the line.
Never mind. Dug around in the vim manual and found some workarounds. One problem was with this:
.!elinks -dump @"<CR>
this won't work as expected. Everything after ! operator is passed to the shell verbatim by vim - so the register value will not be passed to elinks. Another problem is that the command separator somehow is not working after :norm yE
. The final solution to get around these problems was this:
function! Browser ()
normal yE
new
execute ".!elinks -dump " . @"
set nomodified
endfunction
nmap owp :call Browser ()<CR>
Notice the use of execute to get around the limitation of "!" operator. I still need to figure out a solution for question 2 though.
精彩评论