I could create a terminal with vim by running :term in the vim normal mode. However, this terminal is opened at the top of the window and I would like to open it in the bottom. How could I open it at the bottom? By the way, how could I change the height of this window?
3 Answers
This question is a couple of years old now but I found it when I was looking for a way to open a terminal inside vim below a bunch of vertical splits. What I want looks something like this:
+----+----+----+ ¦ ¦ ¦ ¦ ¦ f1 ¦ f2 ¦ f3 ¦ +----+----+----+ ¦ terminal ¦ +--------------+ What you get with :below terminal or with :set splitbelow and then :terminal is:
+----+----+----+ ¦ f1 ¦ ¦ ¦ ¦ ¦ ¦ ¦ +----+ f2 ¦ f3 ¦ ¦term¦ ¦ ¦ +----+----+----+ After a bunch of googling, I pieced this together. To get what I want above is actually pretty simple. Type :botright terminal or :bo term. (See :help :botright for more details.)
You can save a few keystrokes by putting this in your vimrc:
" open terminal below all splits cabbrev bterm bo term Then just type :bterm to open a terminal at the bottom.
I hope someone finds this useful.
- Welcome to Vi and Vim and thanks for writing the answer! I did some small edits, please suggest a further edit if you disagree with any of the changes... Again, welcome!filbranden– filbranden2020-07-10 04:16:23 +00:00Commented Jul 10, 2020 at 4:16
- 2Better might be
:command Bterm botright terminal—the abbreviation also triggers when searching, where the command does not.D. Ben Knoble– D. Ben Knoble2020-07-10 12:18:25 +00:00Commented Jul 10, 2020 at 12:18
In your ~/.vimrc add the line
set splitbelow This will cause all splits to happen below (including terminal).
To change the height of the terminal (row x col)
set termwinsize=10x0 " 'termsize' didn't work - this did for me (GVIM 8.2) - Thanks a lot, how could I change the height of the terminal, and I seem to observe that I could not copy contents in the vim-terminal as I did in pure terminal ?coin cheung– coin cheung2018-07-20 03:35:24 +00:00Commented Jul 20, 2018 at 3:35
- Read
:help termwinsizeto answer the first question. It will tell you how to modify that. You can always look up things by:help commandin this casetermand scroll. For the second I don't actually know the answer but the help page would likely help.MaybeALlama– MaybeALlama2018-07-20 14:08:53 +00:00Commented Jul 20, 2018 at 14:08 - I tried but failed before I asked. I simply add the following lines in my vimrc:
set termwinsize = "10*0"and when I open vim and run command:ter, the terminal still occupies half the screen. What mistake did I made then?coin cheung– coin cheung2018-07-21 02:34:52 +00:00Commented Jul 21, 2018 at 2:34 - 3See also the
:belowcommand, e.g.:below terminalRich– Rich2018-09-13 13:15:17 +00:00Commented Sep 13, 2018 at 13:15 - @coincheung
10*0means at least ten rows high. If you want 10 rows exactly, try:set termwinsize=10x0.Rich– Rich2018-09-13 13:17:44 +00:00Commented Sep 13, 2018 at 13:17
I wanted a way to easily toggle a single terminal that would keep the same size and content.
My solution lies in two functions: the main one controls whether a terminal should be opened, the second opens a terminal split where we want on the screen.
If one or more terminal splits exist, they are hidden. Else, a terminal split is opened, either a new one or the first hidden terminal.
function! PutTermPanel(buf, side, size) abort " new term if no buffer if a:buf == 0 term else execute "sp" bufname(a:buf) endif " default side if wrong argument if stridx("hjklHJKL", a:side) == -1 execute "wincmd" "J" else execute "wincmd" a:side endif " horizontal split resize if stridx("jkJK", a:side) >= 0 if ! a:size > 0 resize 6 else execute "resize" a:size endif return endif " vertical split resize if stridx("hlHL", a:side) >= 0 if ! a:size > 0 vertical resize 6 else execute "vertical resize" a:size endif endif endfunction function! s:ToggleTerminal(side, size) abort let tpbl=[] let closed = 0 let tpbl = tabpagebuflist() " hide visible terminals for buf in filter(range(1, bufnr('$')), 'bufexists(bufname(v:val)) && index(tpbl, v:val)>=0') if getbufvar(buf, '&buftype') ==? 'terminal' silent execute bufwinnr(buf) . "hide" let closed += 1 endif endfor if closed > 0 return endif " open first hidden terminal for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)<0') if getbufvar(buf, '&buftype') ==? 'terminal' call PutTermPanel(buf, a:side, a:size) return endif endfor " open new terminal call PutTermPanel(0, a:side, a:size) endfunction " Toggle terminal - bottom nnoremap <silent> yot :call <SID>ToggleTerminal('J', 6)<CR> " Toggle terminal - right nnoremap <silent> yo<c-t> :call <SID>ToggleTerminal('L', 60)<CR>
:help window-resizeand read up on thecomand modifiers, start reading at:help :vertical:termdoesn't open terminals in split buffer; I don't know about vim. And you could look atsplitbelowoption.