3

Code in .vimrc which starts graphical Neovim on a filename when pressing gff

% http://unix.stackexchange.com/q/277918/16920
:nnoremap gff :silent! exec "!gnvim " shellescape('<cfile>') <bar> redraw!<cr>

Situation

  1. View: a list of files.
  2. Highlight some of them.
  3. Press gff.
  4. Wanted: get many gvims of multiple documents open.

How do I loop over a list of files from a visual selection?

1 Answer 1

4
:vnoremap gff :<C-U>'<,'>g/^/silent! exec "!gnvim " . shellescape('<cfile>') <bar> redraw!<cr>

The mapping is for visual mode, and performs a global on all lines that match /^/...have a start. Then the rest is the same.

Since exec is run synchronously you will only get one instance at a time and your current vim instance will block waiting for the first launched gnvim to end.

To get multiple instances at once you'll need to ether use the OS's background process management ( & in unix systems), or use some sort of dispatching system like screen or tmux. See tpope's Dispatch plugin.

So assuming you are on a Linux/BSD/OSX system

:vnoremap gff :<C-U>'<,'>g/^/silent! exec "!gnvim " . shellescape('<cfile>') . " &" <bar> redraw!<cr>

If you are on Windows you can use START /B program

:vnoremap gff :<C-U>'<,'>g/^/silent! exec "!START /B gnvim " . shellescape('<cfile>') <bar> redraw!<cr>

To script this up using OS detection:

if has("win32") || has("win64")
  :vnoremap gff :<C-U>'<,'>g/^/silent! exec "!START /B gnvim " . shellescape('<cfile>') <bar> redraw!<cr>
else
  :vnoremap gff :<C-U>'<,'>g/^/silent! exec "!gnvim " . shellescape('<cfile>') . " &" <bar> redraw!<cr>
endif
6
  • Are you asking of you can generate line specific mappings? <C-1> does first line? If not, the mapping can be anything usable with normal mode mappings so long as it doesn't undo your visual selection.
    – jecxjo
    May 4, 2016 at 17:23
  • @Masi yes just replace gff with <C-1> and you should be good.
    – jecxjo
    May 4, 2016 at 18:25
  • I have a feeling its because Ubuntu has Ctrl+1 set to something like moving to the 1st Virtual Desktop which would not be controlled by Vim. That would be considered OT for this question since it's an issue with Ubuntu.
    – jecxjo
    May 4, 2016 at 19:26
  • 1
    I would suggest you do this the Vim way and use <leader> and then one or more keys. Since gf is the "Open file named under cursor, you should use either gf or <leader>gf. Beyond that, this is OT.
    – jecxjo
    May 4, 2016 at 19:37
  • I extend the even distribution of windows here vi.stackexchange.com/q/7637/2923 May 5, 2016 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.