Questions tagged [autocommand]

Vim autocommands are executed automatically by vim when certain events occur.

In the Vim text editor, the autocommand command is a way to specify that certain commands should be executed automatically in response to certain events, such as entering a window, or editing a file.

In vim, do :h autocmd.txt for detailed help on using autocomands.

17 questions
4
votes
1 answer

Vim: Use "if" in augroup?

I just want to define an autocommand that executes some external commands. For example, delete some auto-generated files after compilation. I work on both Windows and Linux, and the external commands used are different on these two…
hubanya
  • 39
  • 3
2
votes
2 answers

Open a buffer on a new Tab on Vim

I'm creating a Vim plugin that I need intercept when a new buffer is loaded. The basic idea consists in when I open a new buffer this new buffer must be screened on another tab, and the previous tab must keep the previous buffer loaded. Eg.: I have…
Samuel Simões
  • 141
  • 1
  • 2
  • 13
2
votes
0 answers

Vim: opening new buffer changes file

I think I observe a weird behaviour in Vim autocommands, in which opening a new buffer changes the result of past commands (!). Here is a simple example (VIM 7.3 2010 Aug 15). I just created a file test containing only the line 'disk version', then…
Circonflexe
  • 351
  • 1
  • 9
2
votes
2 answers

Autocommand for new file of specific filetype

I want to run some vim commands anytime I create a new file of a specific file type, sort of combination of the BufNewFile and FileType autocommand events. I have BufNewFile autocommands setup in filetype.vim to set the filetype based on the file…
brianmearns
  • 9,581
  • 10
  • 52
  • 79
1
vote
1 answer

vimscript - catching window resize automatically (with autocommand or not)

So, I was trying to write an autocommand that would fire every time window is resized (not the Vim window entirely, a CTRL-W window). As there is no dedicated event, i tried using OptionSet with different windows' sizes options, but that obviously…
Anton Tretyakov
  • 303
  • 1
  • 9
1
vote
1 answer

How do I run an autocommand on every filetype but one?

I have my vim set up to save files whenever I change buffers and on checktime. The problem is that I use Netrw and end up saving Netrw buffers. Can I run an autocommand on every type of file except netrw?
Jonathan
  • 539
  • 4
  • 15
1
vote
2 answers

Vim Error E20 'Mark not set' when running BuffWrite Command

I set up an auto run script in my vimrc to condense any block of 3 or more empty newlines down to 3 newlines. I set a mark so after the script executes, I retain my cursor position but I'm getting an E20 Mark not set error when the cursor is within…
Brian Egizi
  • 13
  • 1
  • 4
1
vote
1 answer

How to call a function when text is wrapped in vim?

In vim I want to visually make transparent the space I have to write a text in markdown. I use hard wrapping with textwidth=79. I know by some calculation that I'll have 20 lines for a chapter for example. So, what I do is inserting 20 empty lines…
Cutú Chiqueño
  • 855
  • 1
  • 10
  • 24
1
vote
1 answer

In vim, how does one apply autocommands for a filetype to a region of a file?

I've got a kind of polyglot filetype that can have embedded C, python, ruby, etc in it (think 'wiki page' if it helps). Is there a way to execute the autocommands for a known filetype on a region of the file? For example, I might have: #!bash if [ a…
pjz
  • 41,842
  • 6
  • 48
  • 60
0
votes
1 answer

Vim how to leave cursor at the end of the line after autocommand

I'm trying to make my own snippets in pure vimscript using autocommands. I want to make it so that after I type a specific character sequence, it is replaced by another character sequence. I made one like this, that replaces "hello" with "bye" when…
0
votes
2 answers

vimscript - reliable way of checking win and buf type of a new window with autocommands

So, I faced a need to check a type of a window and a buffer when entering a new window so I can do some stuff automatically depending on the types of aforementioned stuff. For example, when quickfix is opened, I need to know that it is it, the same…
Anton Tretyakov
  • 303
  • 1
  • 9
0
votes
1 answer

.vimrc autocommand if NOT filetype

I have a master .vimrc that sets up my global working environment, including special setup for both C++ and Python filetypes. In a project folder I have an .exrc with project-specific settings for C++, but this is overriding my master .vimrc…
Alcamtar
  • 1,478
  • 13
  • 19
0
votes
0 answers

How to start every opening of a file on some text label

I would like for my vim (actually, neovim) to jump always to a label I leave in the text (or the first one, if there is more than one). So, I have setup this autocommand: au BufNewFile,BufRead * call search('\$\$\$') and hope that it would work.…
mcepl
  • 2,688
  • 1
  • 23
  • 38
0
votes
1 answer

How can I auto-format a git mailmap file on save in Vim?

I use mailmap files for some git repos. The lines in the files can be in one of these formats: Proper Name Proper Name Proper Name Commit…
planetp
  • 14,248
  • 20
  • 86
  • 160
0
votes
0 answers

Why does my `au bufadd` prevent Vim from opening multiple files?

So, I've had the following chunk in my vimrc for a few years: " This toggles the hilighting of trailing-whitespace. fun! ToggleExtraWhitespace() if exists('b:ews') && b:ews == 1 "echom "Disabling trailing-whitespace hilighting in"…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
1
2