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?
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
+----+----+----+ ¦ 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.
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>