:hi Vertsplit doesn't run on autocmd from init.vim

280 views Asked by At

I've been setting up my init.vim file to use NeoVim on Windows 10, and ran into an issue I'm struggling to understand.

At the start of my file, I set up a couple of :hi(ghlight) autocmds, and only the VertSplit seems to be ignored on starting. Even worse, I can run the command in the vim cmd bar and it'll work just fine.

Here's a snippet:

set wildmenu
set wildmode=longest:full,full  " get bash-like tab completions
"set cc=120                   " set an 80 column border for good coding style
filetype plugin indent on   " allows auto-indenting depending on file type
set tabstop=4               " number of columns occupied by a tab character
set shiftwidth=4            " width for autoindents
set softtabstop=4           " see multiple spaces as tabstops so <BS> does the right thing
set number
set mouse=a
set undofile
set cursorline
set splitright

autocmd VimEnter :set laststatus 3<CR>
" THIS WORKS
autocmd VimEnter :hi CursorLine cterm=None guifg=#5c6773<CR>
" THIS DOESNT
autocmd VimEnter :hi VertSplit cterm=None guifg=#5c6773<CR>

Any help/advice on this? I've been googling but can't find anything about VertSplit or similar. Can also post the full conf if needed.

Thanks in advance!

1

There are 1 answers

0
romainl On BEST ANSWER

It's really not a matter of googling. It's a matter of studying the documentation for the thing you are about to use and then, applying what you learned.

First, an autocommand is supposed to be made of at least these elements:

autocmd <event> <pattern> <command to execute when the pattern matches>

but you didn't specify a pattern for any of your three autocommands. This is easily fixable:

autocmd VimEnter * :set laststatus 3<CR>
autocmd VimEnter * :hi CursorLine cterm=None guifg=#5c6773<CR>
autocmd VimEnter * :hi VertSplit cterm=None guifg=#5c6773<CR>

Second, the <command> part is always an Ex command so you can drop the useless colon:

autocmd VimEnter * set laststatus 3<CR>
autocmd VimEnter * hi CursorLine cterm=None guifg=#5c6773<CR>
autocmd VimEnter * hi VertSplit cterm=None guifg=#5c6773<CR>

and the useless—and very likely to cause errors down the line—<CR>, which is really only useful in normal mode mappings:

autocmd VimEnter * set laststatus 3
autocmd VimEnter * hi CursorLine cterm=None guifg=#5c6773
autocmd VimEnter * hi VertSplit cterm=None guifg=#5c6773

Now that your autocommands actually look like autocommands, you should address the last remaining issue: set laststatus 3, which:

  1. prints the current value of laststatus,
  2. throws an "Unknown option" error for 3.

Number options are set like this:

set optionname=999

so set laststatus 3 should be:

set laststatus=3

Which leaves you with this mostly correct (and working, at least in my Vim) snippet:

autocmd VimEnter * set laststatus=3
autocmd VimEnter * hi CursorLine cterm=None guifg=#5c6773
autocmd VimEnter * hi VertSplit cterm=None guifg=#5c6773