views:

20

answers:

1

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 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.
A: 

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.

Sudhanshu