How to call external program from vim with visual marked text as param? -


call pattern: path-to-programm visual-marked-text filetype directory

example: "c:\programme\wingrep\grep32.exe" search-pattern *.sql d:\myproject\build

the following vim-script function can used that.

function! feedvisualcmd(cmdpat)     let [qr, qt] = [getreg('"'), getregtype('"')]     silent norm! gvy     let cmd = printf(a:cmdpat, shellescape(@"))     call setreg('"', qr, qt)     echo system(cmd)     if v:shell_error         echohl errormsg | echom 'failed run ' . cmd | echohl none     endif endfunction 

it copies selected text unnamed register (see :help ""), runs given template of command through printf function, , executes resulting command echoing output.

if part of command changes pattern, convenient define mapping,

vnoremap <leader>g :<c-u>call feedvisualcmd('"c:\programme\wingrep\grep32.exe" %s *.sql d:\myproject\build')<cr> 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -