As of May 31, 2023, we have updated our Code of Conduct.

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
2 answers
29 views

Misunderstanding of interaction between local options, moving between windows, and WinLeave, WinEnter, BufLeave, BufEnter events

This what is logged in :messages when I'm printing the value of nu and rnu upon the 4 events WinLeave, WinEnter, BufLeave, BufEnter during the action, done twice, of opening :help and closing it. The ...
Enlico's user avatar
  • 2,054
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
  • 386
0 votes
1 answer
26 views

How to define a User autocmd event based on a command being executed?

I am struggling in using doautocmd to mimic a user-defined event. The event I am trying to mimic is "After :MyCommand has been executed" I am trying to achieve that goal with the following ...
Barzi2001's user avatar
  • 386
0 votes
1 answer
22 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
0 votes
2 answers
51 views

filetype specific autocommand vs after/ftplugin in lua configuration?

Is there any reason advantage (esp using lua) to put filetype specific settings in an autocmd vs putting in after/ftplugin?
Boyd's user avatar
  • 199
0 votes
0 answers
13 views

autocmd to set hls after having manually :nohls doesn't turn search highlighing on

tl;dr Why, after sourceing the following, moving the cursor doesn't result in the text matching the / being highlighted? set hls augroup AU_NAME autocmd! autocmd CursorMoved * set hls augroup END ...
Enlico's user avatar
  • 2,054
0 votes
2 answers
34 views

Capturing a group in a pattern used in a Vim autocmd

I need Vim to ignore the .tmpl file extension to enable syntax highlighting. How can I rewrite this: autocmd BufNewFile,BufRead *.lua.tmpl set filetype=lua to be more general? I want to match the lua ...
Nikita M. Grimm's user avatar
1 vote
1 answer
46 views

How do I automatically open/close location or quickfix lists when they are populated by ALE?

I'm switching from the syntastic plugin to the ALE plugin. In syntastic there was an option g:syntastic_auto_loc_list that would automatically open the location list after it had been populated. If ...
FalcoGer's user avatar
  • 113
0 votes
0 answers
20 views

BufEnter events triggered with a mouse click in gvim: line('.') appear to return a wrong value. How to fix it?

Consider the following auto-group augroup Test au! autocmd BufEnter * :echo line('.') augroup END and open two different buffers in split windows. When using commands such as wincmd p, then ...
Barzi2001's user avatar
  • 386
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
0 votes
1 answer
32 views

How to map `<LocalLeader>s` to send send the selected text to `SlimeRegionSend`?

For python development, I use slime with tmux and the following configuration let g:slime_target = "tmux" " configuration for vim in a split tmux window with a REPL in the other pane: ...
Paul Rougieux's user avatar
0 votes
1 answer
48 views

How to extract filename of :w command in vim's autocmd?

When I use Vim and type in the :w command, sometimes I will tap ] or \ by accident before I tap the Enter key because these keys are close to each other. As a result, I will get files such as ']' in ...
rqdmap's user avatar
  • 3
1 vote
1 answer
36 views

A command that transforms a code comment to a title in a square with many comment symbols, also called an ascii frame

How to create a command that transforms this text # Title Into this text ######### # Title # ######### Is there a name for this kind of text? I have a hard time searching for this in search engines. ...
Paul Rougieux's user avatar
0 votes
1 answer
17 views

figure out plugin triggering autocmd that CD into home

When I open a new file, [n]vim changes directory into home, regardless of the directory i am in. I didn't wrote code for that behavior, so that must be a plugin. How can I figure out the origin of ...
blackyellow's user avatar
1 vote
1 answer
43 views

Reloading a file with autoread throws an error related to undodir

I have the following contents in my ~/.vimrc: set undofile set undodir=$HOME/.vim/undodir " https://unix.stackexchange.com/a/383044 autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * \ if ...
Matt's user avatar
  • 175
0 votes
1 answer
39 views

Vim: mapping tab to ctrl space only if the cursor is in front of a non whitespace character

I am using the jedi-vim extension and really don't like pressing ctrl-space to bring up auto-complete. I would like to use tab, but also obviously when coding I need tab for indentation as well. I ...
hshah's user avatar
  • 1
0 votes
2 answers
107 views

How to close Terminal and NERDTree windows if they are the last windows?

If I close all buffers, I'm left with the terminal window, which automatically opens whenever I open Vim. I would like it close automatically when I exit Vim. I see that on the NERDTree repo, they ...
Jimmy Zeng's user avatar
1 vote
1 answer
248 views

Always duplicate yanked text to system clipboard

