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

Can I remove all maps containing key?

I have a plugin (c.vim) which includes a lot of maps (all with leader key). I changed my leader key to space, which I like, but the problem is that the maps also apply to insert mode. I would like to ...
1
vote
1answer
20 views

How can I fold some lines on opening a buffer?

I want to fold from "Copyright" to "CONNECTION" every time I open a .c or .h file, so I don't have to see it. The license does have newlines in it in my files, so selecting shouldn'...
0
votes
0answers
17 views

vimrc post buffer bash script

I have a script that is called when I open a file with fileA extension in vim: autocmd BufWritePost *fileA !/usr/bin/named_check_vim %:p script named_checkvim checks for errors in a file, if errors ...
1
vote
0answers
43 views

Local “statusline” override problem

I'm currently writing a plugin, and got stuck with this problem. My plugin opens a new window with all local options I want, but also sets the statusline option to display some useful information. Vim ...
1
vote
2answers
59 views
+50

Run autocmd when creating/deleting a buffer

I have two functions tex#PDFOpen() and tex#PDFClose() to automatically open and close the pdf file created by a TeX document. The way I assign them to autocommands is via the following autogroup in ~/....
0
votes
1answer
36 views

How to set a command as a file type specific autocommand

I would like the :Toc command to call :Voom in R markdown files and :VimtexTocOpen in latex files. First try: au BufRead,BufNewFile *.Rmd command! Toc Voom au BufRead,BufNewFile *.tex command! Toc ...
1
vote
0answers
28 views

How to open a file automatically while entering vim

I know that we can open a file with the help of the argument -o of vim: vim -o myfile. But for some reason I can't pass any argument when I execute the command vim. So I'm thinking if it is possible ...
0
votes
1answer
26 views

How can I backup VimWiki on Git

I'll start by saying that I never wrote any VimScript or done any advanced configuration in my .vimrc. I'm a super noob 😅. Bear with me. I've been trying to backup my VimWiki on Git. I want to add ...
1
vote
1answer
17 views

Command history for specific file

Is it possible to find :commands entered while editing a specific file, as opposed to all commands ever typed at the : prompt? Failing that, is it possible to auto-save commands to a separate history ...
0
votes
1answer
23 views

Unable to get autocmd to execute command

This works: execute pathogen#infect('bundle/ruby/{}') But this doesn't: autocmd FileType * execute pathogen#infect('bundle/ruby/{}') Nor this: autocmd FileType * :execute pathogen#infect('bundle/...
0
votes
0answers
24 views

Cannot use CursorHold event

I'm trying to make vim execute some command, let's say echo "Hello", everytime I hold the cursor on a word for a while. So I do autocmd CursorHold * echo "Hello" But that doesn't seem to do anything,...
0
votes
0answers
7 views

Change match hilights on CmdlineLeave

Vim uses two different highlight groups for matching patterns while searching in the command-line with / or :substitute for example. The incsearch group for the match under the cursor The search ...
1
vote
2answers
21 views

Assign a filetype when editing any file from a directory

The context I store all my shell scripts insde the $HOME/.bin directory. Because of this, I've been looking for a way to set the sh filetype whenever I open a file located in that directory. So, I'...
3
votes
1answer
48 views

Disabling `kana/vim-textobj-entire` by filetype autocommand

kana/vim-textobj-entire creates text-obejcts ae and ie which stand for the entire buffer. But in lervag/vimtex ae and ie stand for an environment in a .tex file. vimtex's ae and ie mappings are much ...
1
vote
1answer
71 views

Silence command but not its output

I use the following function to compile a LaTeX document function! TeXCompile() let filepath = expand('%:p') execute "!cd $(dirname ".shellescape(filepath,1).") && pdflatex -synctex=1 "....
0
votes
1answer
21 views

Map a key on a terminal buffer whose corresponding job is already finished

The context I have mapped <c-p> in terminal mode so that it deletes the terminal buffer where the cursor is. The way I've created this mapping is presented below tnoremap <c-p> <c-w&...
2
votes
0answers
13 views

What pattern could I use to set a filetype for files ending in '.ot.txt' [duplicate]

