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
0 answers
8 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?
user avatar
0 votes
1 answer
49 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 ...
user avatar
0 votes
1 answer
34 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 *...
user avatar
0 votes
1 answer
26 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 ...
user avatar
1 vote
1 answer
35 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 ...
user avatar
2 votes
1 answer
81 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, ^,...
user avatar
  • 1,648
0 votes
1 answer
32 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, ...
user avatar
1 vote
1 answer
144 views

How to remove vim trailing white space?

In Vim I used autocmd BufWritePre * :%s/\s\+$//e to delete trailing white space. Now, Neovim 0.7 has the new vim.api.nvim_create_autocmd. What is the correct syntax to update this autocmd in Lua? vim....
user avatar
  • 113
0 votes
1 answer
40 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 ...
user avatar
0 votes
1 answer
31 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 ...
user avatar
  • 11
0 votes
0 answers
23 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 ...
user avatar
4 votes
1 answer
154 views

Is the colon of the {cmd} argument to autocmd optional?

I know it's a dumb question, but I don't find the explicit answer in the docs. Learn Vimscript the Hard Way's chapter 12 is about autocmds. Here are a few examples: :autocmd BufNewFile * :write :...
user avatar
  • 1,648
0 votes
0 answers
13 views

autocommand variable is not substituded [duplicate]

let Dropbox = "/usr/Dropbox" ... autocmd BufNewFile *.php 0r Dropbox/vim/templates/php_start.txt The variable 'Dropbox' is not substituded by its value
user avatar
0 votes
1 answer
25 views

Custom folding for filetype best practice

In order to keep my tex files organized, i decided to add the following line to my .vimrc, so i can create folds for different parts of them easily by adding "%%" and "%;" as ...
user avatar
0 votes
1 answer
35 views

Buffer not reloaded after external command? [duplicate]

My buffer is able to reload every time I pull changes from the remote, with: autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif autocmd FileChangedShellPost * ...
user avatar
1 vote
2 answers
140 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 ...
user avatar
0 votes
0 answers
22 views

Detect new visual selection with vimscript

I asked a related but different question here. I'm writing the vim-visual-history plugin that keeps a traversable history of previous visual selections. To detect the selections, I'm using: autocmd ...
user avatar
  • 916
0 votes
1 answer
56 views

Vimscript: how to detect selection of a text object in visual mode?

I'm writing what may become a plugin that needs to know what is currently visually selected. To do it, I'm using the autocmd CursorMoved event to detect the creation of visual mode selections on the ...
user avatar
  • 916
1 vote
1 answer
46 views

Making an autocmd conditional

I have the official black plugin installed in vim. I have in my vimrc: au FileType python autocmd BufWritePre <buffer> Black This works fine, but I would like to be able to disable the ...
user avatar
  • 130
0 votes
0 answers
56 views

Easiest way to highlight/underline specific words (by location) in a file based on the output of an external program?

I have a program that I run on a file and the output of the program is a line number. If I save this line number in a temporary file, can I get vim to automatically highlight or underline this word/...
user avatar
  • 101
