I'm pretty new to writing stuff in my .vimrc, and I'm trying to understand how to use conditionals.

I'm using neovim. I'm trying to get (an enhanced version of) nvim's terminal emulator to launch in a split when I open nvim (unless I specify just one thing to open).

""" Split-Term terminal helpers
Plug 'vimlab/split-term.vim'
set splitbelow
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | 10Term | endif

This works. almost the way I expect. The terminal split opens and says

/bin/bash: -c: line 0: syntax error near unexpected token `|'
/bin/bash: -c: line 0: `| endif'

[Process exited 1]

Pretty clearly what's happening is the last couple words of the if-endif block are getting passed as additional arguments to Term (which it's documented as accepting, it's just that these aren't valid shell commands and they're not supposed to get treated that way).

In fact, if I leave off the | endif, then it really does work perfectly. Nvim doesn't yeild any kind of warning that I'm missing the endif. The only weirdness is that I start in insert mode, which isn't ideal and suggests that I really am doing something wrong.

What's the right way to do this?


The :Term command you are using does not support the -bar option so it will take | endif as an argument. You can overcome this with :execute

autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | execute '10Term' | endif

Regarding the final detail: I was starting nvim in Insert mode because one of the UX improvements offered by the Split-Term plugin is that new terminals start in Insert mode. It was unclear that this is what was happening because another plugin was starting after the Term, creating another split, and focus passed to that new split without leaving Insert mode.

Having already used Peter Rincker's fix for the other problem, this wasn't too hard to solve:

autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | execute '10Term' | stopinsert | endif

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.