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
22 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
34 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
51 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
24 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
30 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
18 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
27 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
29 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
34 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 ...
2
votes
1answer
313 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
21 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
22 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
60 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
29 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
45 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
53 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
75 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
40 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
213 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
382 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
73 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....
0
votes
1answer
171 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
120 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
39 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
56 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
71 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
69 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
24 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
62 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
46 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
37 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
32 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
37 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
57 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 ...
0
votes
2answers
87 views

Run command on kill signal?

Is there an autocmd event for kill signals (for e.g. SIGTERM) ? As this answer indicates Vim can catch SigUSR1 event. My use case is to save session on SIGTERM before quitting.
0
votes
1answer
38 views

Exclude trailing newline when reading in skeleton file

I have the following in my .vimrc: au BufNewFile *.py 0r ~/.vim/skeletons/py.skel | let IndentStyle = "python" However, when I open a new .py file, there is always a trailing empty line ...
1
vote
1answer
40 views

Interaction between multiple {event}s and multiple {path}s

From :h autocmd-events: You can specify a comma-separated list of event names. No white space can be used in this list. The command applies to all the events in the list. From :h {pat}: The {pat} ...
2
votes
1answer
104 views

Mapping specific for diff mode and vimdiff

My idea is that whenever &diff is true for a buffer, I would like some mappings to be active when that buffer is the current buffer. The following attempt works for when I open a session in diff ...
1
vote
1answer
43 views

How does the InsertChange event work?

So this is in the help page (:h autocmd-events): |InsertChange| when typing <Insert> while in Insert or Replace mode I don't really understand what it means with when typing <Insert>....
0
votes
1answer
156 views

Run a command every time any key is pressed

I want to run a function every time the user presses any key. I have already looked through the autocommand documentation and there does not seem to be one for this. Is there any function I do not ...
1
vote
1answer
56 views

Combine FileType with other events

I'd like to combine two events: FileType and TextChangedI. According to this awesome book I can do that, by adding a comma between both events like this: :autocmd BufWritePre,BufRead *.html :normal gg=...
0
votes
0answers
46 views

Cannot understand how to group autocommands in this case

I downloaded a program called calcurse and it allows me to make notes by making temporary files in /tmp folder. The note files are named as calcurse-note.[some random alphanumeric characters after ...
1
vote
1answer
27 views

Only allow syntax and without other autocmds in popup

I write a lf-like file browser demo as below. Now there is a problem: when preview a file in popup, it can be slow if there exists a lot of autocmds, so I abandon autocmd by vimcmd("noautocmd let ...
2
votes
2answers
70 views

Buffer scope variable not exists when run autocmd BufUnload

Describe the issue I use a vim plugin that when use Vim to open a ipynb (python notebook) file, will call system function to use jupytext create corresponding python file to enable use like, YCM to ...
-1
votes
2answers
83 views

How can i make this autocmd BufEnter command work?

i am setting the default vim-statusline, and i made this line on my colorscheme: hi MyStatusLineDevIcon ctermfg=7 ctermbg=0 cterm=NONE So i can color the devicons on my statusline.vim config I call ...
0
votes
2answers
241 views

Can I use a variable in autocmd pat?

I have 3 languages and any can be a source or target so I need some flexibility. I am successfully loading a language translation specific setup with this: let g:tr_source = 'dyu' let g:tr_target =...
1
vote
2answers
317 views

Adding new filetypes with vim commentary

I'm trying to add include an unsupported filetype, gf, with vim commentary. The comments are simple, just prepend -- to any line, as in the Haskell tradition. According to the vim-commentary git, ...
2
votes
1answer
114 views

Why are nested FileType autocommands triggered even ++nested is not used?

From :h autocmd-nested, it says "By default, autocommands do not nest." But nested FileType events are triggered anyway without using ++nested. As seen in this test: autocmd BufNewFile,...

1
2 3 4 5
7