Questions tagged [autocmd]

`autocmd`s are commands executed automatically on certain events. Questions on creating or modifying `autocmd` definitions are appropriate for this tag.

Filter by
Sorted by
Tagged with
3
votes
0answers
43 views

How to create intermediate directories with :w automatically? [duplicate]

It happens that you want to save a file in a subdirectory that does not exist yet, as in :w ~/customers/one-met-today/note.txt when the directory one-met-today/ does not exist. In the shell, that ...
7
votes
1answer
1k views

Run bash command on writing a file with a particular extension?

I want to run a bash command on writing a .less file, saving it and generating the corresponding .css file with the same name and in the same directory. I do have the bash command which generates the ....
4
votes
2answers
727 views

How can I switch to filetype=txt when entering insert mode for Vim help files?

When writing a Vim help file, it's often useful to set the filetype to help to show syntax highlighting and such. But I find this annoying to work with when editing the document due to the "concealed" ...
2
votes
1answer
909 views

Navigate to first diff in diff mode on startup?

Vim diff opens 2 files for diffing, but it doesn't navigate to the first diff section automatically on startup. Can I add something to startup script (like _vimrc) to do this?
3
votes
3answers
2k views

How do I trigger an autocommand when user enters/leaves command mode

I'm using a really clever plugin that changes the line number style (relative/normal) contextually. Basically when you enter insert mode you have normal line numbers and when you leave insert mode it ...
1
vote
2answers
142 views

Persist autocmd per file (not per filetype) without vimrc

I have some autocmd triggering on TextChanged, that I want to have persisted between Vim restarts. I could make a big if-elseif construct in the vimrc, sure, but I prefer saving the autocmd only for ...
15
votes
2answers
7k views

Suppress output from a vim autocomand

I have an autocommand defined in my vimrc: au BufWritePost * !./make.sh The script make.sh compiles a .tex file 3 times and I don't want the output to be displayed. Is there a way to suppress the ...
7
votes
1answer
1k views

Writing modified buffer to a temporary file

I'd like to write the modified buffer I'm currently editing to a temporary file periodically. In the background I could then, for example, use external tools to analyze the file. I don't want to ...
12
votes
1answer
3k views

How can I run an autocmd when starting Vim with no file, a non-existing file, or a blank file (but not when starting with an existing file)?

I would like to run an autocmd in the following scenarios when I start Vim: With no filename specified. When the file is new. When the file exists but is completely blank. In all of the above three ...
6
votes
1answer
581 views

Why don't I get syntax highlighting when I open a file in an autocmd?

While trying to devise a solution to How do I make vim look in a set of directories for a file, if it doesn't exist in the current directory?, I have got so far using Python: function LookupFiles ...
5
votes
1answer
203 views

Different autocmd behavior when using --remote-tab-silent?

This question is a follow-up to Switching to the local directory after loading a file? I have the following in my .vimrc: autocmd BufReadPost *.tex lchdir %:p:h with the intent of setting the ...
6
votes
3answers
951 views

Switching to the local directory after loading a file?

When running gvim by double clicking with a file in a graphical file manager, like nautilus, the vim instance is called with a strange current directory (seems root sometime, but I am not sure). This ...
10
votes
1answer
539 views

How can I stop Vim from writing a file without throwing an error?

I'm trying to improve the code from this answer to ask for confirmation before creating the missing directory, this is what I write: function! CreateDirectoryAskConfirmation(path) if !isdirectory(...
39
votes
5answers
8k views

How do I save a file in a directory that does not yet exist?

Suppose I start Vim to edit a new file in a directory that is not yet created: vim nonExisitingDirectory/newFile.txt Vim will happily show me an empty buffer and I can start writing my new file. But ...
14
votes
1answer
3k views

Is it possible to easily work with .odt, .doc, .docx, .rtf, and other non-plain-text formats in Vim?

Occasionally someone sends me a .odt, .doc, and .docx file; opening them in OpenOffice is always a pain because, well, OpenOffice. Right now I use a variety of commandline tools (such as odt2txt) to ...
2
votes
1answer
987 views

Autocommand groups syntax and usage [closed]

What are some of the ways to construct autocommand groups in the .vimrc? What is the benefit of grouping autocommands? Can you provide some materials on proper use of autocommand groups? Any help here ...
17
votes
2answers
2k views

Disable syntax highlighting depending on file size and type

I often have to edit various XML files with vim, which vary wildly in size - from configuration files containing a few hunded lines to production data files with sizes up to 2GB. Having syntax ...
6
votes
2answers
830 views

How do I run a command on creation of a new file?

I'm aiming to make scripts I write in a certain directory (or of a certain extension) automatically executable on creation. I can do this whenever a file is written to, using the following autocmd: ...

1 2 3 4 5
6