I'd like to use VimOutliner with files ending in .ol.txt. This entry in ~/.vim/ftdetect/votl.vim doesn't do that au! BufRead,BufNewFile *.ol.txt setfiletype votl Is there a [pattern] for this?
1
vote
1answer
25 views

Autocomplete on command-line search pattern returns strange symbols of <09> and ^I

Using Neovim v0.4.3 on a just recently upgraded Linux Mint 19.3. Problem Description: After the upgrade, when typing / followed by first characters of any word below the cursor, in the buffer, and ...
1
vote
1answer
45 views

How to properly hook an action on save in vim

I have a code linter (https://github.com/symplify/easy-coding-standard) that I can run manually from the command line, but which I'd like to run automatically in vim whenever I save a file that I've ...
1
vote
2answers
80 views

Using an if-endif conditional in autocmd

I'm pretty new to writing stuff in my .vimrc, and I'm trying to understand how to use conditionals. I'm using neovim. I'm trying to get (an enhanced version of) nvim's terminal emulator to launch in ...
1
vote
1answer
30 views

Changing filetype for *.mm files to cpp

I am try to change the filetype for *.mm files. I have created a mm.vim file in ~/.vim/ftdetect, with the following code: au BufNewFile,BufRead *.mm set filetype=cpp But the when opening a file with ...
0
votes
0answers
8 views

autocmd pattern matching symlinked directory

I am trying to pattern match autocmd to a directory referenced by a symlink. I don't want to refer to the actual directory name in my script as the symlink can change targets. I have the directory ...
2
votes
1answer
30 views

Having current filename in the command line

Some time ago I completely got rid of the status line. Vertical space is a scarcity in the modern HD world. The only thing I missed from it is an ability to see what file I'm working with. So I'm ...
3
votes
1answer
48 views

How to exclude filetype with autocmd to load language specific skeleton

I have the following in order to use a different template per language. But I want English to be the default, if I don't specify .en.adoc in the filename. But the *.adoc,*.en.adoc also picks up *.fr....
2
votes
0answers
23 views

Can I trigger a command when the status bar shows up or hides?

I'm using set laststatus=1 so the status bar is only visible when needed, e.g. to display file names when multiple splits are open. However, when the status bar shows up, the existing buffer seems to ...
0
votes
1answer
31 views

Simulate backspace in normal mode

I would like to have the delete key work similarly in normal mode as it does in insert mode, and it's been a bit tricky to map this. Here is what I have so far: :nnoremap <Backspace> i<BS>...
0
votes
1answer
18 views

CmdlineEnter vs CmdwinEnter (In the context of changing Cmdline background color)

Firstly, Im using NeoVim (as you can tell by the winhighlight command). When entering the command line by pressing :, I change the command line window foreground/background. The following very ugly ...
1
vote
1answer
26 views

Command to open pdf file when editing a latex document

I have this command to open the pdf created by a latex document: autocmd FileType tex nnoremap <leader>p :silent !open $(echo "%:p" \| sed s/.tex/.pdf/g)<CR> which works, but I'd like to ...
1
vote
1answer
49 views

BufLeave: Auto save split file not working

I usually keep *.in files open in split and edit them. I would like vim to autosave the *.in files whenever I switch between splits. Searching other answers I found BufLeave that suits my case. I ...
1
vote
1answer
46 views

how to redraw screen (with cursor at top like `zt`) from autocommand

When I open a .task file I don't want to see all the comments at the top. I want the screen to be scrolled down... I can do that manually when vim's already running via zt and I want this to be done ...
3
votes
2answers
343 views

How can I run a function / action every period of time (once an hour)?

I want to run https://stackoverflow.com/questions/7588531/vim-set-color-theme-based-off-time-of-day So something like: if strftime("%H") < 12 set background=light else set background=dark ...
1
vote
0answers
20 views

Run custom code after a vim command

I have searched through a list of all the autocmd's and can't find one which is fired when a built in VIM command is run. How does one run some custom code after a person calls an existing vim ...
1
vote
1answer
59 views

event on command executed

I want to run a command when I change the textwidth. I have tried autocmd CmdlineLeave * call Myfunction() When I do :set tw=40, the function is called before tw is changed. What is the best ...
0
votes
0answers
33 views

What is the event triggered when the command line changes?

I have a function that I'd like to run every time the command line is changed, where by command line I mean the line where text is written when I save a file, get a warning, an error, or echo messages....
1
vote
2answers
85 views

How do I elegantly override file type detection patterns with more specific patterns

I have a file in my ~/.vim/ftdetect directory, which includes configuration such as: autocmd BufRead,BufNewFile,BufWritePost .envrc.template set filetype=sh However, I also have the vim-polyglot ...
1
vote
0answers
17 views

Adding an header when checking an HPP file on the fly

I often use HPP files when separating a template header from its implementation. In this scheme an #include"impl.hpp" is inserted in the .h (the header) file after all relevant definitions. As such, ...
1
vote
1answer
105 views

Usage of a autocmd to write into a buffer - E523: Not allowed here

I am trying to make a plugin, which will be displaying a content of registers in the side bar and updating this side bar at every register's changing. To accomplish this task I decided to set a hook ...
2
votes
1answer
24 views

Autocmd pattern to match empty file/no filename

Say I want to match a buffer with no filename. I can use the pattern *, then manually check the filename, like autocmd myVimrc BufEnter * if @% == "" | echom 'blank filename' | endif Is there a ...
1
vote
1answer
69 views

Which event is triggered by deleting a character with the x key?

I have written a vimscript function. I want to use autocmd to call this function when a character is deleted with the x key. But autocmd requires an event name. Which event is triggered when a ...
3
votes
2answers
54 views

Abbreviations for local filtype buffers only

After typing tds I would like to see it replaced with the current time stamp in Markdown files, but eg. NOT while editing C source code. The following mostly works (stripped for brevity) except that ...
1
vote
2answers
53 views

Preventing an autocmd from overriding last cmd - :<bang><bang> (:!!)

I have an autocmd set up like this: au BufWritePost *.sh,*.zsh,.zshrc silent exec "!ctags --language-force=sh %" When I run :!!<cr> after saving a file, the command !ctags --language-force=sh %...
1
vote
1answer
62 views

Split window size change event

Couldn't find anything in autocommand-events, but is there may be a way to be notified if window split size was changed (with mouse or with C-w +)? What I try to achieve is to be able to auto-save ...
3
votes
1answer
80 views

How to override ftplugin set commands in Neovim

One thing I hate about a lot of the default Vim plugins is that they add o to formatoptions. In Vim I would get around this by using au FileType * set formatoptions-=o in my vimrc, but for some reason ...
0
votes
1answer
216 views

FileType autocommand not working in Neovim

My init.vim is just au FileType * echom "test" However, if I open a file, neovim-qt will not echo test. If I load a new file while the window is open, it will also not work. I have managed to find ...
2
votes
1answer
55 views

How do I trim whitespace automatically?

I've been doing this: au BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif The problem is that it moves the cursor sometimes when I save the file.
0
votes
1answer
78 views

How do I tell vim to detect when a new file was created and do some action? [closed]

What I want to achieve is simply set up some auto command that will detect anytime I create a new file and based on the name of the file I want to insert a couple of lines of text in that file. So if ...
2
votes
1answer
138 views

How to handle a drag & drop event in vim in order to paste the file path instead of opening it

I would like to handle a drag & drop event of a file into gvim in order to insert the file name into the buffer I am dropping it. This should happen only when such file is an image, e.g. .png, or ....
2
votes
1answer
49 views

How can I access buffer variables from BufUnload/BufDelete?

vimdoc says: BufUnload Before unloading a buffer. ... NOTE: When this autocommand is executed, the current buffer "%" may be different from the buffer being unloaded "<afile>". Don't change ...
4
votes
1answer
95 views

Autocmd treat user defined command differently?

This works fine: augroup au_test | au! autocmd BufNew * if 1 | echom 123 | endif augroup end But this doesn't work: com Test echom 123 augroup au_test | au! autocmd BufNew * if 1 | Test | endif ...
4
votes
2answers
214 views

Saving a scratch buffer

I currently use scratch buffers a lot for various uses such as when I read from STDIN to quickly analyze some data or take some very temporary notes. That way I don't have to worry about a swap file ...

1
2 3 4 5 6