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
0
votes
0answers
15 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
25 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
25 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
100 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
17 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
19 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
44 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
27 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
37 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
36 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
50 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
127 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
325 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 ...
0
votes
1answer
61 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
86 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
65 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
31 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
33 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
24 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
56 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
61 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
15 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
56 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
36 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
31 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
27 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
41 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
63 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
34 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
34 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
70 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
35 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
91 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
48 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
40 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
26 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
66 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
64 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
172 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
215 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
85 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,...
2
votes
1answer
211 views

Disabling relativenumber in Command Mode

I have au InsertEnter * set norelativenumber au InsertLeave * set relativenumber So that I have relativenumber in normal mode but not insert mode. I want to extend this to command mode. I tried ...
2
votes
1answer
73 views

Print bound autocmds to a file

I would like to print all of my current autocmds to a file so that I can grep through and do further analysis. From within vim, the list of autocmds can be found with :autocmd, but this prints to a ...
0
votes
1answer
49 views

ctags: can you ignore matching tags for a specific file extension?

small background: I have a code base with multiple languages: C, C++, Python, Sh, Makefile, Perl. I configure my ctags generation right now to just do: C,C++,Python,Sh. I point vim at the ctags tag ...
1
vote
1answer
59 views

Different word boundaries in command mode

I very commonly use CTRL-W to adjust a previous path in the command line, like I'll bring up the directory of the current file or perhaps a previous :e ... command from history that's close, and use ...
0
votes
0answers
87 views

vim: is possible to use mouse to move lines around

Question: Is possible to use mouse to move lines around? Requirements & Clarification I do know keyboard solutions. normal mode ddp d2j'}p dapggp alike. cmdline commands, :co. '<,'>m'a etc....
1
vote
1answer
45 views

Vim BufLeave event weird behaviour with <c-w><c-f>

How to reproduce Run vim --clean on a file that contains another filename. Now run these commands :set number relativenumber :autocmd BufLeave * set norelativenumber | echoerr "BufLeave ...
1
vote
1answer
261 views

How to map a key for a specific file

We can use the FileType autocommand event to create a customized key mapping for a specific type of file. For example, Spaceb could call different build tools for a Java file compared to a C++ file. I ...

1
2 3 4 5
7