137

Invoking :help in Vim, I got the help manual page with split window. I want to maximize the help manual window and close the other window.

How can I do this? What is the Vim command to do this?

Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
cola
  • 12,198
  • 36
  • 105
  • 165
  • For people using NeoVim try: `vim.cmd("wincmd ...")`, where `wincmd` is equivalent to `` in Vim, and substitute `...` for `_`,`|`,`h`, ..., etc. Linked to an answer below: https://stackoverflow.com/a/29923368/5290519 – NeoZoom.lua Dec 24 '21 at 08:28

11 Answers11

166

You can employ Ctrl+WT (that's a capital T) to move any open window to its own tab.

As mentioned by others Ctrl+W_ / Ctrl+W| to maximize within the current tab/window layout (while respecting min height/width settings for various other windows).

(Ctrl+W= resizes all windows to equal size, respecting the minimum height/width settings)

Edit To the comment

  1. start vim (e.g. gvim /tmp/test.cpp)
  2. invoke help :help various-motions - opens a split window
  3. move help into separate tab maximized: C-wT
  4. enjoy reading the fine manual :)
  5. move the help back into the original tab:

    mAZZ<C-w>S`A
    
    • mA: set global mark A
    • ZZ: close help buffer/tab
    • C-wS: split original window
    • `A: jump to saved mark A

You can avoid using a mark for normal (non-help) buffers. Let me know if you're interested.

cmaher
  • 5,100
  • 1
  • 22
  • 34