2 votes
0 answers
24 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 (...
user avatar
1 vote
2 answers
35 views

How can I open python output in a editable buffer?

I am using this in my vimrc, to get output of current script printed on the screen when I click enter. autocmd FileType python map <buffer> <CR> :w<CR>:!python3 %<CR> How can ...
user avatar
  • 123
1 vote
1 answer
36 views

Run autocommand only after all buffers have been written using :wa

I use an autocmd to copy a directory using rsync when saving a file with BufWritePost. When I save multiple files at once (using :wa), it runs rsync after every buffer save. How can I run rsync or the ...
user avatar
  • 131
0 votes
0 answers
80 views

Why do `wq!` and `q!` causing "E855 Autocommands caused command to abort" on any Python files?

Executing :q! and :wq! (of course :x as well) on any Python files causing "E855: Autocommands caused command to abort". However, :qa , :wqa (and of course :xa as well) don't caused the same ...
user avatar
  • 101
2 votes
1 answer
232 views

What's the difference between `BufWinEnter` and `BufEnter`?

I need an example to differentiate the two events in Vim, as I'm having a hard time understanding them.
user avatar
  • 761
2 votes
1 answer
62 views

How to cancel quitting in a QuitPre autocmd

I want to write an autocmd that prompts the user when the user tries to quit Vim. Based on the user's response, Vim should either quit, or cancel the quit. Is this possible using QuitPre? If not, how ...
user avatar
  • 811
0 votes
0 answers
97 views

Auto-update Markdown Outline

For Markdown I use the https://github.com/plasticboy/vim-markdown plugin. This Plugin defines a command :Toc which opens a new window a propagates a clickable buffer out of the Headlines. Very helpful ...
user avatar
  • 353
3 votes
1 answer
277 views

How do you manually trigger an event?

I have case where I would like to trigger the TextChanged event manually without actually changing the text. Would that be possible? How? I know it's hacky, but it would make my life easier right now. ...
user avatar
  • 269
2 votes
1 answer
269 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 ...
user avatar
0 votes
0 answers
27 views

How to show autcmd errors on another window?

I've got this command that's run before write, which formats my Elixir code, however the error is also shown in the same buffer(?) or the same window, so the window gets messed up as a result. augroup ...
user avatar
1 vote
1 answer
52 views

Echo filename before deleting buffer

I would like to echo the filename before deleting any buffer (:bd, :q). I wanted to achieve this by using auto-commands like this: augroup DummyCodeGroup autocmd! autocmd BufDelete * lua print(...
user avatar
  • 113
0 votes
1 answer
71 views

How do I compound multiple autocmds for tmux window renaming?

I have these automcmds that work nicely for renaming tmux windows with the current filename (from here): autocmd BufEnter * call system("tmux rename-window " . expand("%:t")) ...
user avatar
  • 105
1 vote
1 answer
38 views

Run a Command Upon Exiting a Filetype

I know you can run a command upon entering a filetype with... au! Filetype foo echo "bar" but what can I use to run this command when I leave this filetype?
user avatar
  • 106
0 votes
0 answers
108 views

Detect how vim was quit in autocommand

I have an autocommand on ExitPre like this: autocmd ExitPre * call PromptSaveSession() I'd like to avoid prompting to save the session if vim was forcefully exited, e.g. ':q!' or ':qa!'. Is there a ...
user avatar
1 vote
1 answer
120 views

How do I set spelling and spelling highlight for markdown files?

When I do this: :set spell spelllang=en_us :hi SpellBad cterm=underline It underlines the spell on markdown. I just need this auto command on markdown files. If I put these commands in my .vimrc, and ...
user avatar
  • 145
0 votes
1 answer
28 views

Executing settings based on directory during startup

I am trying to execute some custom settings based on the directory on startup. For this I am trying: autocmd VimEnter /path/to/dir/* :source /custom.vim When I now execute: cd /path/to/dir vim I ...
user avatar
  • 123
0 votes
1 answer
39 views

Shell script runs multiple times, I want it to run only once

I use vim pretty extensively for latex compiling. I've a function which automatically compiles the current tex file. I use pdflatex as a compiler, which creates a bunch of different files that it ...
user avatar
1 vote
1 answer
48 views

Is it possible to use || operator for autocommand events? Any workaround?

The following is a set of autocommands used to prevent the cursor from move when you exit from Insert mode: let CursorColumnI = 0 autocmd! InsertEnter * let CursorColumnI = col('.') autocmd! ...
user avatar
1 vote
1 answer
19 views

Count time in insert mode for this project

I'm trying to code some projects in flutter by the dart language. I want to count the time that spends in insert mode to finish this project :call Startchrono() 0 : wait to go in insert mode ... ...
user avatar
1 vote
0 answers
59 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 ...
user avatar
  • 11
1 vote
0 answers
47 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 ...
user avatar
  • 111
0 votes
0 answers
128 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 ...
user avatar
  • 121
6 votes
1 answer
1k 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>...
user avatar
  • 705
0 votes
1 answer
45 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)) ...
user avatar
0 votes
0 answers
28 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-...
user avatar
  • 21
0 votes
1 answer
194 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 ...
user avatar
0 votes
0 answers
67 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 ...
user avatar
0 votes
1 answer
87 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 ...
user avatar
  • 103
0 votes
1 answer
108 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> ...
user avatar
0 votes
0 answers
241 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 ...
user avatar
  • 149

1
2 3 4 5
8