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
8
votes
1answer
304 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
203 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
531 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
381 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
520 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
133 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
327 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
181 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
278 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 ...
45
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,...
1
vote
1answer
139 views

Why does this auto command to disable hlsearch not work?

I like having hlsearch on, but find it annoying in insert mode. So I tried doing the following autocommand to disable it whenever I enter insert mode: autocmd InsertEnter * nohlsearch For whatever ...
4
votes
2answers
82 views

Permission dependent behavior

I would like to set some options for all things I will read but not modify. That is special settings for read-only files (and files in vim view mode). Particularly I'm interested in setlocal wrap ...
2
votes
0answers
411 views

autocmd VimLeave event not firing

I had problem with YCMD server not shutting down properly, so I tried to kill it on VimLeave. After a couple tries I detected that VimLeave/VimLeavePre event not firing on vim exit. VimEnter is ...
2
votes
1answer
935 views

Fire autocmd FileType on current buffers in windows

Context I have shortcuts to edit my vimrc and to source my vimrc. When I'm writing code I can quickly add a new mapping and then source vimrc. And all that would be good if I did not use autocmd ...
3
votes
2answers
609 views

Make vim switch to other window after opening a diff

99% of the time when I am opening a diff (using the :diffsplit command), it's because I want to reference some code, but still edit the file I started in. However, whenever you open a diff with ...
8
votes
1answer
1k views

What is the relevance of has(“autocmd”) today?

Context I have been using Vim for more than 6 years and have compiled it from source a couple of times during that period. Over the years my vimrc did grow. Now, I am trying to clean my vimrc and I ...
3
votes
1answer
364 views

How can I securely restrict vim access to a single file?