sehe
  • 374,641
  • 47
  • 450
  • 633
  • 7
    After getting tab with CTRL+W T how can i get back to the original splitted windows ? – cola Oct 20 '11 at 12:42
  • 2
    @guru: just switch tabs as always (use `Ctrl-PgUp`, `Ctrl-PgDown` or `:tabnext`, `:tabprev`). To close the new (e.g. help) tab, use `ZZ`, `Ctrl-W, C`, `:q`, `:clo`, `:tabclose` or any other way you usually close windows/tabs – sehe Oct 20 '11 at 12:52
  • 2
    No, that was not the question. Suppose you have two tabs, now you want no tabs, you want that two buffers as splitted windows. Is there any one command to do this ? – cola Oct 20 '11 at 22:12
  • 1
    Editing question with general procedure. (_I wish to add that the tone of your comments may come across rather unfriendly. In written language, `"No, that was not the question"` may sound as a reprimand. I'm sure you don't mean it badly_) – sehe Oct 20 '11 at 22:21
  • @guru: answer is updated. It was a bit trickier than expected since help buffers are _special_ (and you cannot use `:sbuf` like I'd normally prefer). Hope this helps – sehe Oct 20 '11 at 22:29
  • That's the answer I was looking for! Whereas other options like `C-w O` close all windows except one, `C-w |` really mazimaze current window. – aryndin Sep 23 '19 at 20:12
97

With :help [topic] you open up a topic that interests you.
Ctrl-Wo will minimize the other windows (leaving only the help window open/maximized).
(Ctrl-Wo means holding Ctrl press W, and then o)

Rook
  • 60,248
  • 49
  • 165
  • 242
  • 42
    or , :only will do the job. – cola Oct 20 '11 at 03:47
  • 20
    From the editing file how can i get back to the help manual after doing CTRL+W o ? – cola Oct 20 '11 at 03:50
  • 4
    @guru: `C-w`, `^`, `:buf OtherFile.txt`, `:sbuf Otherfile.txt` etc. (see help for `wincmd`, `switchbuf` for details). The funy thing is that my (IMHO) _correct_ answer hadn't been given yet... – sehe Oct 20 '11 at 12:32
  • @sehe - Your answer suggest using tabs. Not only were tabs not in the question, good vim practice is usually avoiding them. – Rook Oct 20 '11 at 22:22
  • 2
    @ldigas: that is a (surprising) opinion. Unless you quote a reputable source, I'm going to hold that as your personal preference, really. I'm usually not using them, but I've recently found I'm using them for thigns like this (maximizing a sidebuffer temporarily; doing power stuff like having multiple disjoint side-by-side diffs in a single vim session). Tabs are also a usability miracle with `gvim --remote`. I'm always using `se guioptions=agim` though because I prefer console-like rendering of tabs. – sehe Oct 20 '11 at 22:32
  • @sehe - No it is (well, it is in a way, since everything is) not a personal preference. Vi/Vim was originally designed to work with the concept of buffers and windows. Tabs were added only later; Moolenaar was not expecially enthusiastic about them, but a lot of people demanded them, so in they went. You can find the relevant messages on Vim's archives (somewhere, if memory serves, around 2006 but I could be wrong by a year or two). But, I'm not saying they aren't practical sometimes, nor that you should shop or start (or whatever) using them. – Rook Oct 20 '11 at 23:50
  • 28
    this will close other windows, and if you have one or more windows where you have made changes and not saved, then this will not work - also I think question is about maximizing window to work for a short time in that state and then later on return to previous state -- by closing all windows then you will have to use your session file or manually open all other windows to get back – serup Aug 25 '16 at 06:59
  • I quote `JohnBeckett` which says *To open the current window in a new tab with the cursor in the same place, enter `:tab sp` which splits the current window into a new tab. To close the current window, press `Ctrl-W` then `c`.* That will close the newly opened tab.` from http://vim.wikia.com/wiki/Maximize_window_and_return_to_previous_split_structure – Fabrizio Bertoglio Oct 16 '18 at 08:18
  • `command! -nargs=1 -complete=help H h | only` . Setting this in your .vimrc let's you use `:H` as you normally would `:h`, but automatically does the `Ctrl-W-o` combo. – Patrick Aug 28 '20 at 09:55
63

You can expand a window to its maximum size using Ctrl+W_ (underscore). The final size of the expanded window will be constrained by the value of the winminheight option. When you close the help window, your previous window(s) will be restored to their former sizes.

sehe
  • 374,641
  • 47
  • 450
  • 633
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
27

I prefer to use tabs for that. Use

:tabedit %

to open a file maximized in a new tab, once you are done return to the old setup with all windows using

:tabclose

I find this the ideal solution as this works together with :cw and the Tagbar plugin. Taken from: vim.wikia

Azrael3000
  • 1,847
  • 12
  • 23
  • 1
    Thanks for this easy & simple suggestion! You can also just `:q` to close the tab once you're done with it to get back to your previous tab & layout – Nathan Wallace Mar 30 '21 at 17:58
15

I like to use 'M' to maximize and 'm' to minimize.

It won't look great as it'll shrink all the other open windows that are in the same buffer, but I found it to be more useful when dealing with tabs. So for instance, instead of opening a new tab for that file then having to close it after you're done with it or want to minimize it.

nnoremap <C-W>M <C-W>\| <C-W>_
nnoremap <C-W>m <C-W>=

The reason for nnoremap is that I don't care about recursive mapping, but just map should also work.

Gustavo Matias
  • 3,508
  • 3
  • 27
  • 30
  • 2
    If you use `nnoremap M \|_` (without the space after `|`), then the cursor won't move by 1 on each maximize. – rsanden Feb 11 '18 at 07:53
  • 2
    I like this using backslash (`nnoremap \ \|_`). It feels natural with the default bindings `|`, `_`, and `=`. – rsanden Feb 11 '18 at 07:54
8

Install the plugin vim-maximizer, then you can maximize the current window and restore with F3

Searene
  • 25,920
  • 39
  • 129
  • 186
7

You can get help window in full size without closing/resizing any other windows by using

tab help {topic}

This will open help window in a new tab, other windows will be left as-is (really resized so that tabline can be shown, but this is only one additional line above). You can close help as usual: at least :bw<CR> and <C-w>c work for me closing new tab as well.

ZyX
  • 52,536
  • 7
  • 114
  • 135
5

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

Hotschke
  • 9,402
  • 6
  • 46
  • 53
  • `v25n` can be found in [this repo](https://github.com/drn/zoomwin-vim/), and for `vim-plug` users, use: `Plug 'drn/zoomwin-vim'`. – llinfeng Jan 16 '22 at 15:49
3

Somehow the ZoomWin plugin did not work at all for me, I now see there are other plugins but I already wrote this and gives me the exact effect I wanted (with a minor quirk detailed below):

function! ToggleZoom(zoom)
  if exists("t:restore_zoom") && (a:zoom == v:true || t:restore_zoom.win != winnr())
      exec t:restore_zoom.cmd
      unlet t:restore_zoom
  elseif a:zoom
      let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
      exec "normal \<C-W>\|\<C-W>_"
  endif
endfunction

augroup restorezoom
    au WinEnter * silent! :call ToggleZoom(v:false)
augroup END
nnoremap <silent> <Leader>+ :call ToggleZoom(v:true)<CR>

Use the mapped key (Leader and + in my case) to toggle between maximized / previous layout. If you change to another split in the same tab, maximization turns off.

If you change tabs, the split stays maximized, although somehow it won't cover the complete full width anymore, with the width minimized windows gaining back some 4 columns or something. Anyway it works acceptably for me even with that minor quirk.

edit: somehow it works fine now, must've messed up in some way before.

ata
  • 2,045
  • 1
  • 14
  • 19
3

To get just the help up, then close the other window, do this: :helpCTRL-WCTRL-W:close. Then you'll have just the help up.

Jeff Ferland
  • 17,832
  • 7
  • 46
  • 76
1

in your .vimrc, just place

nmap - :res<CR>:vertical res<CR>$

When you want maximize current window, just press - in command mode. Press = when you want to restore the last status of multiple window

blessdyb
  • 49
  • 1