1

I'm using vim 8 and I set a shortcut to open a terminal in my vim.

nnoremap <F5> :wa<CR> \| :term ++kill=term<CR>

It works except that it opens a terminal vertically as below:

--------------------
|        |some file|
|nerdtree|----------
|        |terminal |
--------------------

What I need is to put the terminal on the right side:

-----------------------------
|        |         |        |
|nerdtree|some file|terminal|
|        |         |        |
-----------------------------

How can I change the shortcut of <F5> to achieve this?

  • 1
    Have a look at the different command modifiers, starting at :h :vertical – Christian Brabandt Apr 23 at 10:21
2

Use the :vertical and :botright modifiers.

nnoremap <F5> :wa \| vertical botright term ++kill=term<CR>

Or:

nnoremap <F5> :wa<CR>:vertical botright term ++kill=term<CR>

(Also note that you need one of <CR> or \|, not both. Your original command ends up executing the Normal mode | motion, which moves the cursor to the first column, followed by a space that moves it to column two.)

| improve this answer | |
  • Now I'm working on Ubuntu 18.04 and ++kill=term gave me an error: Invalid attribute: kill. Do you know how to slove this? – Yves Jul 21 at 10:46
  • @Yves You might have an older version of Vim... Or are you on NeoVim? Can you upgrade to Ubuntu 20.04? Otherwise, search for a Ubuntu PPA with a newer Vim package... – filbranden Jul 21 at 14:51
  • 1
    Yea you are right, the verison of my vim in Ubuntu 18.04 is 8.0, instead of 8.2. I'll upgrade it. – Yves Jul 22 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.