So first, I realize that this question is slightly out of the ordinary for this site. I will explain the backstory to avoid the XY problem. Over on Programming Puzzles and Code Golf, lots of users (...
4
votes
2answers
262 views

How do I keep custom cursor reset function from interfering with vim-template?

I have an autocommand function in my .vimrc that resets the cursor to where it was before I last closed the file. This function looks like this: function! ResCur() if line("'\"") <= line("$") ...
4
votes
1answer
1k views

How to set a local variable for a plugin in a BufNewFile autocmd

I currently have autocmd BufRead *.sage \ set filetype=python | \ let b:syntastic_skip_checks=1 which works as intended (sage files are treated as Python, but with Syntastic disabled)...
7
votes
2answers
311 views

au FileType netrw echom “ft is now netrw” does not show up in :messages

Entering in vim :au FileType netrw echom "ft is now netrw" Afterwards, I open a netrw window with :E . Now, I expect to have a message entry in :messages. However, no message is there. Why is there ...
3
votes
1answer
1k views

How to automatically open the location list window after using the :lhelpgrep command?

I have the following autocmds to automatically open the quickfix window or the location list window after executing a quickfix command. augroup quickfix_window autocmd! autocmd ...
0
votes
2answers
352 views

Why does vim tell me that I added an autocommand?

I have been changing "$OLD" to "~/new" in a lot of files lately, so I am now used to starting vim like this $ vim file.txt Enter Lorem ipsum $OLD Lorem .OLD ipsum :%up (brings back %s:\$OLD:\~/new:...
17
votes
1answer
2k views

For an autocmd in a ftplugin, should I use pattern matching or <buffer>?

I have an autocmd for TeX and Markdown files to save the file automatically. Nothing unusual: autocmd CursorHold *.tex,*.md w However, as custom settings for these files increased, I split them off ...
6
votes
3answers
1k views

From a TextChanged autocommand event, how to get the range that has been changed?

Problem I am trying to implement "trimming trailing whitespace in changed lines only". For this purpose, I intercept TextChanged and TextChangedI autocmd events and record the current line (line(.)) ...
13
votes
3answers
1k views

How to automatically lower case the second letter of a word?

When I have to type a lot of text I often tend to keep my finger pressed on shift when I write the first letter of a sentence which often give: [...]end of sentence. NEw sentence[...] Here the E of ...
1
vote
1answer
53 views

Autocommand when writing to files in the arglist

Is it possible to create an autocommand that executes whenever one of the files in the arglist is written to?
5
votes
1answer
274 views

Run file though a command when opening from Explore

I have configured vim to automatically decompile ".class" files similar to the instructions in: http://vim.wikia.com/wiki/VimTip54. I have made a minor change to use cfr_0_115 as below: augr class ...
3
votes
2answers
624 views

How to set commands for unrecognised file type

I want to set some commands for specific filetypes. For example an abbreviation: :iabbr Sb SameBatch The files have extension like .data, .pro. Their grammar, syntax-highlighting are defined in the ...
0
votes
1answer
262 views

Autocmd for scrolling a window?

Is there a autocmd for scrolling a window without moving a cursor, the one that occurs for CTRL+E/Y? Is there some autocmd that is triggered for that? I googled but found nothing.
4
votes
1answer
173 views

augroup end indentation

When I'm editing my vimrc, if I gg=G vim autoindents nicely except where augroup is involved I end up with augroup movingBackup au! au BufWritePost * call WriteBackupFile(expand("%:t"), ...
1
vote
2answers
655 views

Automatically resize the active window to maximum height

I know that it is possible: I googled it some time ago, but now I can't find the solution. What do I need add to .vimrc to resize my current active window in full height automatically after window ...
3
votes
2answers
420 views

How to restore cursor position after search and replace in autocmd

I'd like to delete all spaces on empty lines before saving files. I've figured out how to do that. autocmd BufWritePre * silent! %s/\v^\s+$//e But this moves my cursor to the line where the spaces ...
2
votes
1answer
389 views

Is there an autocmd event while triggering the insert mode completion popup menu?

There is a CompleteDone and MenuPopup event. However, I can't find an event for the triggering of the insert mode completion popup menu. So if I want to do something when triggering the completion ...
0
votes
1answer
3k views

Executing a function on buffer enter and on buffer leave events?

I would like to execute a certain function every time I leave a buffer associated with C++, and another function every time I enter a C++ buffer. I came up with this so far: " Buffer Leave augroup ...
1
vote
1answer
49 views

How to write the output of `:au` in a file

I am debugging a plugin, and to do so saving the output of au into either a file or a temporary buffer would help immensely. Is there a way?
4
votes
2answers
349 views

How can I cancel reading a file into a buffer on BufReadPre?

In order to open PDFs using an external application, one can use the following script: augroup nonvim au! au BufRead *.pdf sil exe "!open " . shellescape(expand("<afile>")) | bd augroup ...
4
votes
2answers
991 views

How to make an autocommand run for closing a window?

There is a (moderately complicated) way to make an autocommand that only runs when windows are created, but I want to have one for when they are removed as well. The reason is that whenever a window ...
14
votes
1answer
5k views

How to enable spell check for certain file types?

I flip between Ruby and Markdown files a lot. Is there a way that I can have set spell automatically set when I open a *.md file, but not when I open a *.rb one?
7
votes
1answer
1k views

What does an `autocmd User` do?

I switched to vim-plug recently. In the README, there's this snippet for using YouCompleteMe with vim-plug: " Code to execute when the plugin is loaded on demand Plug 'Valloric/YouCompleteMe', { 'for'...
3
votes
1answer
61 views

Discard command-line contents when receiving remote keys

If Vim command-line is being edited and the Vim instance receives a string due to vim --remote-send KEYS executed on a shell somewhere, result is somewhat equivalent to pressing Return in the command-...
8
votes
1answer
195 views

The first and last 5 lines of a file? Use for file specific spell ignore list?

Rumor has reached me that it is possible to place vim commands in the first five, or in the last five lines of a a file. But, I could not find this in Google. Any leads would be appreciated. I ...
2
votes
1answer
213 views

BufWritePost not working after navigating using netrw

I'm trying to deploy some static content upon writeing a buffer with an autocmd: augroup dep autocmd! autocmd BufWritePost myProject/frontEnd/** :call s:deploy() augroup END The s:deploy ...
9
votes
3answers
3k views

How do I add skeleton text to new vim files?

I use Vim for writing C++, and I have quite a few #include<> statements, comments, etc. that I must include in each new file I create. I've added autocmd BufNewFile *.cpp r C:\(full file path ...
0
votes
1answer
84 views

Why is an autocmd using cryptmethod a better way to prevent Vim from recording events than a separate vimrc?

There is a comment by Carpetsmoker which suggests a way to prevent Vim from recording events for certain filetypes: I would not recommend using a separate vimrc file, for the simple reason that it'...
3
votes
1answer
150 views

Automate running SQL filetype scripts when opening a PHP file

When I open a PHP file in Vim I want Vim to provide SQL assistance as well as all the PHP assistance. From :h sql-completion-filetypes: This can be enabled easily with the following steps (assuming ...
4
votes
1answer
369 views

How to test filetype in an autocommand without using the FileType event?

I want all trailing whitespace in the buffers I'm editing to be highlighted in red. Here is the autocommand I'm using: autocmd BufEnter,WinEnter * call matchadd('Error', '\v\s+$', -1) The matchadd()...
7
votes
1answer
2k views

Trouble to call a bash command from vimrc with autocommands | “Error: no previous command” (neovim)

basically i want to test within my vimrc, if /home/$USER/.dotfiles/nvim/bundle/vim-snippets/snippets was symlinked to /home/$USER/.dotfiles/nvim/snippets If not, it should create the symlink. the ...