Tips about the terminal of vim and neovim

We just update the shell layer of spacevim, but we found some differences between vim and neovim’s terminal. here is some tips I got today:

  1. how to open terminal in current window?

I use both neovim and vim, neovim implements +terminal before vim, and I have been used to it. In neovim, :te will open an terminal buffer in current windows, but in vim8 :term will open terminal in split window.

in vim8, if you want to open terminal in current windows, you can use :term ++curwin

2. how to automatically close window when terminal is closed?

if you open terminal buffer in an extra split window, after run command, and maybe you will press Ctrl+d to close terminal, but this will not close terminal windows by default. then you can start a terminal via:

:call term_start('bash', {'curwin' : 1, 'term_finish' : 'close'})

3. how to open terminal in specified eatra split window?

the problom is : I want to open an terminal on the topleft of current vim windows, then run command like git add . git commit -m "foo"and git push after command is finished, I want to press Ctrl+d to close terminal windows, just same as use ctrl+d in terminal emulator.

here is what I added to vimrc:

if has('nvim')
fu! OpenTerminal()
" open split windows on the topleft
topleft split
" resize the height of terminal windows to 30
resize 30
:terminal
endf
else
fu! OpenTerminal()
" open split windows on the topleft
topleft split
" resize the height of terminal windows to 30
resize 30
:call term_start('bash', {'curwin' : 1, 'term_finish' : 'close'})
endf
endif
nnoremap <F4> :call OpenTerminal()<cr>