I'm using neovim 0.8.2 Is there a way to automatically mirror last yanked text to system clipboard, regardless of which register I used to yank it to? So if I run something like "ayiw I will have ...
xaxa's user avatar
  • 165
3 votes
1 answer
125 views

How do I change behavior on write based on file path?

I have the following function in my config and it works fine for formatting files on save function! Formatonsave() let l:lines="all" if has('python') pyf ~/bin/clang-format....
emitrax's user avatar
  • 133
1 vote
1 answer
31 views

Is it correct that between a CmdlineLeave and a CmdwinEnter there must be a CmdlineEnter?

Given augroup Dummy autocmd! autocmd CmdLineEnter / echom "CmdLineEnter /" autocmd CmdwinLeave / echom "CmdwinLeave /" autocmd CmdLineLeave / echom "CmdLineLeave /&...
Enlico's user avatar
  • 2,054
1 vote
1 answer
42 views

How to suppress "No matching autocommands"?

I have a log library that has a autocmd log User hook, to show saved log or set it to a dedicated scratch buffer or etc. It works quite well, but there is slight nuisance. When inspection/debug done, ...
qeatzy's user avatar
  • 940
0 votes
1 answer
26 views

Is it possible to delete part of a wildcard autocmd?

If I put this augroup AU_NAME autocmd! autocmd CursorMoved *.cpp,*.hs echo localtime() augroup END autocmd! AU_NAME CursorMoved *.cpp in my vimrc, then open a file and enter :au AU_NAME, I see --...
Enlico's user avatar
  • 2,054
0 votes
0 answers
731 views

Neovim augroup and autocommand in lua (relative line numbering)

I'm converting my init.vim into a set of lua config files, called from init.lua I'm trying to convert this from init.vim augroup numbertoggle autocmd! autocmd BufEnter,FocusGained,InsertLeave * ...
Demus's user avatar
  • 1
0 votes
1 answer
30 views

The pattern of `DirChangePre` is strange where it jumps between `global` and `tabpage`?

As title. I'm trying to fix my plugin with a problem related to the pattern of autocmd. I know that the event DirChangedPre brings a pattern with it when it happens. To reproduce the strange thing I ...
NeoZoom.lua's user avatar
  • 1,190
0 votes
1 answer
73 views

`au BufWritePost` equivalent that matches on FileType?

There are a few cases where the file extension isn't necessarily indicative of the file contents, and filetype needs to be set with a modeline. For example, Salt *.sls files can contain many ...
mpounsett's user avatar
  • 101
0 votes
2 answers
81 views

What's the difference between `:doautocmd` and `doautoall`?

I'm using NeoVim and trying to understand why the need of creating augroup. Then I realized that I don't know the two related commands doautoall, doautocmd. Can anyone help me point out the important ...
NeoZoom.lua's user avatar
  • 1,190
2 votes
1 answer
1k views

Is it possible to set a vim.api.nvim_create_autocmd for a FileType (not just a pattern)?

Currently I'm using pattern in vim.api.nvim.create_autocmd(): vim.api.nvim_create_autocmd({ "BufEnter", "BufFilePost" }, { pattern = { "*.tf" }, callback = ...
RubenLaguna's user avatar
0 votes
3 answers
165 views

Autocmd and key mapping with a conditional expression

I am currently running the following configuration for latex: NVim 0.9, Vmitex and Evince. I have been trying to map a key to open <current-file>.log, while the current-file is a name taken ...
Celdor's user avatar
  • 148
0 votes
0 answers
64 views

Terminal inside vim: I can't quit without first exiting the terminal, any autocmd for this?

When I enter vim and open :terminal I want to :wq or :q without first having to switch to the terminal window and typing exit Any autocmds for this? Can't seem to find any. Note: I have the terminal ...
Nickotine's user avatar
  • 103
0 votes
1 answer
129 views

Autocommand to run :Prettier on :w

I am working in a React (TypeScript) project. I am using LSP with Neovim and have TypeScript Server installed. Right now, after I make a change, I have to run :Prettier followed by :w. I'm getting ...
J86's user avatar
  • 205
2 votes
1 answer
179 views

How can I execute a command after searching with `/`?

After a search command / (i.e., in normal mode) is done, I would like another command to be executed automatically. At the moment the other command should be :normal! zz, in order to center the found ...
Anton Wessel's user avatar
1 vote
1 answer
42 views

autocmd calling function isn't triggered

The following ftdetect-file doesn't work as expected: augroup dummy au! au BufRead bla* setf dummy au BufRead bla* call s:detect_ft() augroup END echom 'one' function! s:detect_ft() abort ...
radlan's user avatar
  • 667
3 votes
1 answer
304 views

Detecting the Enter and Leave of Visual mode event

