Questions tagged [autocmd]

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

71 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
178 views

Preventing autocmds from being redundantly repeated

I'm trying to figure out what is the proper way to prevent autocmds from being redundantly repeated. Here are articles which I have already read: Remove augroups around autocmds in .vimrc (related ...
john c. j.'s user avatar
4 votes
0 answers
723 views

Can't get autocmd with two events to work

I have the VIM Clang Format Plugin and I would like to format my code every time I save it. This is in my current .vimrc: " map to <Leader>cf in C++ code autocmd FileType c,cpp,objc nnoremap ...
LastSecondsToLive's user avatar
3 votes
0 answers
70 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 (...
Jonathan Wakely's user avatar
3 votes
0 answers
508 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 ...
user1685095's user avatar
  • 1,141
3 votes
0 answers
745 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 ...
fourslashw's user avatar
2 votes
2 answers
557 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 ...
ghostshell's user avatar
2 votes
0 answers
75 views

Modify the path of a file be opened

I am trying to write a function that runs before a new file is created, or an existing file is opened. What I would like to do is edit the path to the file which is being opened depending on the path. ...
run_the_race's user avatar
2 votes
0 answers
33 views

Can I trigger a command when the status bar shows up or hides?

I'm using set laststatus=1 so the status bar is only visible when needed, e.g. to display file names when multiple splits are open. However, when the status bar shows up, the existing buffer seems to ...
danijar's user avatar
  • 391
2 votes
0 answers
162 views

How to profile save time

Sometimes it takes a really long time to save a file out. Saving the same file after various changes takes various amounts of time. It does not seem to be related to file size. I've disabled any ...
embedded.kyle's user avatar
2 votes
0 answers
58 views

Is it more efficient to use one function instead of multiple autocommands?

I have a lot of lines with with filetype-specific autocommands defining mappings and abbreviations, which looks like this: augroup vimrc au! ... au FileType blah nnoremap <buffer> aa bb au ...
Thunderbeef's user avatar
2 votes
0 answers
324 views

Jump to last position when using vim netrw to open a file

I am looking to jump automatically to the last position in any file that I open. I have in my ~/.vimrc file: autocmd BufReadPost * ...
anti-destin's user avatar
2 votes
0 answers
3k views

Exclamation mark after autocommands

I'm trying to understand what does exclamation mark after autocommands mean. Sometimes it is possible to see something like this: function! LangSpecificOptions() if (&filetype == 'markdown' || ...
john c. j.'s user avatar
2 votes
0 answers
73 views

the matching pattern for TabClosed autocmd

If I want to setup a TabClosed autocmd for a specific tab page only, what should I do? Can I use the autocmd {pat} argument? Is this {pat} still matched against the filename? Moreover, the t: ...
doraemon's user avatar
  • 1,597
2 votes
0 answers
703 views

Vim not recognizing markdown and tex files

Here is a sample of my .vimrc, that doesn't do a thing (the autocmd does not work) when I open a .md or .tex file, but works fine for .py files: augroup filetype_python autocmd FileType python ...
Ul Tome's user avatar
  • 31
2 votes
1 answer
167 views

Dynamically toggle formatoptions based on input

Question: Is there a way to control the indentation + comment leader input, when adding a new line? Details: I am trying to set formatoptions-=cro when inserting a new line (in specific syntax region)...
fleischie's user avatar
2 votes
0 answers
340 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|...
Tumbler41's user avatar
  • 7,646
1 vote
0 answers
33 views

How to manually implement autochdir?

'autochdir' 'acd' boolean (default off) global {not in Vi} {only available when compiled with it, use exists("+autochdir") to check} ...
theonlygusti's user avatar
  • 2,083
1 vote
0 answers
49 views

Is there an autocommand event after buffer is deleted?

help BufDelete BufDelete Before deleting a buffer from the buffer list. This is close to, but not what I am looking for: After deleting a buffer.
Cyker's user avatar
  • 177
1 vote
2 answers
649 views

Delete all marks except bookmarks in nvim

I use dashboard so I like my marks clean. So I generally make many marks while working on something and then delete them all except the file bookmark in the end. Is there any way to delete all marks ...
muppi090909's user avatar
1 vote
0 answers
102 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 ...
Max's user avatar
  • 11
1 vote
0 answers
74 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 ...
cccplex's user avatar
  • 111
1 vote
1 answer
89 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)) ...
Big McLargeHuge's user avatar
1 vote
0 answers
617 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 ...
noibe's user avatar
  • 179
1 vote
0 answers
91 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 ...
idbrii's user avatar
  • 559
1 vote
0 answers
95 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 ...
sussy_baka's user avatar
1 vote
1 answer
90 views

Unable to reset settings after running command that triggers bash script

I have the following autocommand in my vimrc for vimwiki: autocmd BufWritePost *.md silent! VimwikiAll2HTML The VimwikiAll2HTML triggers a custom script with :! scriptname to process all the files in ...
StevieD's user avatar
  • 1,377
1 vote
0 answers
117 views

Local "statusline" override problem

I'm currently writing a plugin, and got stuck with this problem. My plugin opens a new window with all local options I want, but also sets the statusline option to display some useful information. Vim ...
Max_Payne's user avatar
1 vote
0 answers
168 views

How to open a file automatically while entering vim

