I want to setup vim to behave like a traditional ide for the most part. What I would like to do is when I type the command vim it opens up this way:

Vim window

The problem is it opens this way:

vim demo

I would like the terminal to auto-start, but in the previous window. I've tried to read the docs, but I"m not to informed on how to read the documentation and put it into code, most of the code in my vimrc is copy-pasted and some of the basics I already knew. I would like to have it auto-start like in the first picture.

Also, one more question I'm not sure is possible in vim, sometimes in NetRW when I click away the buffer would erase the directory tree and then a blank buffer will appear. Is there anyway of disabling certain commands from interfering with the terminal buffer and dir tree listing? An example is if I try to open a file and the last buffer was the terminal buffer it will ask me do i want to save the current buffer (terminal) and open the file, I would like it to be smarter in open it in the non-terminal buffer rather than the terminal. Basically ignoring the terminal all together besides entering commands.

Here is my vimrc, probably a mess since I did nothing but copy and pasting:

set mouse=a
set number
imap jj <Esc>
set autochdir
map <Tab> <C-W>W:cd %:p:h<CR>:<CR>
map <C-l> :q!<CR>
map <C-t> :term bash<CR>
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'

" Initialize plugin system
call plug#end()

function! NetrwOpenMultiTab(current_line,...) range
   " Get the number of lines.
   let n_lines =  a:lastline - a:firstline + 1

   " This is the command to be built up.
   let command = "normal "

   " Iterator.
   let i = 1

   " Virtually iterate over each line and build the command.
   while i < n_lines
      let command .= "tgT:" . ( a:firstline + i ) . "\<CR>:+tabmove\<CR>"
      let i += 1
   let command .= "tgT"

   " Restore the Explore tab position.
   if i != 1
      let command .= ":tabmove -" . ( n_lines - 1 ) . "\<CR>"

   " Restore the previous cursor line.
   let command .= ":" . a:current_line  . "\<CR>"

   " Check function arguments
   if a:0 > 0
      if a:1 > 0 && a:1 <= n_lines
         " The current tab is for the nth file.
         let command .= ( tabpagenr() + a:1 ) . "gt"
         " The current tab is for the last selected file.
         let command .= (tabpagenr() + n_lines) . "gt"
   " The current tab is for the Explore tab by default.

   " Execute the custom command.
   execute command

" Define mappings.
augroup NetrwOpenMultiTabGroup
   autocmd Filetype netrw vnoremap <buffer> <silent> <expr> t ":call NetrwOpenMultiTab(" . line(".") . "," . "v:count)\<CR>"
   autocmd Filetype netrw vnoremap <buffer> <silent> <expr> T ":call NetrwOpenMultiTab(" . line(".") . "," . (( v:count == 0) ? '' : v:count) . ")\<CR>"
augroup END

" Toggle Vexplore with Ctrl-E
function! ToggleVExplorer()
  if exists("t:expl_buf_num")
      let expl_win_num = bufwinnr(t:expl_buf_num)
      if expl_win_num != -1
          let cur_win_nr = winnr()
          exec expl_win_num . 'wincmd w'
          exec cur_win_nr . 'wincmd w'
          unlet t:expl_buf_num
          unlet t:expl_buf_num
      exec '1wincmd w'
      let t:expl_buf_num = bufnr("%")

" NeTRW Explorer Settings

let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 15
augroup ProjectDrawer
  autocmd VimEnter * :Vexplore
augroup END
map <silent> <C-n> :Vexplore<CR>

" Per default, netrw leaves unmodified buffers open. This autocommand
" deletes netrw's buffer once it's hidden (using ':q', for example)
autocmd FileType netrw setl bufhidden=delete
autocmd TabNew * call feedkeys(":Vexplore\<CR>", 'n')

" terminal split below
set splitbelow
autocmd VimEnter * :term bash

1 Answer 1


Use this autocmd instead:

autocmd VimEnter *
    \ Vexplore |
    \ execute "wincmd l" |
    \ rightbelow term bash

This will execute the whole sequence once, as you enter Vim. I'm using line continuations (follow up lines start with a backslash) and bars to run multiple commands. Note also that autocmd runs Ex commands, so preceding commands with : is not really necessary.

The first command will open the NERDTree window, on the left, as expected.

Second, wincmd l will move to the window on the right (see :help :wincmd). That's the step missing from your attempt, which is causing the next step to split the NERDTree rather than the main window. The wincmd needs to run inside an execute, because otherwise it will try to interpret the | that follows it, which will stop working as a separator.

Finally, the last command opens the terminal, using an explicit rightbelow (see :help :rightbelow) to open this split on the bottom. That's it!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .