1

My ideal editing layout would look like this (in Gvim):

----------------------------------------------------------
|       |                      |                         |
|   N   |                                                |
|   E   |                      |                         |
|   R   |                Editing Area                    |
|   D   |-   -   -   -   -   -   -   -   -   -   -   -   |
|       |  (various splits, horizontal and/or vertical)  |
|   T   |                      |                         |
|   r   |                                                |
|   e   |                      |                         |
|   e   |------------------------------------------------|
|       |                                                |
|       | Terminal window (:terminal)                    |
|       |                                                |
|       |                                                |
----------------------------------------------------------

Note in particular:

  1. I want the terminal window to open at the bottom. Setting splitbelow might work for this, but it would affect all splits, not only the terminal window.
  2. I can move the terminal to the bottom with <C-W>J, but this puts it below NERDTree, requiring me to then toggle NERDTree.

I'm looking to create a mapping that will allow me to open a terminal and place it where indicated in my diagram. Any ideas?

2

We start with:

:bel terminal

When :bel[owright] is followed by a command that splits a window the new window is opened below the current one. That means we first need to get to the bottom right window of the existing layout and then do :bel. Ctrl-W b is how we'd go to the bottom right in Normal mode. The Ex command equivalent is :wincmd b.

Combining into a mapping...

:nnoremap <leader>t :wincmd b \| bel terminal<CR>
  • Thanks. The following mapping is a start: nmap <silent> <leader>s :belowright split terminal<CR>:terminal ++curwin ++close<CR><F2> (note that I'm explicitly using nmap so that I can use my tnoremap <F2> to set the size). However, it isn't exactly what I was looking for since if I'm using vertical splits, the terminal only appears below one of the splits instead of across all but the leftmost. – Scott Severance Jan 18 at 1:03
  • I think it would be easier, in that case, to use a mapping that does Ctrl-W J (or equivalent) on the terminal followed by Ctrl-W H on NERDTree rather than try to maneuver things around conditionally. – B Layer Jan 18 at 1:11
  • So you could use what I have in my answer, followed by :wincmd J | wincmd k | wincmd H....or something like that. (of course, you'd only do that conditionally...if there were a split on the left taking up full height). This is probably going to make more sense with a function rather than just in a mapping. Suggest you define very clearly what the "rules" are if you want that answered for y ou. – B Layer Jan 18 at 1:14
  • OK: Now I've got nmap <silent> <leader>s :wincmd b<CR>\t:belowright split terminal<CR><C-W>J10<C-W>_\t:wincmd b<CR>:terminal ++curwin ++close<CR>, which is good enough for now. (\t is <leader>t, my mapping to toggle NERDTree.) Thanks. – Scott Severance Jan 18 at 1:43
  • Oh, okay. so it's really just the NERDTree case you care about. For the heck of it I may spend a little time on a more general approach. If I come up with something I'll post it here. Cheers. – B Layer Jan 18 at 3:40
1

The following workflow commands can help me structure Vim windows like your desire.

1.Split below window

set splitbelow

2.Execute NERDTree

autocmd VimEnter * NERDTree

3.Change cursor to editor console

autocmd VimEnter * wincmd p

4.Open terminal

autocmd VimEnter * terminal

5.Switch to terminal window

autocmd VimEnter * wincmd k

6.Increase size of main editor console

autocmd VimEnter * 10 wincmd +

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.