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
2
votes
1 answer

vim autocmd BufNewfile executed multiple times

My ~/.vimrc contains only so ~/config/vim/vimrc ~/config/vim/vimrc contains usual options, few mappings and source files for different filetype, I've got : autocmd FileType cpp so ~/config/vim/filetype/cpp.vimrc And in that file, I have defined…
Gaut
  • 1,255
  • 2
  • 15
  • 33
2
votes
1 answer

Clear search highlight on autocmd BufWrite

I tried most of the suggestions in those three questions: Get rid of Vim's highlight after searching text How to get rid of search highlight in Vim Vim clear last search highlighting It's mainly the :noh, and it works when I type it manually. I just…
Al.G.
  • 4,327
  • 6
  • 31
  • 56
2
votes
1 answer

How would you switch to the previous window using vim autocmd

I use NERDTree and have it set to automatically open when I open vim, but that causes the NERDTree window to be the one selected, which isn't what I want. I want to be able to go right into editing the file I opened, but autocmd vimenter *…
Ashen
  • 23
  • 4
2
votes
3 answers

Disable syntax highlighting for certain filenames

I have syntax highlighting enabled in .vimrc, but that makes loading certain files too long. So I need to disable (or, to be precise, not enable... enabling it and then disabling is not a solution) syntax highlighting for these files. I tried au…
PhilippFrank
  • 143
  • 1
  • 4
2
votes
2 answers

Vim autocmd based on file contents

I'm trying to set up Vim to detect when a .tex file contains the command '\usepackage{sagemath}', and run a command accordingly. I've gotten to :au BufReadPost,BufWritePost *.tex TTarget sagepdf but that will fire for all .tex files, which isn't…
sethjust
  • 118
  • 7
2
votes
4 answers

Toggle NERDCommenter to Alternative Value Based on File Type

I'd like to configure NERDCommenter in vim to use the alternative comment styles for certain file types. What is the correct way to do this. I can't figure out how to call into the plugin code from the autocmd. What I'm trying to do is something…
cmcginty
  • 113,384
  • 42
  • 163
  • 163
1
vote
1 answer

Vim autocmd to apply a user defined command to multiple specific (by filetype) tabpages?

I open my Vim session with multiple tabpages simultaneously. Some of my tabpages are .txt files, some are not. I have created, in my .vimrc, a command named Tran which refers to syntax.vim where are defined a few specific syntax highlightings for my…
ThG
  • 2,361
  • 4
  • 22
  • 33
1
vote
2 answers

syntax highlighting autocmd is not working in neovim

I am new to vim and esp. in lua scripting. I want to create an autocmd such that all the jinja files will get yaml syntax highlighting. local a = vim.api a.nvim_create_autocmd( { "BufNewFile", "BufRead" }, { pattern = { "*.j2" }, command = [[…
DDStackoverflow
  • 505
  • 1
  • 11
  • 26
1
vote
1 answer

autocmd does not detect *.ott files

I'd like to have syntax highlighting on files with the .ott extension (using ott-vim), but I am not getting any colors when opening a file, even though filetype=ott is set. Re-setting set filetype=ott manually does enable the colors again. Oddly…
Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56
1
vote
1 answer

Vim: BufNewFile autocmd does not work when inside filetype plugin

Background story: I want vim to generate a public class declaration when editing new java files, so I wrote the following augroup: augroup generate_public_class_declaration_upon_creation au! autocmd BufNewFile *.java execute "normal! ipublic…
Futarimiti
  • 551
  • 2
  • 18
1
vote
2 answers

vim: automatic date/timetamp when opening a specific file?

I would like help with my vim script. thus far I am able to check for the file name, however, I have been unsuccessful in learning how to give normal mode commands via vim script. here is what I've got: autocmd VimEnter * if @% == 'diary.md' | :r! |…
Rokiora
  • 21
  • 5
1
vote
1 answer

Is there an autocmd-event that works on unmodified buffer with :x, but not :q

I want to autorun formatter when saving a file. Using BufWritePre doesn't work when quitting with :x (or ZZ), if the file hasn't yet been modified. ExitPre or QuitPre don't work either.
Kljunas2
  • 56
  • 1
  • 6
1
vote
1 answer

Vim: disable autocmd BufRead (modeline)

From this answer I executed: :set modeline | doautocmd BufRead Since then, I cannot disable the BufRead. I can open a file and unset the modeline: :set nomodeline :e! :wq But when I reopen the same file, its modeline is again auto executed. I…
Xopi García
  • 359
  • 1
  • 2
  • 9
1
vote
1 answer

How to list autocmd groups in Vim?

In my .vimrc I want to define several autocmd groups. Also, I want to avoid conflicts with any pre-existing groups. How can I list currently defined groups in Vim?
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
1
vote
0 answers

How can I determine whether the current window in Vim was opened in a new tab?

In Vim, I use the Startify plugin. There's a few ways to open new Vim tabs with this plugin; and I would like to configure my Vim to ensure that :tcd %:h is executed automatically for the first buffer opened into a new Tab after executing…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78