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
1
vote
1answer
26 views

Making an autocmd conditional

I have the official black plugin installed in vim. I have in my vimrc: au FileType python autocmd BufWritePre <buffer> Black This works fine, but I would like to be able to disable the ...
0
votes
0answers
15 views

Easiest way to highlight/underline specific words (by location) in a file based on the output of an external program?

I have a program that I run on a file and the output of the program is a line number. If I save this line number in a temporary file, can I get vim to automatically highlight or underline this word/...
2
votes
0answers
14 views

Does TermDebug have an option to open source files readonly?

Vim's TermDebug is brilliant. A real game changer for my development workflow. My only problem with it is that I often have multiple separate gvim windows running, with different sources in each (...
1
vote
2answers
33 views

How can I open python output in a editable buffer?

I am using this in my vimrc, to get output of current script printed on the screen when I click enter. autocmd FileType python map <buffer> <CR> :w<CR>:!python3 %<CR> How can ...
1
vote
1answer
29 views

Run autocommand only after all buffers have been written using :wa

I use an autocmd to copy a directory using rsync when saving a file with BufWritePost. When I save multiple files at once (using :wa), it runs rsync after every buffer save. How can I run rsync or the ...
0
votes
0answers
64 views

Why do `wq!` and `q!` causing "E855 Autocommands caused command to abort" on any Python files?

Executing :q! and :wq! (of course :x as well) on any Python files causing "E855: Autocommands caused command to abort". However, :qa , :wqa (and of course :xa as well) don't caused the same ...
1
vote
1answer
112 views

What's the difference between `BufWinEnter` and `BufEnter`?

I need an example to differentiate the two events in Vim, as I'm having a hard time understanding them.
1
vote
1answer
32 views

How to cancel quitting in a QuitPre autocmd

I want to write an autocmd that prompts the user when the user tries to quit Vim. Based on the user's response, Vim should either quit, or cancel the quit. Is this possible using QuitPre? If not, how ...
0
votes
0answers
27 views

Auto-update Markdown Outline

For Markdown I use the https://github.com/plasticboy/vim-markdown plugin. This Plugin defines a command :Toc which opens a new window a propagates a clickable buffer out of the Headlines. Very helpful ...
3
votes
1answer
216 views

How do you manually trigger an event?

I have case where I would like to trigger the TextChanged event manually without actually changing the text. Would that be possible? How? I know it's hacky, but it would make my life easier right now. ...
2
votes
0answers
33 views

Plugin conflicts over BufWinEnter Autocommands

I have vim-markdown and nerdtree installed. And everything was working fine until I added the following to my .vimrc (verbatim from the nerdtree readme) " Open the existing NERDTree on each new ...
0
votes
0answers
24 views

How to show autcmd errors on another window?

I've got this command that's run before write, which formats my Elixir code, however the error is also shown in the same buffer(?) or the same window, so the window gets messed up as a result. augroup ...
1
vote
1answer
43 views

Echo filename before deleting buffer

