9

I like to use the vim embedded terminal, but I do not know how I could adjust its height. Sometimes, I need it to be lower so that I could concentrate on my editor how could I adjust it ?

3
  • 2
    :h window-resize Commented Sep 13, 2018 at 8:51
  • @ChristianBrabandt Sorry, I do not quite understand the meanings of the doc, would show me with an example, if I would like to adjust the terminal height to 20 row ? Commented Sep 13, 2018 at 8:55
  • 2
    @coincheung From inside the terminal, press <Ctrl-W> N to enter terminal-normal mode. Then use the standard window-resizing commands to change the window. e.g. 10<Ctrl-W>_ or :res 10. Then press i or a to get back into regular terminal mode.
    – Rich
    Commented Sep 13, 2018 at 13:26

4 Answers 4

6
:h termwinsize

You need to set termwinsize option. It's argument like {row}x{columns}. So if you want your terminal appear 30 row and 200 column, you should use:

:set termwinsize=30x200
3
  • The OP asked to change the terminal height only. :help termwinsize specifies that the format is written as "{rows}x{columns}" and that "when columns is zero then use the width of the window." For example to get a terminal buffer with 10 lines only, enter :set termwinsize=10x0. Commented Jan 11, 2021 at 12:46
  • @PaulRougieux Does the width, height of Neovim's vim.fn.jobstart the same idea as you had described? Commented Feb 26, 2023 at 18:37
  • @job_start I don't know, I use vim only. Commented Feb 27, 2023 at 15:34
6

To open a terminal for running command with height 20 you can do

:new +resize20 term://command

If the terminal is ready created, you either use :resize 20 or 20<c-w>_ for height. :vertical resize 20 or 20<c-w>| for width.

1
  • :20sp term://command and :80vs term://command
    – rofrol
    Commented Jan 2, 2020 at 15:54
2

There are several options:

(1) The simple way is to drag the bar separating the two split windows using the mouse. As far as I know this works by default, but I've only been using neovim, not standard vim so you may need to enable the mouse first.

(2) In normal mode, type 10<C-W>+ to increase the size of the current split by 10 lines. Or make a binding for this, e.g. nmap <Leader>b 10<C-W>+<CR> (b for bigger; Leader is \ by default but should be rebound to space in my opinion)

(3) A more automatic solution to the problem of the current split being too small is to add this to your vimrc:

set winheight=38

This will make the currently active window 38 lines tall, with the terminal filling the remaining space. But when you switch to the terminal, this is swapped around so that you can see the command output better.

5
  • It does not work since the height of the upper window may affect the terminal height. Commented Sep 13, 2018 at 11:54
  • which of the options does not work, and what unexpected result do you get? Commented Sep 13, 2018 at 12:50
  • 1
    You can also use the ++rows option to specify height, e.g. :terminal ++rows=10. See :h :terminal Commented Sep 13, 2018 at 14:33
  • Note if you are considering option 3, perhaps vim-maximizer bound to \ is a better option. Commented Oct 5, 2021 at 8:09
  • With winheight set, is there a way to set the unfocused window default height? I would like my terminal to be there with a height of, say, 1 row. Commented Dec 9, 2021 at 11:07
0

To enforce a default height when running a vanilla :term ex command, you can add the following to your vimrc:

autocmd TerminalWinOpen *
  \ if &buftype == 'terminal' |
  \   resize 10 |
  \   setlocal termwinsize=0x140 |
  \   setlocal nowrap |
  \ endif

The other setlocal commands are optional, but helpful to make sure the terminal doesn't wrap.

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.