Are there any events similar to InsertEnter and InsertLeave that I could use for visual mode? Looking through the helpfiles, I did not fine any. If not, how would I be able to detect if Vim enters or ...
unrealapex's user avatar
1 vote
1 answer
15 views

How can I deactivate CR only if its effect is to move to the next line?

I don't use arrow keys, but to avoid the cursor moving should I hit them by mistake, I have this in my vimrc: inoremap <Left> <NOP> inoremap <Right> <NOP> inoremap <...
Enlico's user avatar
  • 2,054
0 votes
1 answer
56 views

Vim: cursor manipulation in help file

So I want to be able to automatically open help files in a new tab. I saw a question on this SE that pretty much solved my problem. I wanted to make just one change: center the screen. "That will ...
Dominik Teiml's user avatar
3 votes
2 answers
70 views

What is the pattern matched against for events CmdwinLeave and CmdwinEnter?

More in general I'm always in doubt about what's the meaning of the {aupat} argument of autocmd for a given {event}. From :help :autocmd I read (my emphasis) Add {cmd} to the list of commands that ...
Enlico's user avatar
  • 2,054
1 vote
1 answer
38 views

Detect line endings in current buffer, substitute all line endings depending on result

In GVIM, I'd like to save the current file with either \r\n or \n line endings. Depending on the opened file, the appropriate line endings should be chosen automatically. I had a look at https://unix....
Lvn's user avatar
  • 13
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
1 answer
48 views

Is there a way to detect all the autocommand that have been triggered?

I have a file for which the filetype is not correctly set. The filetype is set by an autocmd but I would like to identify which one. How can I know which autocmd have been triggered when I load my ...
Vivian De Smedt's user avatar
1 vote
1 answer
202 views

'BufNewFile,BufFilePre,BufRead' or simply 'BufFilePre,BufRead' when detecting a filetype?

The following snippet is from the vim-pandoc-syntax plugin README: If you want to use vim-pandoc-syntax without vim-pandoc, you'll need to tell Vim to load it for certain files. Just add something ...
john c. j.'s user avatar
0 votes
0 answers
24 views

How to trigger a command on line creation/deletion getting info about it?

I'm working on a "memo buffer" that is scroll-bound to a "document buffer" and used for adding description for that. Each line of the memo should keep being in the same row as the ...
Dugesia7's user avatar
0 votes
1 answer
88 views

How to change editor options when switching to diff mode?

I have a few options I like to apply both when Vim is opened in diff mode and when it is switched to diff mode, e.g., when calling diffsplit. I have the following lines in my ~/.vimrc: command! -nargs=...
Matt's user avatar
  • 175
0 votes
1 answer
134 views

'autocmd OptionSet' - How to make it work?

The following .vimrc snippet is by Martin Tournoij's answer posted here: How do I stop the colorcolumn from breaking into multiple pieces when there are wrapped lines? augroup wrappedcc autocmd! ...
john c. j.'s user avatar
0 votes
1 answer
121 views

To not wrap at 'textwidth' if 'filetype' is 'text'

I want to ask Vim to not auto-wrap text at the textwidth value. For this, I adopted a function from the following article: Vim: Set wrapping and indentation according to file type. The autocmd doesn't ...
john c. j.'s user avatar
1 vote
1 answer
80 views

"autocmd!" on a separate line vs. "autocmd! <the autocmd itself>"

From what I have read in a book by Steve Losh (chapter 14), it seems that to avoid performance issues, it is best practise to enclose autocommands, even the single ones, in autocommand groups: augroup ...
james's user avatar
  • 109
0 votes
2 answers
94 views

What is wrong with my autocommand groups?

This is the current state of my autocmds.vim file. " Option for specific filetypes autocmd BufRead,BufNewFile *.md setlocal textwidth=...
paradroid's user avatar
  • 239
0 votes
0 answers
126 views

Override autocmd to change filetype for a subset of markdown files

I'd like to load the cornelis plugin for the Agda language when I open a *.lagda.md file. I have this autocmd in init.vim: au BufNewFile,BufReadPre *.agda,*.lagda* setf agda However, *.lagda.md gets ...
Li-yao Xia's user avatar
1 vote
1 answer
75 views

Automate find and replace

When having selected something in visual mode where I want to perform a find-and-replace I always have to run :'<,'>s/foo/bar/g manually. Is there some way so that I can bind it to some key ...
Richard's user avatar
  • 155
0 votes
0 answers
11 views

how to prompt to mkview when leave the window

Is there a way to make vim prompt to ask if you want to mkview, choose [Y/n], and also ask where you want to save the view file if choose yes?
Jiang Yuanhao's user avatar

1
2 3 4 5
9