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
0 answers
20 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} ...
  • 1,921
0 votes
1 answer
18 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: ...
0 votes
1 answer
43 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 ...
  • 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. ...
0 votes
1 answer
15 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 ...
1 vote
1 answer
33 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 ...
  • 145
0 votes
1 answer
32 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 ...
  • 1
0 votes
2 answers
81 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 ...
1 vote
1 answer
170 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 ...
  • 165
3 votes
1 answer
120 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....
  • 133
1 vote
1 answer
29 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 /&...
  • 2,014
1 vote
1 answer
31 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, ...
  • 940
0 votes
1 answer
24 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 --...
  • 2,014
0 votes
0 answers
419 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 * ...
  • 1
0 votes
1 answer
29 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 ...
  • 1,131
0 votes
1 answer
47 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 ...
  • 101
0 votes
2 answers
69 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 ...
  • 1,131
2 votes
1 answer
503 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 = ...
0 votes
3 answers
115 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 ...
  • 148
0 votes
0 answers
49 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 ...
  • 101
0 votes
1 answer
77 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 ...
  • 205
2 votes
1 answer
128 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 ...
1 vote
1 answer
39 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 ...
  • 647
3 votes
1 answer
235 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 ...
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 <...
  • 2,014
0 votes
1 answer
55 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 ...
3 votes
2 answers
63 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 ...
  • 2,014
1 vote
1 answer
32 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....
  • 13
0 votes
0 answers
36 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.
  • 157
1 vote
1 answer
35 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 ...
1 vote
1 answer
134 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 ...
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 ...
0 votes
1 answer
71 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=...
  • 145
0 votes
1 answer
105 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! ...
0 votes
1 answer
90 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 ...
1 vote
1 answer
53 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 ...
  • 109
0 votes
2 answers
79 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=...
  • 229
0 votes
0 answers
101 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 ...
1 vote
1 answer
64 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 ...
  • 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?
1 vote
1 answer
150 views

Run autocmd on file close

I've been looking through :help autocmd-events for an event that is going to be ran when a file is closed, but I got pretty confused, seeing there were many events that sound like they might do their ...
0 votes
1 answer
48 views

How to set fileformat based on file type?

In a project I need to set fileformat=dos for all *.html files. Is it possible to do with autocmd? My fileformats=unix,dos by default, since I'm on Linux. I've tried the simplest way: autocmd BufRead *...
1 vote
1 answer
76 views

vim: FileChangedShell-like notification for file created after editing started

I really dislike vim taking the focus when I enter a window with a file that has been edited elsewhere, asking me to pick (O)k, (L)oad file and other options. There is a solution for that: register a ...
1 vote
1 answer
37 views

Odd behaviour when pressing Tab with this mapping

I am trying to map ctrl+shift+i to insert an italics command in LaTeX files, and here's my attempt: autocmd BufNewFile,BufRead,BufWrite *.tex inoremap <buffer> <c-I> \textit{}^[i I am ...
2 votes
1 answer
131 views

The right way of mapping 0, j, k, ^, $ to g0, gj, gk, g^, g$ when wrap is set

First, I'm not sure just mapping j to gj always is a good idea, because, for instance, I don't want j to behave as gj when wrap is off and the line is longer than the screen. How can I make 0, j, k, ^,...
  • 2,014
0 votes
1 answer
227 views

nvim: How do I insert a luasnip for BufNewFile "_skel"

I am using nvim-cmp and luasnips and I have a _skel snippet, I would like to create an autocmd to trigger this snippet for New Files: I already have some code: local status_ok, packer = pcall(require, ...
  • 1,077
4 votes
3 answers
3k views

How to remove Neovim trailing white space?

In Vim I used autocmd BufWritePre * :%s/\s\+$//e to delete trailing white space on save. Now, Neovim 0.7 has the new vim.api.nvim_create_autocmd. What is the correct syntax to adapt this autocmd in ...
  • 157
1 vote
1 answer
130 views

How to remove views saved by :mkview

I use :mkview to save folders in vim: autocmd BufWinLeave *.* mkview autocmd BufWinEnter *.* silent loadview but how to delete currently saved views? I comment out those two lines from vimrc but I ...
0 votes
1 answer
99 views

How to make an abbreviation that expands without pressing space

I am trying to replicate the behavior of beg abbreviation shown on the page https://castel.dev/post/lecture-notes-1/ with vimscript. That means I want to make it so that when I type "beg" in ...
  • 11
0 votes
0 answers
40 views

A counterpart for BufUnload,BufDelete event but gets fired after a buffer is unloaded

I've defined an autocommand that essentially checks for the remaining buffers' filetype, and for now by relying on BufUnload or BufDelete, the unloaded buffer still gets detected as being present at ...

1
2 3 4 5
9