Code find-xargs(less)-gvim

find . -name "*.tex" -exec grep -il "agent" {} + | less -s -M +Gg



In less, command !gvim

  • You se the current line number at the status bar at the bottom. It locates at the top of the window.
  • Expected output is the file ./InfectiousDiseases/1.4.2016.tex of the current line in a new window gvim.
  • Current output is unsuccessful with empty file in vim.

Muru's proposal with Xargs in less

|X xargs gvim

which is about

|Xcommand Pipe file between current pos & mark X to shell command.


Muru's suggestion with find-vim-gvim

find . -name "*.tex" -exec grep -il "agent" {} + | vim -

I do successfully :tabe <cfile> or :vs <cfile> just by keeping cursor on the current line. I do successfully !gvim <cfile> but the list view goes to the another view Press ENTER or type command to continue which I do not like. I would like to keep the view in the list view. It would be also great to have a binding/macro for launching many external windows fast on the current line.

:nnoremap gff :silent! exec "!gvim " shellescape('<cfile>') <bar> redraw!<cr>

which works successfully by pressing gff on the current cursor position. I think the sequence binding gff is too slow. It would be great to have a stereo binding that is pressing two buttons which activates the macro. I can recall that CTRL-1 or CTRL-ESC or CTRL-F1 could be possible.


I am having some problem with stereo keybindings <C-1> because stereo keybinding is impossible in Vim, but not in some Gvim's. I extended OS X specific part here in Apple Stackexchange, but noticed that Vim Stackexchange knows better so here.

How can you execute gvim on the current line in viewer?

  • 1
  • 1
    In less? Maybe try |X xargs gvim, where X is a mark (dunno what that is). In vim, maybe you could create a custom command: :command E !gvim <cfile>. Then you can do :E. (Or a map with similar effects)
    – muru
    Apr 20, 2016 at 20:53
  • 1
    Ah, yes, that was a typo, sorry about that. For the status bar, that's the Vim Airline plugin: github.com/vim-airline/vim-airline It's very popular.
    – muru
    Apr 20, 2016 at 20:56
  • 1
    Try this mapping: :nnoremap gff :silent! exec "!gvim " shellescape('<cfile>') <bar> redraw!<cr>. Then you can press gff while on the filename.
    – muru
    Apr 20, 2016 at 21:11
  • 1
    Yes. In less type h. You'll see |X mentioned right below !. It says it pipes content between current line and mark X to the command. And to convert stdin to args, xargs it is.
    – muru
    Apr 20, 2016 at 21:23

1 Answer 1


Solution to question [deprecated]

So first do

find . -name "*.tex" -exec grep -il "agent" {} + | vim -

In .vimrc, one macro from vi.stackexchange where gff opens many windows of the visual selection

% https://vi.stackexchange.com/a/7627/2923
if has("win32") || has("win64")
  :vnoremap gff :<C-U>'<,'>g/^/silent! exec "!START /B gnvim " . shellescape('<cfile>') <bar> redraw!<cr>
  :vnoremap gff :<C-U>'<,'>g/^/silent! exec "!gnvim " . shellescape('<cfile>') . " &" <bar> redraw!<cr>


Much better solution

Use the proposal here and just use tabs .vimrc

nnoremap <leader>gf :silent! execute "tabe " . expand('<cfile>') <bar> redraw!<CR>

function! OpenSelectionAsTabs() range
    let tabnr = tabpagenr()
    for line in range(a:firstline, a:lastline)
        execute "tabedit " . getline(line)
        execute "tabp"

nnoremap <leader>gf :'<,'>call OpenSelectionAsTabs()<CR>
vnoremap <leader>gf :call OpenSelectionAsTabs()<CR>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .