5

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
  • 1
    Have a look at the different command modifiers, starting at :h :vertical Commented Apr 23, 2020 at 10:21

3 Answers 3

5

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.)

3
  • 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
    Commented Jul 21, 2020 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
    Commented Jul 21, 2020 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
    Commented Jul 22, 2020 at 2:38
1

You can use

:set splitright

combined with a command abbreviation like:

:ca term vert term

Splits will always open on the right; term will always shortcut to vert term on the command line (this includes when using / and ?).

1
  • I can’t really recommend an abbreviation here like this; it should at least only affect the Ex prompt and not searches. I also highly recommend spelling out commands (and using :cnoreabbrev).
    – D. Ben Knoble
    Commented Jan 11, 2022 at 13:38
0

You can use the following keys to move a window:

  • Control+L (to right),
  • Control+H (to left),
  • Control+K (to top),
  • Control+J (to bottom).

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.