1

I am trying to put from current line of vi to shell argument. I'd like to run at Virmc like this map :! xpdf "xxxxxxxxxx" I want to this. the xxxxxxxx will from current text line of vi.

Does anyone know how to put them into shell argument?

Currently tried : .vimrc map :! xpdf :p^M but it is not work.

DavidEG
  • 5,857
  • 3
  • 29
  • 44
Carter
  • 274
  • 2
  • 13

1 Answers1

1

You can use something like:

:nnoremap <F7> :execute(':!echo "' . getline(".") . '"')<CR>

This will map F7 and will echo the content of the current line (getline(".")). You can just replace F7 and echo for whatever you want.

A similar but most generic approach:

:nnoremap <F7> "zyiw:execute(':!echo "' . getreg('z') . '"')<CR>

Again will map F7 but this time will echo the current word.

"z  => Just use z register, you can use any register you want (`:help registers`).
yiw => Copy the current word, you can replace for any yank command you like.
getreg('z') => Get the text copied in the register *z*.
Community
  • 1
  • 1
DavidEG
  • 5,857
  • 3
  • 29
  • 44
  • Thanks @DavidEG. But I have still problem. I can't read the documents when I use your the first command. I used like this :nnoremap :execute(':!evince "' . getline(".") . '"') in the VI. Then the output message is like this. Unable to open document, file not open. – Carter Nov 20 '14 at 00:56
  • 1
    Either the line contains data that is not part of the file name or the content is not a full path that evince can find. For the first case I would go for the second command using `yiw`, you will need some tweak, `yiw` is not probably what you want to use. For the second case I would use something like `find` to locate the file: `:nnoremap :execute(':!find /path/to/your/pdf/files/ -name "' . getline(".") . '" -exec evince {} \;')`. Again probably will need tweaks. – DavidEG Nov 20 '14 at 09:38
  • Thanks @DavidEG , I'm not sure as to /path/to/your/pdf/files/. Did you mean that I have to type absolute path when I want see some pdf files? This is very uncomfortable way. Is there any way to fill with automatically? – Carter Nov 25 '14 at 00:43
  • I mean  /path/to/your/pdf/files/ this part should be assigned current vi path directory. – Carter Nov 25 '14 at 00:50
  • 1
    In that case you can use `getcwd()`. You might want to use something like https://github.com/vim-scripts/gf-ext (haven't used it but seems it does what you need) – DavidEG Nov 25 '14 at 10:08
  • Thanks, but I just want to use that. I don't need else. – Carter Nov 25 '14 at 12:21