Questions tagged [autocmd]

Vim commands you can specify to be executed automatically when reading or writing a file, when entering or leaving a buffer or window, and when exiting Vim

Vim's documentation on autocmd: http://vimdoc.sourceforge.net/htmldoc/autocmd.html

113 questions
6
votes
2 answers

Run the CommandTFlush command when a new file is written

I'm trying to make Vim run the command 'CommandTFlush' whenever a new file is writte. For those not using the Command-T plugin, the 'CommandTFlush' command is used to rebuild an index of files in the current directory. What I want to do is run the…
peterfarsinsen
  • 101
  • 1
  • 5
6
votes
2 answers

vim + c++: insert a uuid in a guard clause

I'm trying to automate file comment headers. I'm stuck trying to figure out how to insert the result of the uuidgen command into my header using vim's autocmd. Inside the header, the placeholder text is present, like this: #ifndef _UUID_ #define…
J. Polfer
  • 12,251
  • 10
  • 54
  • 83
6
votes
2 answers

autocmd function always executed twice

I put together the following pile of awesomeness: if !exists("g:AsciidocAutoSave") let g:AsciidocAutoSave = 0 endif fun! AsciidocRefresh() if g:AsciidocAutoSave == 1 execute 'write' execute 'silent !asciidoc -b html5 -a icons "%"' …
Profpatsch
  • 4,918
  • 5
  • 27
  • 32
6
votes
3 answers

Vim: Combining autocmd?

I need to do the logical-and of two autocmd events in vim. Basically, the command has to run on an InsertLeave when the FileType is tex. It seems like this should work (in a .vimrc): autocmd FileType tex :autocmd InsertLeave :w But it doesn't. The…
Paul Biggar
  • 27,579
  • 21
  • 99
  • 152
5
votes
2 answers

Vim - How to insert a backslash at the start of a line in a new file using autocmd and a template file

I followed this guide to automatically insert different header templates into new files of different types based on the file extension: http://www.thegeekstuff.com/2008/12/vi-and-vim-autocommand-3-steps-to-add-custom-header-to-your-file/ It works…
5
votes
1 answer

How do you use buffer-local autocommands in VimScript?

I'm trying to write a snippet of VimL to allow the user to toggle the hilighting of unwanted trailing whitespace with a hotkey. (This is my first-ever Vim script, beyond copy-pasting things into my .vimrc, so … grain of salt :P) I wish for the ‘are…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
5
votes
2 answers

vim autocommand on buffer load/file open?

I'm trying to execute an autocommand when a file (buffer?) is opened in vim that will display indentation guides by executing ig. I'm using the vundle plugin nathanaelkane/vim-indent-guides I currently am trying autocmd BufWinEnter
Nat Dempkowski
  • 2,331
  • 1
  • 19
  • 36
4
votes
2 answers

Vim autocommand trigger on opening "nothing"

I want vim to open up the :Explorer when no file is opened or created. Eg. when I call vim without any options. calling vim newfile.txt should still behave the normal way though. How would I go about doing this? I can't seem to find the correct…
romeovs
  • 5,785
  • 9
  • 43
  • 74
4
votes
1 answer

Vim Buffer has been modified

I am trying to implement an AutoCmd in Vim that needs to be executed when the current buffer has been modified. I have read through all the events available for AutoCmd in the docs but could not find something that would help determine when a buffer…
alfredodeza
  • 5,058
  • 4
  • 35
  • 44
4
votes
4 answers

How do I set an autocmd in the vimrc to only run with specific filetypes?

The Explanation: Recently I acquired a .vimrc file from a git repository, and have found it incredibly useful so far. One of the useful tools that came with it is that it automatically deletes trailing white space when you write the file. However, I…
kirypto
  • 129
  • 2
  • 14
4
votes
1 answer

Vimscript: Trigger when cursor moved between lines

I need a autocmd trigger to use when the cursor moves between lines. Now I'm using: :autocmd CursorMoved * call MyFunc() With it, MyFunc is executed in each cursor movement, but I need a trigger only when cursor move up or down (not right and…
Antonio
  • 91
  • 1
  • 7
4
votes
2 answers

Call a function in Vim’s `autocmd` command

I want to use the expand function in an autocmd. In particular, I am adapting a tip by Paul Biggar and I wanted to use the following auto command in my .gvimrc: autocmd FileType tex set makeprg=rubber-info\ expand("%:t:r").log – Which of course…
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
3
votes
1 answer

autocmd event for MenuPopup in Vim

Objective Map k and j to and during ins-completion, like so: autocmd MenuPopup inoremap k autocmd MenuPopup inoremap j And undo the temporary mapping when the MenuPopup is gone: autocmd MenuPopupGone iunmap k autocmd…
Kit
  • 30,365
  • 39
  • 105
  • 149
3
votes
1 answer

Jump to last position when using vim netrw to open a file

I am looking to jump automatically to the last position in any file that I open. I have in my ~/.vimrc file: autocmd BufReadPost * …
anti-destin
  • 799
  • 1
  • 8
  • 19
3
votes
0 answers

vim is really slow to start and slow to quit

Okay I need help. For some reason, vim has been really slow to start since a couple of days. I investigated this and I saw that it was probably because of my .vimrc file. for instance here they suggest to put autocmd lines inside an augroup…
julio514
  • 181
  • 1
  • 1
  • 13