Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.03 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to use vim variables in an external filter command in visual mode?
  2. " set b:perltidy_options based on dirname of the currently edited file
  3. function! SetProjectVars()
  4.   if match(expand("%:p:h"), "/project-foo/") >= 0
  5.     let b:perltidy_options = "--profile=$HOME/.perltidyrc-foo --quiet"
  6.   elseif match(expand("%:p:h"), "/project-bar/") >= 0
  7.     let b:perltidy_options = "--profile=$HOME/.perltidyrc-bar --quiet"
  8.   else
  9.     let b:perltidy_options = "--quiet"
  10.   endif
  11. endfunction
  12.  
  13. " first set the project specific stuff
  14. autocmd BufRead,BufNewFile * call SetProjectVars()
  15.  
  16. " then use it
  17. vnoremap ,t :execute "!perltidy " . b:perltidy_options<Enter>
  18.        
  19. :'<,'>execute "!perltidy " . b:perltidy_options
  20.        
  21. :execute "'<,'>!perltidy " . b:perltidy_options
  22.        
  23. vnoremap ,t :<C->e'execute '.string(getcmdline()).'."!perltidy " . b:perltidy_options'<CR><CR>
  24.        
  25. vnoremap ,t :!perltidy <C-r>=b:perltidy_options<CR><CR>
  26.        
  27. vnoremap ,t :execute "!perltidy " . b:perltidy_options<Enter>
  28.        
  29. vnoremap ,t :<C-u>execute "!perltidy " . b:perltidy_options<CR>