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

How can I disable the terminal statusline in gVim?

I want to disable the terminal statusline in gVim as it seems quite useless and I usually have the windows at a relatively small size when using gVim, so it takes up too much space. I've tried quite a ...
paradroid's user avatar
  • 365
1 vote
2 answers
55 views

Unmap error in filetype autocommand

I use a plugin for todo.txt file (https://gitlab.com/dbeniamine/todo.txt-vim). Because I mapped some d[other_letters] in my .vimrc and there's a \d mapped in the plugin, to avoid delays when I type \d ...
Antonio's user avatar
  • 275
0 votes
2 answers
70 views

How to exclude a specific buffer from the BufEnter autocmd group?

I want to load a plugin when I enter a buffer, so I set this event to BufEnter. But when I start neovim, the plugin loads at the dashboard buffer. I want to exclude that buffer. How can I do it? ...
Nias26's user avatar
  • 11
1 vote
1 answer
79 views

Put the mutiple search or replace results into different split window

Dsecription I am using :g/regex to do global search and it always list --More-- So I need to click Enter or Space to see the full results, it takes too much time. I found one way to achieve my goal ...
M_Sea's user avatar
  • 137
1 vote
1 answer
78 views

How do I create a dummy autocommand for User? [duplicate]

:help User warns about using doautocmd without any registered autocmds: Note that when :doautocmd User MyEvent is used while there are no matching autocommands, you will get an error. If you don't ...
idbrii's user avatar
  • 631
1 vote
1 answer
49 views

How to save the files when global replace completed in one command line

I have so many huge size of files and always need to do search and replacement so I map the command as nnoremap aa :let i=1 \| g/regexp/ s/^/\=printf("%1d. ",i)/g \|let i =i+1\|:w! 1.txt ...
M_Sea's user avatar
  • 137
3 votes
1 answer
662 views

How to make Vim start at the end of a template?

I have skeleton template files for various filetypes, and when I create a new file based on these templates, the cursor always starts at the top of the file. It would be more convenient if it started ...
paradroid's user avatar
  • 365
1 vote
1 answer
131 views

Vim command-line mode encoding error when using global search in autocmd

Update Found the issue due to souce the menu this cause encoding=utf-8 and fileencoding=cp936 in _vimrc but in txt files it shows encoding=utf-8 fileencoding=utf-8 The way to fix is reset fenc=utf-8 ...
M_Sea's user avatar
  • 137
1 vote
0 answers
29 views

Autocommand for i_CTRL-x mode?

Is there a way to run a function when entering i_CTRL-X (ins-completion) mode? It doesn't seem to be an event I can run an autocmd for? I can just imap C-S-x (say) to run my function and then call C-x....
Ronak M Soni's user avatar
1 vote
1 answer
49 views

Autocommand is executed multiple times on filetype

I am trying to auto format python files on save. first.py #!/usr/bin/python3 print( "first") second.py #!/usr/bin/python3 print( "second") py.vim def BlackFormat() :...
balki's user avatar
  • 355
0 votes
0 answers
17 views

switch to terminal opened from autocomand

I am trying to create autocommand to run current python file in a terminal, when it is saved. It is working with the following autocommand: vim.api.nvim_create_autocmd("BufWritePost", { ...
user48990's user avatar
2 votes
1 answer
33 views

Create autocmd for downloaded files (filename contains spaces and incrementing numbers)?

I want an autocmd for downloaded log files. These files are called log.txt or log (1).txt (where 1 could be any number). (On Firefox/Windows, when you download a file with the same name as another ...
idbrii's user avatar
  • 631
2 votes
2 answers
106 views

How to exclude filetype in autocmd using Neovim's Lua API?

Translating this excellent Vimscript answer for creating an autocmd that applies certain options only to the focused window into Lua, I have the following: local focused_window_group = vim.api....
Jethro Cao's user avatar
1 vote
2 answers
41 views

How to detect netrw directory listing from autocommand?

I want to detect from a BufEnter autocommand whether the buffer is a netrw directory listing. It seems that when the autocommand is fired, the filetype is empty and there are no netrw-related buffer ...
Andy Stewart's user avatar
  • 1,329
1 vote
1 answer
119 views

Is there an autocmd event that triggers when a command becomes available?

I'm using nvim-lsp and pyright. That latter provides a command PyrightSetPythonPath to reset the path to the python interpreter. Since I can see no other way to perform the same task, I'd like to call ...
Futarimiti's user avatar
0 votes
1 answer
61 views

Error message when opening .ini file

Vim shows the following long error message when I open a file with a dot-ini (.ini) file extension: Error detected while processing /usr/share/vim/vimrc[25]../usr/share/vim/vim90/syntax/syntax.vim[44]....
Melvin Q. Watchpocket's user avatar
0 votes
0 answers
12 views

Vim Autocommand pattern to match rspec.rb files?

I am trying to trigger rspec each time I save a file, but none of the patterns I gave trigger the command. What did I do wrong? I am using the vim-rspec and dispatch.vim. The rspec commands run fine, ...
Iggy's user avatar
  • 165
0 votes
1 answer
121 views

How to run a callback when an nvim plugin is loaded. Can I tie this back to running a callback when a plugin is required/imported?

I can see in vim how we can: Call function only when the plugin is loaded But I want to: Call function only when the plugin is required
Ari Sweedler's user avatar
1 vote
1 answer
89 views

Negate pattern in autocmd

I have some lua auto command that triggers whenever I open a file that has */some_pattern/* in the path. vim.api.nvim_create_autocmd({ 'BufEnter' }, { pattern = vim.fn.expand('~') .. '*/...
Stein's user avatar
  • 143
0 votes
0 answers
30 views

Popup to show number of matches of a given string while in insert mode, and while completion popup is being shown

This is a follow up to a previous question. Thanks to that, I could come up with this augroup: augroup Foo autocmd! autocmd TextChangedI,TextChangedP * call <SID>foo() fun s:foo() let ...
Enlico's user avatar
  • 2,172
1 vote
1 answer
141 views

How can I run a java file from a neovim terminal using a remap

For a bit of background, I'm trying to set up a function that runs a java file in Neovim, I've tried using the following autocmd: vim.api.nvim_create_autocmd( { "FileType" }, { ...
Nico Elbers's user avatar
0 votes
0 answers
43 views

How can I get the number of matches of pattern without altering the search buffer nor moving the cursor?

My end goal is to be able to highlight all the matches of the word being typed and echo their number, but this question is about one specific aspect of this, which I've been having trouble with, ...
Enlico's user avatar
  • 2,172
0 votes
1 answer
189 views

Autocmd is breaking my lsp and not working (neovim)

I’m new to neovim so there’s a decent chance this is just a rookie mistake. I wanted to make an autocmd to remap F5 to running the (python) file. I found a stack overflow post on how to do this (https:...
Nico Elbers's user avatar
0 votes
1 answer
32 views

How does <cword> work in insert mode?

Basically I want to access the last \w\+ in my current insertion. (Hence I asked this question.) Another solution I thought of was something like the following (I'm echoing, but clearly I'd pass it to ...
Enlico's user avatar
  • 2,172
0 votes
2 answers
39 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,172
0 votes
0 answers
64 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
  • 481
0 votes
1 answer
59 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
  • 481
0 votes
1 answer
86 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
1 vote
0 answers
70 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
259 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
18 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,172
0 votes
2 answers
73 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
230 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
  • 149
0 votes
0 answers
21 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
  • 481
1 vote
0 answers
57 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,229
0 votes
1 answer
83 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
74 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
39 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
33 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 ...
user avatar
1 vote
1 answer
64 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
  • 177
0 votes
1 answer
53 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
211 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
512 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
130 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
45 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,172
1 vote
1 answer
80 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
37 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,172
1 vote
1 answer
1k 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
  • 11
0 votes
1 answer
34 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,322
0 votes
1 answer
219 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

1
2 3 4 5
9