I'm looking for a way to:

  • combine two buffers into single buffer using columns [1, winwidth] from left buffer and columns [1, eol] from right buffer.
  • close buffer 2 so left with same contents in single left buffer. (It's should basically look like the window divider disappeared).

Visual example:
Before State

After running the cmd left with a single buffer with contents of the two buffers joined at the left buffer's window width After State Thank you for any suggestions. So I've tried starting in left buffer after copying the text in right buffer using visual block mode:

:set virtualedit=all    //for lines not the full width
:set nowrap             //don't want wrapping with new text
gg                      //go to first line
:norm! g$               //go to last column 
p                       //paste 
bd rightside.txt        //delete the no longer needed right buffer

This mostly works, but I'd like not have to block select the right side ahead of time, and ideally a better way to reference the right side buffer both to copy the text and close the buffer after. This is for a script that will split/rejoin a file right along the winwidth.

  • What did you try?
    – romainl
    Commented Mar 29 at 5:51
  • 1
    updated with what I have tried so far. Commented Mar 29 at 6:43

3 Answers 3


I would do:

  • :let &tw=&winwindth -1 set the text width to match the window width
  • ggVG select all
  • gq reformat introducing hard breaks
  • :wincmd w switch to the other window
  • :let &tw=&winwindth -1
  • ggVG
  • gq
  • :wincmd p switch back to the original window
  • ggCtrl vG$ select all in block mode
  • y yank
  • :q kill the window
  • ggCtrl vG select the first column
  • I Esc introduce 2 spaces
  • gg
  • P paste the content of the first window
  • 1
    The set commands don't make sense; you probably meant :let
    – D. Ben Knoble
    Commented Mar 29 at 13:41
  • 1
    Thank you. those let and windcmd options may do the trick. Will test and report back. Commented Mar 29 at 19:51
  • Thanks for your feedback :-) Commented Mar 29 at 19:54
  • 1
    Your solution slightly modified did exactly what I needed. Thank you. I posted the solution I ended up using. Commented Mar 30 at 21:43
  • Thanks for the feedback :-) Commented Mar 31 at 4:48

I would:

  1. disable Vim's "mouse" handling,
  2. select the relevant text with my "mouse",
  3. copy it with my terminal/system "copy" feature,
  4. open a new buffer in Vim,
  5. put the content from the system clipboard,
  6. remove the separators.

Something like:


  • That's a cool use of the mouse selection to bust through vim's idea of text selection. I should have mentioned that this is for a script that will operate on thousand line file so I'm looking for a solution without manual selection. I'll update the description. Commented Mar 29 at 16:23

Thanks to the other answers, was able to find a set of commands that does what I'm looking for:
Assume have the vertical split and focus in the left split.

:wincmd l     // move to right window
gg Ctrl v G$  // block select all of right buffer
y             // copy 
:wincmd h     // move back to left buffer
gg g$ l       // move one past last column in left window
p             // past contents of right buffer
0             // move to first column
:wincmd l     // move back to right window
:close        // close right window  
  • 1
    To avoid needing to know the direction, you can use C-w p (or :wincmd p) for « previous window ».
    – D. Ben Knoble
    Commented Mar 30 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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