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
1answer
19 views

How to group all `cscope` related configuration into `augroup`, so it's only applied for C/C++ files?

How can I group all cscope (:cs) related configuration into e.g. autocmd, so that this configuration is only applied to c or cpp files? I have been looking at e.g. this, but it only address a single ...
1
vote
0answers
23 views

How to execute shell command and show result right inside vim similar to when execute command through autocmd?

The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I ...
0
votes
3answers
55 views

How to automatically re-apply max window height + width upon terminal resize?

I often use the <C-w>_ and <C-w>| commands in Vim to maximize the current pane to fill the entire window (I have it keymapped to <C-w>0). And I've recently started using a tiling ...
0
votes
1answer
12 views

au VimLeave ex mode command not returning output

I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer). I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I ...
1
vote
1answer
44 views

Can I make a bufwrite bound command save the buffer without triggering infinite filewrite operations?

I have a problem similar that for which nnoremap was conceived, but for the BufWrite aucmd. I have a code formatter which isn't very well-behaved. Gnatpp demands to read a file directly rather than be ...
0
votes
1answer
30 views

How to implement an autocommand that deletes a buffer when it's being hidden and when it hasn't been modified in the last N seconds?

I'm trying to implement a simple autocommand, which deletes a buffer when it's hidden, with a condition that the file hasn't been modified in the last N seconds. I have the following code in ~/.vim/...
-1
votes
1answer
27 views

Run action on file write in local vimrc

I'd like to make it so that in my current project, when I write the file :w, if the file is *.cpp then also automatically run the substitution :%s@^\( \)\+@\=repeat("\t", strlen(submatch(0))...
1
vote
0answers
27 views

Run a command when a buffer is closed and show errors in a new buffer

Goal I'm trying to create a commit buffer: write text, save to commit, show errors in new buffer on failure. Progress I'm having trouble with the last step. I figured I'd use bufhidden=wipe and ...
0
votes
2answers
33 views

Automatically resize window based on filetype

I have a nifty autocommand in my vimrc that automatically maximizes any :help window: augroup LargeHelpWindow autocmd! autocmd BufWinEnter * if &l:buftype ==# 'help' | wincmd _ | endif ...
1
vote
1answer
30 views

How to execute `zz` command after each Jedi jump to defenition command?

I am using davidhalter/jedi-vim plugin to navigate through Python definitions. If a definition is in the same file, the cursor is placed at the top or bottom of the screen. In these cases I usually ...
0
votes
2answers
38 views

Run command on kill signal?

Is there an autocmd event for kill signals (for e.g. SIGTERM) ? As this answer indicates Vim can catch SigUSR1 event. My use case is to save session on SIGTERM before quitting.
0
votes
1answer
29 views

Exclude trailing newline when reading in skeleton file

I have the following in my .vimrc: au BufNewFile *.py 0r ~/.vim/skeletons/py.skel | let IndentStyle = "python" However, when I open a new .py file, there is always a trailing empty line ...
1
vote
1answer
30 views

Interaction between multiple {event}s and multiple {path}s

From :h autocmd-events: You can specify a comma-separated list of event names. No white space can be used in this list. The command applies to all the events in the list. From :h {pat}: The {pat} ...
2
votes
1answer
54 views

Mapping specific for diff mode and vimdiff

My idea is that whenever &diff is true for a buffer, I would like some mappings to be active when that buffer is the current buffer. The following attempt works for when I open a session in diff ...
1
vote
1answer
28 views

How does the InsertChange event work?

So this is in the help page (:h autocmd-events): |InsertChange| when typing <Insert> while in Insert or Replace mode I don't really understand what it means with when typing <Insert>....
0
votes
1answer
48 views

Run a command every time any key is pressed

I want to run a function every time the user presses any key. I have already looked through the autocommand documentation and there does not seem to be one for this. Is there any function I do not ...
1
vote
1answer
43 views

Combine FileType with other events

I'd like to combine two events: FileType and TextChangedI. According to this awesome book I can do that, by adding a comma between both events like this: :autocmd BufWritePre,BufRead *.html :normal gg=...
0
votes
0answers
36 views

