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
95
votes
6 answers

Vim run autocmd on all filetypes EXCEPT

I have a Vim autocmd that removes trailing whitespace in files before write. I want this almost 100% of the time, but there are a few filetypes that I'd like it disabled. Conventional wisdom is to list the filetypes you want an autocmd to run…
jerodsanto
  • 9,726
  • 8
  • 29
  • 23
87
votes
2 answers

How to automatically execute a shell command after saving a file in Vim?

This is because I'd like to automatically run tests after each file save. I have looked at autocmd and BufWritePost but cannot make it work.
Running Turtle
  • 12,360
  • 20
  • 55
  • 73
34
votes
1 answer

Prevent Vim's autocmd from running on write just once

I have the following line in my .vimrc to automatically beautify js files after I save them: autocmd BufWritePost *.js :call JsBeautify() I want this 99% of the time, but sometimes I just want to write without having this function called. Is there…
Vlad the Impala
  • 15,572
  • 16
  • 81
  • 124
31
votes
2 answers

Using shorter textwidth in comments and docstrings

From the mighty PEP 8: [P]lease limit all lines to a maximum of 79 characters. For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended. When editing Python code in Vim, I set my textwidth to…
Eric Naeseth
  • 2,293
  • 2
  • 19
  • 18
17
votes
1 answer

How to prevent saving files with certain names in Vim?

I type really fast and sometimes accidentally save a file with the name consisting of a single ; or :. (A typo is sometimes introduced as I type the :wq command.) Is there any way to write a macro that rejects files matching certain names from being…
xjq233p_1
  • 7,810
  • 11
  • 61
  • 107
10
votes
4 answers

autocmd check filename in vim?

I want to write some autocmd's that check if the filename is this or that.. I've been trying: autocmd VimEnter * if % is "preamble" | Explore | endif autocmd VimEnter * if %=="preamble" | Explore | endif autocmd VimEnter * if &filename == "preamble"…
romeovs
  • 5,785
  • 9
  • 43
  • 74
10
votes
6 answers

"set iskeyword-=_" not being set from vimrc

Basically the title. When I include in my vimrc set iskeyword-=_ and save it, when I reload gvim and type :set iskeyword I still see iskeyword=@,48-57,_,192-255 As you can see, the '_' is still there. If I just :set iskeyword-=_ it works as…
rockzombie2
  • 2,835
  • 4
  • 16
  • 20
9
votes
2 answers

The autocmd pattern to match filename and part of path in Vim

I am trying to make an auto-cmd triggered by opening a new file with path including test/ and with filename ending in Test.java. Reading in :h autocmd-patterns I can not figure out if either only limited patterns can be used as a file pattern in an…
user847614
  • 351
  • 3
  • 11
9
votes
2 answers

Is it possible to have vim prevent the saving of a php file that has a parse error?

I use vim and would like it to prevent me from saving php files that has parse errors. If I would like to use for instance "php -l " to achieve this, how would the autocmd in .vimrc look like? I know I can hook into BufWritePre with something…
Christer
  • 246
  • 2
  • 7
8
votes
1 answer

Automatic headers when opening a new python file with vim

Possible Duplicate: How can I automatically add some skeleton code when creating a new file with vim I googled and searched on SO for a way to create automatic headers when creating a new python file. I was hoping to find something with snipMate…
statquant
  • 13,672
  • 21
  • 91
  • 162
7
votes
2 answers

How to open pdf files under cursor (using 'gf') with external PDF readers in vim

The current gf command will open *.pdf files as ascii text. I want the pdf file opened with external tools (like okular, foxitreader, etc.). I tried to use autocmd to achieve it like this: au BufReadCmd *.pdf silent !FoxitReader % & "open file under…
Liang
  • 71
  • 1
  • 2
7
votes
1 answer

Vim disable mouse only in insert mode

When I insert mode sometimes my cursor moved because my palm accidentally placed on trackpad. So, I want to make autocmd to disable mouse on insert mode and enable it in normal mode. I write it like this: autocmd InsertEnter * set mouse="" …
rahmat
  • 1,727
  • 16
  • 35
7
votes
4 answers

Preventing Vim preview window from moving main

Is there an autocmd for when the preview window is opened/closed? I want to scroll the main window n lines up when it the preview window is opened, then n lines down when it is closed, to counteract the "moving text" effect that occurs natively. Am…
Michael Robinson
  • 29,278
  • 12
  • 104
  • 130
6
votes
3 answers

How do you set an autocmd to take effect when filetype is none?

In Vim, I want to have a certain mapping set only if and only if the filetype is markdown, text, or none (ie NULL). Specifying "none" is the hard part. The command below works if :set filetype? returns filetype=markdown or filetype=text. But if…
MERM
  • 629
  • 7
  • 21
6
votes
1 answer

How to make vim run "cpplint" after every "save" command?

I wish that each time I ":w" to save a .h/.cpp file in vim, vim will automatically run cpplint to check my format, and change the file if needed. How to specify this with autocmd? Thanks.
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
1
2 3 4 5 6 7 8