-1

Code

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

Output in OS X: windows on top of each other. Ubuntu Linux 16.04: evenly distributed.

I do not want to use system dependent tools to do this like (AppleScript). I want the same view in OS X and Ubuntu Linux. The current view of Ubuntu Linux is the best one. The possibility is to use NeoVim's API here.

Possible solution [8bittree]

Do not open many GVim's, but use tabs. The reason why I open many GUIs here is that I have not managed to install Airline in OS X (thread here about How to Install Vim Airline Plugin?) such that I can use similar settings in Ubuntu 16.04. I think it would be ok if all filenames are visible on the top-bar.

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

where something problem with nvim -p. Results in messy outputs in tabs.


How can you distribute the windows evenly on OS X?

  • 4
    I'm voting to close this question as off-topic because this question has nothing to do with Vim. You'll need to look into AppleScript to achieve your goal. – romainl May 5 '16 at 8:00
  • 2
    1. Vim/Neovim is not responsible for window positioning, it's the window manager that does all the work. Your problem is that your Linux window manager is subjectively "better" at that job than Mac OS X's. Since Vim/Neovim is unable to position its GUI windows you will need AppleScript to achieve your goal. 2. You already use system-dependent solutions anyway. – romainl May 5 '16 at 8:14
  • 1
    Any particular reason you're using multiple GUI windows instead of splits, tabs, and buffers in one GUI window? – 8bittree May 5 '16 at 14:23
  • So, just to make sure I understand correctly, you're currently opening each file in a separate instance of GVIM, in order to be able to more easily see what files you have open? – 8bittree May 5 '16 at 14:46
  • 2
    Not to tell you what to do, but you might find it beneficial to get used to opening/closing files within a single instance of vim. Whether you use tabs as part of a solution is up to you, but it it'll feel more natural jumping between windows, copying/moving text between them etc than separate instances of vim. – user859 May 5 '16 at 16:47
2

It appears as though your needs may be met by using tabs. See :help tabpage in Vim for general help, but here are a few relevant commands:

  • Start Vim with vim -p filename ... to open each file in a separate tab (Though this will be limited by the tabpagemax setting).
  • Move to the next tab with gt and the previous with gT.
  • :tabe or :tabedit will open a new tab with a blank file. Provide one filename to open that file.
  • Many commands can be preceded with :tab to have it operate on a tab instead of its normal target. An example would be :tab split to open a new tab with the current file, instead of a new split. Another is :tab ball to open all (listed, check via :ls) buffers in tabs, again, up to tabpagemax.

Now, if you really want to try rearranging GUI windows, that's possible in GVim, although I've not tested it on a Mac nor with Neovim.

  • :winpos will display the current pixel coordinates of the upper left corner of the GUI window. Provide X and Y arguments to move it to those coordinates. This only works in GVIM, not in a terminal, and might not be available in all versions.
  • lines and columns are settings that store the current (character, not pixel) size of the GVIM gui window or terminal. Check their current value with :set lines? and :set columns? and change them with :set lines=24 columns=80, substituting the desired numbers, of course.

Just to reiterate, :winpos is GUI window only, lines and columns work in both GUI windows and terminals.

  • Can you show how to use vim -p in the macro, please. Please, see the body for my proposal which leads to corrupted output. – Léo Léopold Hertz 준영 May 5 '16 at 17:57
  • @Masi vim -p is something you run to start up vim. If you've already got vim open, you should open files with :tabe, or, if you've already got the files opened, use :tab ball to move them all to tabs. – 8bittree May 5 '16 at 20:05
  • Please, see the macro. I run find with exec. Vim is not open yet but you cannot run vim -p. Which one to run? – Léo Léopold Hertz 준영 May 6 '16 at 4:09
  • @Masi I do not understand. The code in your question is all Vim mappings. You have to have Vim open to run them. – 8bittree May 6 '16 at 13:07
  • 1
    @Masi Don't put vim -p into a vim mapping or in your .vimrc. Open a terminal and type vim -p file1 file2 file3. – 8bittree May 6 '16 at 13:44

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