开发者

How do I make elinks dump the web-page at a URL under cursor in a new vim buffer/tab?

开发者 https://www.devze.com 2023-01-15 23:37 出处:网络
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:

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.

  1. What am I doing wrong here?
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消