I would like to echo the filename before deleting any buffer (:bd, :q). I wanted to achieve this by using auto-commands like this: augroup DummyCodeGroup autocmd! autocmd BufDelete * lua print(...
0
votes
1answer
51 views

How do I compound multiple autocmds for tmux window renaming?

I have these automcmds that work nicely for renaming tmux windows with the current filename (from here): autocmd BufEnter * call system("tmux rename-window " . expand("%:t")) ...
1
vote
1answer
27 views

Run a Command Upon Exiting a Filetype

I know you can run a command upon entering a filetype with... au! Filetype foo echo "bar" but what can I use to run this command when I leave this filetype?
0
votes
0answers
48 views

Detect how vim was quit in autocommand

I have an autocommand on ExitPre like this: autocmd ExitPre * call PromptSaveSession() I'd like to avoid prompting to save the session if vim was forcefully exited, e.g. ':q!' or ':qa!'. Is there a ...
1
vote
1answer
83 views

How do I set spelling and spelling highlight for markdown files?

When I do this: :set spell spelllang=en_us :hi SpellBad cterm=underline It underlines the spell on markdown. I just need this auto command on markdown files. If I put these commands in my .vimrc, and ...
0
votes
1answer
25 views

Executing settings based on directory during startup

I am trying to execute some custom settings based on the directory on startup. For this I am trying: autocmd VimEnter /path/to/dir/* :source /custom.vim When I now execute: cd /path/to/dir vim I ...
0
votes
1answer
33 views

Shell script runs multiple times, I want it to run only once

I use vim pretty extensively for latex compiling. I've a function which automatically compiles the current tex file. I use pdflatex as a compiler, which creates a bunch of different files that it ...
1
vote
1answer
48 views

Is it possible to use || operator for autocommand events? Any workaround?

The following is a set of autocommands used to prevent the cursor from move when you exit from Insert mode: let CursorColumnI = 0 autocmd! InsertEnter * let CursorColumnI = col('.') autocmd! ...
1
vote
1answer
19 views

Count time in insert mode for this project

I'm trying to code some projects in flutter by the dart language. I want to count the time that spends in insert mode to finish this project :call Startchrono() 0 : wait to go in insert mode ... ...
1
vote
0answers
37 views

How can I track the event of opening a file in netrw in an autocommand?

I'm trying to solve this problem by creating an autocommand which will track when a new buffer is opened through netrw, and will then immediately close netrw once the buffer is closed. How can I track ...
1
vote
0answers
35 views

What could interfere with setting foldmethod=indent by autocmd FileType python?

So recently I noticed my autocmd FileType python setlocal foldmethod=indent is not working anymore. The version for my vim is 8.2 When I open a python file everything is working fine except the ...
0
votes
0answers
47 views

Setting ftdetect a given directory

I'm looking for a way to set filetype on load, a loading phase via ftdetect. Right now I can open the files inside a given directory via some utility function that I wrote, and during the opening ...
5
votes
1answer
576 views

how to include multiple commands nested inside a single `autocmd BufRead...`?

I want to make several keybinds and options set for certain files based on their location. Is there a more elegant way than... autocmd BufRead,BufNewFile /tmp/wiki-tag-reports/* nnoremap <Enter>...
0
votes
1answer
31 views

Prevent vim from exiting in case of error during autocommand

I'd like to save my session before vim exits. Here's what I have so far: function SaveSession() let l:new_session = trim(inputdialog("Enter new session name: ", v:this_session, -1)) ...
0
votes
0answers
23 views

Matching patterns in autocommands

I'm trying to match a particular path pattern for an autocommand. I have this: au BufRead *.md if expand('<amatch>') =~ "/path/to/dir/[0-9]" It successfully matches, eg. c:\soemthing-...
0
votes
1answer
86 views

Should the filetypedetect augroup be used in plugins?

I'm writing my first Vim/Neovim plugin, which improves support for files managed by yadm. Pretty straightforward. However, while reading other plugins for inspiration, I have noticed that plugin ...
0
votes
0answers
34 views

Should an exclamation point be added after an "autocmd" in a filetypedetect augroup?

I'm trying to learn more about augroups, which have always confused me. The Section 43.2 documentation (:help 43.2) makes it clear that the filetypedetect group should be used to group autocmds which ...
0
votes
1answer
60 views

Apply `:mkview` to all open tabs at exit from Vim

I use Vim from the CLI and use tabs rather than buffers (as I understand the terminology). I may or may not open multiple files using the -p option, but end up with a few tabs open at once. If I ...
0
votes
1answer
73 views

Calling a function before autocmd event is triggered

In my vimrc I have a key mapping for switching buffers that also automatically resizes the splits by calling a function: nnoremap <silent> <M-h> <c-w>h:call Splitresize()<CR> ...
0
votes
0answers
129 views

What's the best way to auto hide a custom bufferline when there is only one buffer listed?

this is gonna be a lengthy question. I'm developing a neovim bufferline plugin which shows a list of all the buffers in the tabline. I'm trying to implement a auto-hide feature, where the bufferline ...
1
vote
1answer
46 views

How to run an autocommand after undo?

I want to run an autocommand to restore cursor position after undoing with u. After reading the documentation for event, I cannot find a event that is specified for undoing. Which event should I be ...
0
votes
0answers
309 views

Autoloaded vs lua functions: which is faster/more efficient?

I'm creating a neovim plugin written in Lua, and I have to react to the BufAdd and BufUnload events with a function call. I have 3 options: write the function in Lua (like the rest of the plugin) and ...
4
votes
2answers
473 views

Is there a way to write a file and skip the autocmd on write?

My .vimrc has, autocmd FileType rust autocmd BufWritePre <buffer> call LanguageClient#textDocument_formatting_sync() This works great, unless my LanguageClient crashes. Then I can't write the ...
1
vote
1answer
123 views

a way to run a function on CTRL-O / CTRL-I?

I wrote a little function to highlight a current line when navigating which basically mimics this emacs package. It works fine for navigating between windows. function Util.flash_cursorline() vim....
1
vote
1answer
256 views

persistant error "E676: No matching autocommands for acwrite buffer" [closed]

I had a file called a.txt open in vim. I mashed some keys (I really don't know which) but when I tried to save the file :w I got the above error. Same when I tried to quit the file. Finally, I forced ...
0
votes
2answers
212 views

How to set autocmd for files without a filetype?

I want some autocmds to run when I open a file without a filetype like nvim (no file name) or nvim myfile (no extension). I also want them to run when opening certain file types like text and markdown ...
0
votes
1answer
66 views

How to detect the change that from insert mode to normal mode, so I can implement Auto-Save?

I want to do the following: autocmd changeFromItoN * if &readonly == 0 && filereadable(bufname('%')) \ | silent update | endif That is: I want to implement the ...
0
votes
1answer
131 views

Neovim does not autoreload after a BufWritePost, maybe because the timestamps are too close?

I am using neovim to work on a Swift project, so I have set up an autocmd to run swiftformat when I write Swift files as shown. autocmd BufWritePost * if count(['swift'],&filetype) | silent ...
0
votes
1answer
26 views

How to group all `cscope` related configuration into `augroup`, so it's only applied for C/C++ files?

How can I group all cscope (:cs) related configuration into e.g. autocmd, so that this configuration is only applied to c or cpp files? I have been looking at e.g. this, but it only address a single ...
2
votes
2answers
107 views

How to execute shell command and show result right inside vim similar to when execute command through autocmd?

The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I ...
0
votes
3answers
82 views

How to automatically re-apply max window height + width upon terminal resize?

I often use the <C-w>_ and <C-w>| commands in Vim to maximize the current pane to fill the entire window (I have it keymapped to <C-w>0). And I've recently started using a tiling ...
0
votes
1answer
32 views

au VimLeave ex mode command not returning output

I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer). I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I ...
1
vote
1answer
90 views

Can I make a bufwrite bound command save the buffer without triggering infinite filewrite operations?

I have a problem similar that for which nnoremap was conceived, but for the BufWrite aucmd. I have a code formatter which isn't very well-behaved. Gnatpp demands to read a file directly rather than be ...
0
votes
1answer
72 views

How to implement an autocommand that deletes a buffer when it's being hidden and when it hasn't been modified in the last N seconds?

I'm trying to implement a simple autocommand, which deletes a buffer when it's hidden, with a condition that the file hasn't been modified in the last N seconds. I have the following code in ~/.vim/...
-1
votes
1answer
39 views

Run action on file write in local vimrc

I'd like to make it so that in my current project, when I write the file :w, if the file is *.cpp then also automatically run the substitution :%s@^\( \)\+@\=repeat("\t", strlen(submatch(0))...
1
vote
0answers
39 views

Run a command when a buffer is closed and show errors in a new buffer

Goal I'm trying to create a commit buffer: write text, save to commit, show errors in new buffer on failure. Progress I'm having trouble with the last step. I figured I'd use bufhidden=wipe and ...
0
votes
2answers
43 views

Automatically resize window based on filetype

I have a nifty autocommand in my vimrc that automatically maximizes any :help window: augroup LargeHelpWindow autocmd! autocmd BufWinEnter * if &l:buftype ==# 'help' | wincmd _ | endif ...
1
vote
1answer
80 views

How to execute `zz` command after each Jedi jump to defenition command?

I am using davidhalter/jedi-vim plugin to navigate through Python definitions. If a definition is in the same file, the cursor is placed at the top or bottom of the screen. In these cases I usually ...

1
2 3 4 5
7