I know that we can open a file with the help of the argument -o of vim: vim -o myfile. But for some reason I can't pass any argument when I execute the command vim. So I'm thinking if it is possible ...
Yves's user avatar
  • 943
1 vote
0 answers
30 views

Change match highlights on CmdlineLeave

Vim uses two different highlight groups for matching patterns while searching in the command-line with / or :substitute for example. The incsearch group for the match under the cursor The search ...
Biggybi's user avatar
  • 2,649
1 vote
0 answers
60 views

Run custom code after a vim command

I have searched through a list of all the autocmd's and can't find one which is fired when a built in VIM command is run. How does one run some custom code after a person calls an existing vim ...
run_the_race's user avatar
1 vote
0 answers
22 views

Adding an header when checking an HPP file on the fly

I often use HPP files when separating a template header from its implementation. In this scheme an #include"impl.hpp" is inserted in the .h (the header) file after all relevant definitions. As such, ...
kabanus's user avatar
  • 163
1 vote
0 answers
258 views

Autocmd commands for sharing terminal when open new tab

I was trying to create a trigger that does the following: When opening a new tab with a file, if there already exists a terminal buffer, it is opened below in this new tab. I have seen in logfiles ...
Joan Albert's user avatar
1 vote
0 answers
189 views

How to externally trigger [neo]vim to reload an edited file?

I have a file, /tmp/file.txt that is being edited by vim (or neovim), as well as some other external process. I wish the external app to notify vim, in such a way that vim takes that notification to ...
caveman's user avatar
  • 181
1 vote
0 answers
107 views

Automatically saving on FocusLost sometimes stops working for a gvim window

In my ~/.vimrc I have at the moment: autocmd BufLeave,FocusLost * nested silent! wall Which most of the time works as I would like, however sometimes it seems saving simply stops working (for a ...
jberryman's user avatar
  • 133
1 vote
0 answers
49 views

Keep `scroll` equal to current window height

Is there a way to update scroll every time window height changes? I know, that I can achieve the same behavior calling winheight(0) on each ctrld press as suggested here, but I'm curious if there is ...
magras's user avatar
  • 111
1 vote
0 answers
138 views

Run commands before and after a buffer is externally changed

Imagine I have a Vim buffer open and the file is changed externally (example: I switched git branches or the file was just edited normally). Any time that happens, I want to have 2 commands run. The ...
ColinKennedy's user avatar
1 vote
0 answers
124 views

Why does this autocommand works on neovim but not on vim?

I have this little augroup that contains a simple autocommand that hides the /home/devs/ text on top of nerdtree: augroup HideHOME autocmd! FileType nerdtree autocmd FileType nerdtree syntax ...
John Fred Fadrigalan's user avatar
1 vote
0 answers
84 views

How can I make Vim not remember a command?

I have set up an autocommand, that makes some changes to the file I'm working on, whenever I save. Everything works nice and dandy, except one thing. Whenever I save, and press . afterwards, or undo ...
hgiesel's user avatar
  • 1,894
1 vote
0 answers
471 views

Disable paste mode entirely

I get what paste mode does for you, but I have never found it particularly useful. I would like to completely deactivate it. I don't see an option to do so when looking at :help paste. However, I ...
maxwell's user avatar
  • 171
1 vote
0 answers
214 views

How vim doesn't expand Ex commands in autocmd?

I'm trying to pass a command to 'vim-tmux-runner' on each file save with au bellow. autocmd FileWritePost,BufWritePost *.py :VtrSendCommandToRunner python manage.py test <afile>:p:h:t Where: :...
sgp667's user avatar
  • 125
1 vote
0 answers
60 views

How does one automatically run a function when any error message appears?

I would like to play sounds for accessibility reasons. Do I need to patch and compile (neo)vim to provide some sort of OnError autocmd? edit: more generically I'm looking for a way to hook into ...
Bart's user avatar
  • 285
1 vote
0 answers
48 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 ...
Mahmoud Al-Qudsi's user avatar
1 vote
0 answers
108 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 ...
aghast's user avatar
  • 207
1 vote
0 answers
309 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 ...
Jonathan Hodgson's user avatar
1 vote
0 answers
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....
Yotam's user avatar
  • 153
1 vote
0 answers
2k 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,...
thosphor's user avatar
  • 111
1 vote
0 answers
118 views

Vim 7.4 autoread no longer detects change of file permissions

I've been using Vim 6.3 (specifically, gvim) for years (and plain old vi for decades before that). One nice feature was that autoread would detect if the file permissions changed. I made use of that ...
Stefan Vorkoetter's user avatar
0 votes
0 answers
30 views

How to use variables inside autocmd?

I have defined the following augroup: vim9script augroup MY_AUGROUP autocmd! autocmd CursorMoved,CursorHold <buffer> \ if index(b:line_numbers, line('.')) != -...
Barzi2001's user avatar
  • 364
0 votes
1 answer
19 views

Specifying filetype in ModeChanged event autocmd

I'm using stylua as the code formatter for lua files. I do not usually get used to its formatting style but sometimes I do need a little help with it, so I decided to make it the formatprg during the ...
Futarimiti's user avatar
0 votes
0 answers
21 views

How to override neovim paste implementation?

I wanted to add some handler that is triggered whenever a paste happened. From what I know, there is no such a thing like autocmd for paste action. I have look into some possible solution such as ...
Muhammad Sulthan Mazaya's user avatar