Cannot understand how to group autocommands in this case

I downloaded a program called calcurse and it allows me to make notes by making temporary files in /tmp folder. The note files are named as calcurse-note.[some random alphanumeric characters after ...
1
vote
1answer
25 views

Only allow syntax and without other autocmds in popup

I write a lf-like file browser demo as below. Now there is a problem: when preview a file in popup, it can be slow if there exists a lot of autocmds, so I abandon autocmd by vimcmd("noautocmd let ...
2
votes
2answers
55 views

Buffer scope variable not exists when run autocmd BufUnload

Describe the issue I use a vim plugin that when use Vim to open a ipynb (python notebook) file, will call system function to use jupytext create corresponding python file to enable use like, YCM to ...
-1
votes
2answers
56 views

How can i make this autocmd BufEnter command work?

i am setting the default vim-statusline, and i made this line on my colorscheme: hi MyStatusLineDevIcon ctermfg=7 ctermbg=0 cterm=NONE So i can color the devicons on my statusline.vim config I call ...
0
votes
2answers
102 views

Can I use a variable in autocmd pat?

I have 3 languages and any can be a source or target so I need some flexibility. I am successfully loading a language translation specific setup with this: let g:tr_source = 'dyu' let g:tr_target =...
1
vote
2answers
111 views

Adding new filetypes with vim commentary

I'm trying to add include an unsupported filetype, gf, with vim commentary. The comments are simple, just prepend -- to any line, as in the Haskell tradition. According to the vim-commentary git, ...
2
votes
1answer
71 views

Why are nested FileType autocommands triggered even ++nested is not used?

From :h autocmd-nested, it says "By default, autocommands do not nest." But nested FileType events are triggered anyway without using ++nested. As seen in this test: autocmd BufNewFile,...
2
votes
1answer
193 views

Disabling relativenumber in Command Mode

I have au InsertEnter * set norelativenumber au InsertLeave * set relativenumber So that I have relativenumber in normal mode but not insert mode. I want to extend this to command mode. I tried ...
2
votes
1answer
61 views

Print bound autocmds to a file

I would like to print all of my current autocmds to a file so that I can grep through and do further analysis. From within vim, the list of autocmds can be found with :autocmd, but this prints to a ...
0
votes
1answer
22 views

ctags: can you ignore matching tags for a specific file extension?

small background: I have a code base with multiple languages: C, C++, Python, Sh, Makefile, Perl. I configure my ctags generation right now to just do: C,C++,Python,Sh. I point vim at the ctags tag ...
1
vote
1answer
53 views

Different word boundaries in command mode

I very commonly use CTRL-W to adjust a previous path in the command line, like I'll bring up the directory of the current file or perhaps a previous :e ... command from history that's close, and use ...
0
votes
0answers
32 views

vim: is possible to use mouse to move lines around

Question: Is possible to use mouse to move lines around? Requirements & Clarification I do know keyboard solutions. normal mode ddp d2j'}p dapggp alike. cmdline commands, :co. '<,'>m'a etc....
1
vote
1answer
37 views

Vim BufLeave event weird behaviour with <c-w><c-f>

How to reproduce Run vim --clean on a file that contains another filename. Now run these commands :set number relativenumber :autocmd BufLeave * set norelativenumber | echoerr "BufLeave ...
1
vote
1answer
202 views

How to map a key for a specific file

We can use the FileType autocommand event to create a customized key mapping for a specific type of file. For example, Spaceb could call different build tools for a Java file compared to a C++ file. I ...
1
vote
1answer
95 views

autocmd BufNewFile to use template and then run command (to move cursor)

I have a template being used like so: autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py But earlier in my autocommands the cursor position is being set which ...
2
votes
1answer
56 views

matching digits and repetition in autocmd BufNewFile

I've got a template for vimwiki diary entries that's invoked via this autocommand: autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py But I want to be able to ...
2
votes
2answers
67 views

Where do filetype-specific autocommands live?

I have a plugin for a specific filetype (*.tex), and I'm wondering where I can find all the commands which are executed when I type :e examplefile.tex? In general, is there a standardized practice for ...
2
votes
1answer
74 views

Why doesn't `autocmd InsertLeave * :setlocal relativenumber` get executed when I leave Insert mode using Ctrl-C?

I've defined the following autocmds, which active/deactivate relative line numbers, depending on whether I'm in Insert mode or not: " Relative line numbers, except Insert mode augroup ...
1
vote
1answer
79 views

Autosave and Nerdtree conflicts

I was trying to setup NeoVim to autosave each time a change is made. I used this command, which I wrote in ~/.config/nvim/init.vim: autocmd TextChanged, TextChangedI * silent write It works perfectly ...
5
votes
1answer
83 views

How often and when is foldexpr evaluated?

I want to toggle foldmethod between expr and manual because if we always set foldmethod=expr, then the cursor tends to move slowly in vim. I think that foldexpr is evaluated just after switching ...
1
vote
0answers
19 views

How to prevent `autocmd` for stripping trailing whitespace for moving the cursor? [duplicate]

I've the following autocmd for stripping trailing whitespace in a buffer, every time the buffer is written to a file: " trim whitespace autocmd BufWritePre * %s/\s\+$//e However, the autocmd has ...
1
vote
0answers
22 views

How can I automatically delete all whitespace on empty lines and all trailing whitespace on non-empty lines? [duplicate]

I'm using the flake8 linter for Python, which constantly complains about whitespace on empty lines and trailing whitespace on non-empty lines. How can I configure Vim to automatically remove such ...
1
vote
1answer
26 views

How can I alter the window to which ctrl+w, ctrl+p will jump to?

What I'm looking for is a programmatic way of changing which window Ctrl+w, Ctrl+p will jump to. The reason why I want to do this is that I have an autocmd like the following autocmd BufEnter ...
3
votes
1answer
32 views

Why won't vim source my ftplugin_after.vim file?

I have a file called ~/.config/nvim/after/ftplugin_after.vim, which contains set incsearch ignorecase smartcase number relativenumber autoindent shiftwidth=8 tabstop=8 softtabstop=8 expandtab ...
1
vote
1answer
98 views

autocmd filetype nnoremap is not working

I'm trying to create a mapping based on the file type. (as explained in this chapter https://learnvimscriptthehardway.stevelosh.com/chapters/12.htm) :autocmd FileType javascript nnoremap <buffer>...
0
votes
1answer
89 views

Formatting using BufWritePost ends up with WARNING

I am trying to format PHP files using the following function: function! PHPCSFixer() let l:fixer_path = '$HOME/....
1
vote
1answer
176 views

Syntax in autocmd command to compile and run cpp code

From this post here: https://stackoverflow.com/questions/540721/compile-directly-from-vim One of the answer is: autocmd filetype cpp nnoremap <F4> :!g++ % -ggdb -o %:r <CR> autocmd ...
2
votes
1answer
28 views

Execute autocommand only if buffer contains a pattern

Concrete example: When using React with Styled Components, I want to load the CSS snippets file. I could achieve this with: autocmd FileType javascript,typescript :UltiSnipsAddFiletypes css However, ...
0
votes
1answer
46 views

Adding Filetype != filetypes

I have the following mapping: augroup MatchingQuotes autocmd Filetype noremap! ' ''<Left> autocmd Filetype noremap! " ""<Left> augroup END Is there a way to set ...
1
vote
0answers
23 views

Modify the path of a file be opened

I am trying to write a function that runs before a new file is created, or an existing file is opened. What I would like to do is edit the path to the file which is being opened depending on the path. ...
0
votes
2answers
67 views

Define a new ex command active only in specific filetype (C++)

I would like to define a new command for C++ files/buffers (ft=cpp). I shall explain the requirements through the example below. The newly defined command :stripdbg should strip the surrounding dbg() ...
0
votes
1answer
47 views

Unable to reset settings after running command that triggers bash script

I have the following autocommand in my vimrc for vimwiki: autocmd BufWritePost *.md silent! VimwikiAll2HTML The VimwikiAll2HTML triggers a custom script with :! scriptname to process all the files in ...
1
vote
3answers
164 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
2 3 4 5
7