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

How do you clear highlighting if you edit text?

I find it obnoxious that highlight search stays on until you manually turn it off. If I have edited some text after searching, 99% of the time that means I found what I was looking for and I don't ...
1
vote
1answer
228 views

Focus on file when when opening when permanent window for file explorer is enabled

I have a permanent window for file explorer enabled by netrw_altv=1 option. The problem is that when I run vim with file or directory as an argument the window with file explorer is focused. How can I ...
0
votes
1answer
32 views

Deleting an autocmd after it's run

I have this function that I rarely run and it uses matchaddpos. This function highlights at a set position so if I edit text, the same spot is highlighted even though the contents have shifted. I ...
2
votes
1answer
714 views

Set formatoptions for a specific file

In my ftplugin/plaintext.vim script, I have the formatoptions set for editing mostly prose: setlocal formatoptions=tcroqan1j However, in very specific instances -- particularly, Python's idiomatic ...
0
votes
1answer
75 views

norm ^E command works when I type it manually, but fails in an autoloaded vim file. Why?

(Vim 8.0, Windows 7) I wanted to make an autocmd for loading a certain file, that scrolls down five lines from the beginning of the file. It does other things too, so the autocmd itself (inside of an ...
1
vote
2answers
486 views

QuickFixCmdPost autocommand after Glog

I run Glog! from fugitive to populate the quickfix window and set the following autocmd for QuickFixCmdPost (The following questions general and are not specific to Glog, I just use it as example) ...
3
votes
2answers
826 views

autocmd with quickfix window

How can set BufEnter or WinEnter autocmds for entering quickfix window? I tried autocmd WinEnter quickfix echo 'winenter' autocmd BufEnter quickfix echo 'bufenter' None of them works. I doubt that ...
4
votes
1answer
1k views

BufWinLeave * mkview with unnamed file: Error 32

Following this good piece of advice, I have added these lines to my .vimrc. augroup AutoSaveFolds autocmd! autocmd BufWinLeave * mkview autocmd BufWinEnter * silent loadview augroup END It ...
2
votes
2answers
474 views

Are commands in filetype plugins rerun every time the buffer is loaded?

Every time I switch back and forth between two buffers, vim tries to re-load some file specific commands. The error message is E174: Command already exists: add ! to replace it` I am using ...
1
vote
2answers
121 views

How do I make :make run on a buffer write if I'm inside my project directory?

There's posts on SO that explain how to do it in general or on files of a particular type but I would like to restrict it to when I'm inside my project directory. I can run a script to determine ...
7
votes
2answers
450 views

Prevent FocusGained autocmd running in command line editing mode

I have the following in my vimrc to automatically reload a buffer: " Triger `autoread` when files changes on disk " https://unix.stackexchange.com/a/383044/143394 autocmd FocusGained,BufEnter,...
6
votes
2answers
2k views

Start Vim in insert mode for new files

I mostly use Vim to edit configuration files so I understand why it starts in normal mode. But I also use vi mode for the REPL (bash, zsh, ipython, etc.) and the shell always starts in insert mode (...
3
votes
1answer
346 views

endif treated as part of command in autocmd

Here is my code: autocmd BufWritePost *.c,*.cpp,*.h \ let dir=expand('<amatch>:p:h') \ | if filereadable(dir.'/Makefile') || filereadable(dir.'/makefile') \ | Make > /dev/null \ |...
1
vote
1answer
307 views

Checking if Makefile exists before executing autocmd

I want Vim to execute build the project automatically after I write the buffer to a *.c or *.cpp file. Here is what I've done: autocmd BufWritePost *.c,*.cpp make This one works as expected (but the ...
3
votes
1answer
940 views

autocmd BufAdd/BufCreate/BufNew aren't triggered for new, unnamed buffers (`:enew`)?

I'm trying to set up an autocommand so that new, unnamed buffers are created with ft=markdown. Someone on SO suggested the following: autocmd BufEnter * if &filetype == "" | setlocal ft=markdown |...
1
vote
1answer
188 views

Autocommand to add edited filename to bash history

I do a lot of editing in vim and am constantly opening up files using :e or :new ...etc. However, when I quit vim, I do not have the files I edited in my .bash_history. Since I keep finding myself ...
3
votes
1answer
566 views

Autocmd event for `autoread`?

I've just developed a nice solution for automatically loading external changes made to a file, but I'd like a more obvious notification when autoread changes my buffer. Is there a way of having a ...
1
vote
0answers
38 views

Can't hide quickfix before executing makeprg

I'm trying to hide the quickfix window while building, so that it doesn't show outdated info. I can, of course, execute :ccl at any time to close quickfix. Additionally, I've used autocmd to call a ...
2
votes
2answers
104 views

Automatically increase &columns upon :vsplit, but not beyond maximum

I wanted vim to increase its &columns automatically when I do a :vsplit, so I implemented the advice found here: https://groups.google.com/forum/#!topic/vim_use/R4gg-YdPHJM Basically, you add: ...
1
vote
0answers
74 views

Why is filetype not set after :find from autocmd?

Objective I want vi file to act like :find file if file doesn't exist. That is, I want to be able to edit a file by name, without giving a path to the file, from the command line: mkdir -p a/b/c ...
0
votes
1answer
617 views

Automatically insert timestamp when opening certain file

I'd like to have the timestamp inserted on a new line every time I open a certain file. I see that put =strftime('%c') is the command that I want, and that putting that command into a file, say pjf....
2
votes
1answer
622 views

vim cannot access variable in autocmd

I am trying to configure prettier-eslint and prettier-standard as the js formatter with neoformat: " neoformat should try formatprg where available let g:neoformat_try_formatprg = 1 augroup vimrc " ...
1
vote
0answers
259 views

Search not working in function called from autocmd

I am quite new to using vim so please forgive me if this has been asked else where. I have tried Googling but am not really sure what to search for. In my vimrc I have the follwing function that ...
2
votes
3answers
217 views

Running autocmd somehow turns to insert mode

So, here's my problem. I want to be able to run make build whenever I save a source code file and see it in a split pane. If I manually run :split | :te! make build, I get a split pane, my makefile ...
1
vote
0answers
40 views

how can I close the shell buffer? Prefferbly under a certain condition.

I have written a python script that is doing some checks for a LaTeX file and then compiles it. I call it upon saving the file using the following line :autocmd BufWritePost * !~/.vim/latex_compiler....
5
votes
2answers
3k views

Error detected while processing BufReadPost Auto commands for “*.html”: E20: Mark not set

I have what I thought was a pretty simple setup in my neovim init.vim file. Basically all I wanted it to do was configure the tab settings when opening an HTML file. My configuration is: au ...
3
votes
1answer
264 views

What is the point of <buffer> in autocmds?

I know that the buffer is the window you're currently working in (or at least that's what I think it is), but why should I use buffer when scripting :autocmd? For example: autocmd FileType cpp,...
4
votes
1answer
324 views

Vim + Tmux: Resetting tmux tab name when exiting vim

I'm labeling my Tmux tabs with the current file in vim like so: autocmd BufEnter * let &titlestring = ' ' . expand("%:t") set title set t_ts=k Then I have a VimLeave autocmd to have tmux rename ...
1
vote
1answer
227 views

How to execute a command when leaving the 'fugitiveblame' window?

When executing :Gblame, it opens up a window for the blame information. When close that window with q, I want to execute wincmd = I've tried the following, they don't seem to work: autocmd BufLeave ...
3
votes
2answers
646 views

Selectively enable a subset of vim plugins for specific category of workflows (plugin virtualenv for vim projects)

I use vim for many different categories of projects, typically: Writing code (3 languages, python, Matlab and C) Writing documentation ( .rst, .html) Writing reports (.tex) Readme file (.md) As a ...
1
vote
2answers
745 views

autocmd: match more than one pattern

I want to write an autocmd pat that matches more than one file, eg: " Source .vimrc after saving autocmd! BufWritePost ($MYVIMRC,$MYGVIMRC) nested source % | echom "Reloaded " . expand('%') | redraw ...
2
votes
1answer
69 views

Reverse engineering method of loading of a template file

I'm learning .vim configuration and scripting by studying a real world .vimrc file used by Damian Conway (a well known Perl programmer). He has this bit in his file: augroup Perl_Setup autocmd! ...
3
votes
1answer
2k views

Triggering a function with BufEnter

I'm trying to reverse engineer how a .vimrc file works. One of the lines is this: autocmd BufEnter *.p[lm] nmap <buffer> ;t :call RunPerlTests()<CR> The only part I'm unclear on is the ...
1
vote
1answer
408 views

What are the correct autocommand events for various settings?

I have notorious problems finding the right autocommand events for various settings. Usually, my choices seem to be okay, but then there are situations where the settings are reset to default values. ...
4
votes
2answers
208 views

Jump to a series of line numbers one by one after a stay of x seconds at each line

I have a set of 10 line numbers, n1, n2 ,..., n10 in a code of 1000+ lines. I need to jump from one line to another. My normal practice is to do n1G, n2G... till the set is complete. It takes about 5 ...
1
vote
1answer
870 views

Disable absolutely all auto-comments, for real

Auto-comments are the most annoying "feature" of text editors and IDEs for me. I've searched -- nay, scavenged -- high and low to figure out how to get rid of literally any semblance of automatic ...
2
votes
0answers
278 views

How to execute a function when a diff closes

I have a setting (namely highlight the 81st character on the line) that I would like to turn off when there is a diff. This is easy enough as a search through the autocmds results in: |FilterWritePre|...
8
votes
1answer
297 views

vim ZZ lost output with autocommand

I want to check file before quitinq vim with custom functions, everything seems fine with QuitPre autocommand except using ZZ to exit. In this case the output is missing. Consider following function ...
1
vote
2answers
200 views

How to add buffer-local mapping only if not in command-line-window

I've tried this au BufWinEnter * if &l:buftype != 'nofile' | map <buffer> <CR> <Plug>(easymotion-prefix) | endif but somehow this isn't working (easymotion isn't working). ...
4
votes
2answers
518 views

How to detect whether Vim has been invoked by another shell command?

I would like to modify the behavior of one of my mapping but only when Vim is reading data which were piped to it by $ vipe. The mapping closes/quits the current window/session depending on certain ...
7
votes
1answer
365 views

Enable cursorline and cursorcolumn after Quickfix window is opened

Due to performance, I disable the cursorline and cursorcolumn in Vim. However, in the case jumping through a Quickfix window, it is hard to locate the cursor in the file. So I would like to enable ...
7
votes
2answers
503 views

How can I automatically center first search result?

I want to have the very first search result centered on the screen. I know about :nnoremap n nzz mapping, but it only works for centering next matches, not the first. I thought that maybe I could use ...
2
votes
1answer
130 views

How to unfold a fold the cursor is in using modeline?

I've got automatic folding enabled in my file with the following modeline: " vim:foldmethod=marker:foldlevel=0 I also have an autocmd like this to place the cursor where I left it: if has("autocmd")...
3
votes
4answers
1k views

Autocmd on directory to replace netrw

I use the ranger plugin wich I can trigger with a shortcut. But when I open a directory I would like to use the plugin instead of netrw. So I have found that the filetype of directories is netrw, ...
5
votes
4answers
2k views

Stop highlighting when entering Insert mode

I would like Vim to stop highlighting matches when entering Insert mode. And not to highlight them again until a new search is performed. A first thought would be to add the following line to my ....
3
votes
0answers
315 views

Is there a way in vim to determine if something is highlighted after search?

What I want to do is make CursorMoved autocmd that would check if there is a search highlight is on and if it is it would start a timer that would deactivate it. PS I know about all available ...
1
vote
2answers
178 views

Pattern in match in mapping in autocmd

Working on a more lightweight vim-endwise replacement (endwise breaks imap <expr> <CR> mappings). In the following text: def name<-cursor here it adds a newline and another line with ...
6
votes
1answer
273 views

Is there an autocmd-like event for when operator pending mode is entered?

I'd like to make a plugin to display currently pending keys while in operator-pending mode. As the first part of that, how would I register an autocmd to run when operator-pending mode is entered? I'm ...
43
votes
3answers
14k views

Why should I use augroup?

I understand how auto commands work, and how to use them, but I'm somewhat unsure of what augroup is for. I read in :help augroup *:aug* *:augroup* :...
1
vote
0answers
1k views

autocmd not being executed when opening file

I've added the following lines to my .vimrc after reading about folding the other day (taken from vim.wikia.com): autocmd Syntax html,python,tex setlocal foldmethod=indent autocmd Syntax html,python,...