vim autocommand on buffer load/file open?
Asked Answered
B

2

5

I'm trying to execute an autocommand when a file (buffer?) is opened in vim that will display indentation guides by executing <Leader>ig. I'm using the vundle plugin nathanaelkane/vim-indent-guides

I currently am trying autocmd BufWinEnter <Leader> ig, but that doesn't seem to be working. I've also tried with <Leader>ig.

What do I need to change to make this work?

Buote answered 21/2, 2014 at 21:38 Comment(0)
M
11

vim-indent-guides provides the :IndentGuidesEnable function. You can execute this each time you open a file by adding the following to your .vimrc

autocmd BufReadPre,FileReadPre * :IndentGuidesEnable
Marcum answered 21/2, 2014 at 22:2 Comment(1)
There's also BufReadPost and FileReadPost if you want to make sure the file's contents have been read first.Ezarra
F
1

If you want to add normal mode command to autocmd, you could use normal or exec like:

autocmd SomeEvent exec 'normal ' . (exists('mapleader')?mapleader:'\') . 'ig'

I didn't test above line, should work for your case.

Better way I think is, find out what does <Leader>ig mapped to, it could be a function, call the function in your autocmd.

Farny answered 21/2, 2014 at 21:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.