I majorly use vim over an ssh session using putty. Sometimes I may have to copy code from ssh in a vim session but it's not very convenient. I do the following :

:set nu!

This close all splits that I have.

Is there a way just for me to expand the current window to the whole screen temporarily and recover all closed splits afterward?

  • Could you give some screen shots so we can see how it 'breaks' your layout please ? :)
    – nobe4
    Aug 21, 2015 at 15:08
  • @Nobe4 the layout is random. i split windows all the time. by having <C-w>o only current window remains, so i lost the view of multiple files. i am expecting recover to whatever layout after i copy the text i need
    – Jason Hu
    Aug 21, 2015 at 15:10
  • you could define a function that cleans your display and another one that restores it ... Have you tried searching this way ? Writing vim function is an excellent way to learn :)
    – nobe4
    Aug 21, 2015 at 15:18
  • @Nobe4 but how. i know it's not a one command existing solution but i will need a guideline at least.
    – Jason Hu
    Aug 21, 2015 at 16:38

4 Answers 4


Here is a safer way to do what you are currently doing:

:tabe %|set nonu

Once you are done, close that tab page with :q to go back to the previous tab page.

--- edit ---

A similar workflow for transient buffers:

:tabnew|set nonu|b#

--- endedit ---

That said, you should probably try "X forwarding" which allows you to share clipboard over the wire:

$ ssh -X ...

See $ man ssh.

  • thanks. i see the sense here. btw, sorry for the confusion, but i really meant using putty.
    – Jason Hu
    Aug 21, 2015 at 20:17
  • 1
    PuTTY can do X forwarding: tartarus.org/~simon/putty-snapshots/htmldoc/…
    – romainl
    Aug 21, 2015 at 20:23
  • Just out of curiosity: is there a way to do that with an unwritten buffer? (I can use % if the buffer wasn't written once before). Also +1 for X forwarding.
    – statox
    Aug 22, 2015 at 22:10
  • @statox, you can use :tabnew|b#.
    – romainl
    Aug 22, 2015 at 22:21

You could use sessions if you don't feel like creating a function (:h view-sessions)

Before closing your splits simple do

:mksession ~/tmp.session

This will save the current layout in the file ~/tmp.session (of course you can change the file path)

Then expand your window as you usually do and then use:

:source ~/tmp.session

which will restore the layout saved in the file.

Also you can even simplify it, knowing that without argument :mksession will create the file ~/Session.vim you can do the following:

nnoremap <key> :mksession<CR> :only<CR>

This mapping will save your session and "maximize" the current window.

Then create this mapping:

nnoremap <key> :source ~/Session.vim<CR>

to easily get your session back.

EDIT In the comments HuStmpHrr mentionned an issue with :mksession and NERDTree. Actually the problem comes from the way NERDTree creates its buffers: from what I have understood it actually creates a buffer, do some stuff, delete this buffer and create another one and do some stuff again (see this nobe4 answer mentionning this).

In my opinion the wiser is to do more or less like in this answer: closing NERDTree before making a session and opening it after restoring it.

A workaround could then be to create these functions:

function! MyMkSession(filePath)
    execute "mksession! " . a:filePath

function! MySoSession(filePath)
    execute "source " . a:filePath

And to use them instead of the built-in ones. That is neither clean or elegant but that could do the job.

  • i have problems with mksession since i use nerdtree. i have problems with general session managers, because these managers try to preserve all my key bindings, autocmds, commands, etc. however i don't really need. is there a nice way just to remember the layout of windows?
    – Jason Hu
    Aug 21, 2015 at 19:44
  • Uh I've struggled more than once with NerdTree on different topics, I'll see if I can find a workaround ;-)
    – statox
    Aug 22, 2015 at 10:11

As guidelines, I would do something like :

let splits={}

function! Clean()
  " Populate splits with the current splits

function! Restore()
  " Restore the splits from the variable splits

You can look at :h usr_41.txt that contains a lot of function you can call to get all informations you need.


bufname()       get the name of a specific buffer
winheight()     get height of a specific window
winwidth()      get width of a specific window

You can look up for dictionnaries here :h 'dictionary'.


Plugin ZoomWin

by Charles Campbell

This plugin remaps Ctrl-w o to do both: maximize and restore previous layout.

This plugin can be downloaded from two locations

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.