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
23 views

I want to save my typescript file, and immediately run tsc myfile.ts from inside vim. What is the best way to accomplish this?

I am building a daemon, and nodemon currently monitors a file called server.js, which is compiled from the file I am working on, server.ts In order to compile server.ts, after saving with :w, I need ...
2
votes
0answers
42 views

Is it more efficient to use one function instead of multiple autocommands?

I have a lot of lines with with filetype-specific autocommands defining mappings and abbreviations, which looks like this: augroup vimrc au! ... au FileType blah nnoremap <buffer> aa bb au ...
1
vote
1answer
32 views

vim8 - why does my 0read not read? [closed]

I have the following function in an autoload file: function! closet#FindSkeletonForFile() if exists('b:closet_skeleton') return 0 endif let b:closet_skeleton = s:closet....
1
vote
1answer
16 views

Unable to conditionally test for presence of a plugin command & invoke it

I have the following code in my vimrc if exists(":Goyo") augroup LatexGoyo autocmd! autocmd BufReadPost,BufNewFile *.tex Goyo augroup END else augroup LatexColumnSet ...
1
vote
0answers
22 views

Autocmd commands for sharing terminal when open new tab

I was trying to create a trigger that does the following: When opening a new tab with a file, if there already exists a terminal buffer, it is opened below in this new tab. I have seen in logfiles ...
1
vote
1answer
27 views

Override indentation settings with autocmd

When editing Typescript neovim automatically sets indentexpr=GetTypescriptIndent(). I don't like the way it aligns to an open brace instead of inserting a (soft) tab or two, but it doesn't seem to be ...
1
vote
0answers
28 views

How to externally trigger [neo]vim to reload an edited file?

I have a file, /tmp/file.txt that is being edited by vim (or neovim), as well as some other external process. I wish the external app to notify vim, in such a way that vim takes that notification to ...
2
votes
1answer
63 views

Don't jump on search and replace

How do I get my cursor to not move to the last thing it replaced after a search and replace. No <C-o> or extra key presses. Is there some autocmd magic I can setup to listen on any substitute ...
1
vote
3answers
60 views

NERDTree maximize on enter

I'd like to maximize NERDTree when I enter the NERDTree buffer. The command I have so far is: autocmd BufEnter NERD_tree_* <A> ...but the <A> part is wrong. I get the error: E21: Cannot ...
0
votes
1answer
31 views

Reload vim autocmd Filetype [duplicate]

I tried searching for this on the internet but I get bombarded with answers saying to :so $MYVIMRCwhich does not work if I add lines of the type autocmd FileType foo bar. What's a more efficient way ...
2
votes
0answers
17 views

How can I trigger the autocmd FileType commands for all buffers? [duplicate]

I have a key binding to reload my ~/.vimrc. However, some of my options set via autocmd FileType are not active after reloading the config. Those are to set the text width, creating highlights, etc. I ...
1
vote
0answers
33 views

Automatically saving on FocusLost sometimes stops working for a gvim window

In my ~/.vimrc I have at the moment: autocmd BufLeave,FocusLost * nested silent! wall Which most of the time works as I would like, however sometimes it seems saving simply stops working (for a ...
0
votes
1answer
51 views

Apply templates when new file created

I have a file template which is rendered with replacing some stubs when new file created: augroup templates autocmd! autocmd BufNewFile *.java $r ~/.vim/templates/skeleton.java|call s:...
1
vote
1answer
41 views

Execute command only for specified filetype

I'm setting up an environment to automatically recompile .tex files on save. I've found solution for this: autocmd BufWritePost *.tex :! latexmk -pdf But is there any better way to do this? It seems ...
1
vote
0answers
34 views

Keep `scroll` equal to current window height

Is there a way to update scroll every time window height changes? I know, that I can achieve the same behavior calling winheight(0) on each ctrld press as suggested here, but I'm curious if there is ...
0
votes
1answer
45 views

Always move cursor to top of gitcommit buffer

I have the following autocmd in my vimrc. augroup line_return au! au BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ execute 'normal! g`"zvzz' | \ ...
2
votes
1answer
96 views

why doesn't this autocmd take effect for neovim?

I am writing an autocmd which will warn me if the file opened is not in UTF-8 format. This is what I have got: augroup non_utf8_file autocmd! autocmd BufRead * if &fileencoding != 'utf-8' ...
3
votes
2answers
177 views

autocmd for the event: “the first time a buffer is entered”

I know that the autocommand autocmd BufEnter will be triggered every time a buffer is entered. Is there a way to define an autocmd that will be triggered only the first time a buffer is entered?
2
votes
1answer
113 views

What's the difference between autocmd {cmd} and autocmd! {cmd}

For example, what's the difference between calling this command this way: autocmd BufWritePre * call StripTrailingWhitespace() vs. this way (with the bang after autocmd): autocmd! BufWritePre * ...
0
votes
1answer
41 views

Enable line numbering for directories

When viewing a directory (using :Explore, for example), I would like to see line numbers. I can run :set number after opening the directory, and that works, but I can't get numbering to turn on by ...
0
votes
2answers
80 views

Trigger autocommand on error?

Is there an autocommand that is triggered when an error occurs (a Vim error of the type E###)? A try/catch block isn't enough because I need it at a more global level.
1
vote
0answers
27 views

VimEnter autocmd to change cursor shape sometimes outputs escape sequences

Inspired by this answer, I have the following in my vimrc: augroup cursor au! autocmd VimEnter * silent !echo -ne "\e[1 q" augroup end However, this sometimes prints the following on startup:...
1
vote
0answers
39 views

Run commands before and after a buffer is externally changed

Imagine I have a Vim buffer open and the file is changed externally (example: I switched git branches or the file was just edited normally). Any time that happens, I want to have 2 commands run. The ...
2
votes
0answers
47 views

Jump to last position when using vim netrw to open a file

I am looking to jump automatically to the last position in any file that I open. I have in my ~/.vimrc file: autocmd BufReadPost * ...
2
votes
1answer
60 views

How to match file pattern, with extension, not containing a specific word?

I'm trying to use autocmd BufNewFile to like so: autocmd BufNewFile \(.*_spec\)\@!.rb 0r ~/vim/skeleton.rb autocmd BufNewFile *_spec.rb 0r ~/vim/skeleton_spec.rb So, I want the first ...
0
votes
1answer
40 views

Run pdflatex in vim without a pop-up window

I currently have this autocommand in my vimrc: autocmd BufWritePost *.tex silent! execute "!pdflatex %" | redraw! It compiles my current LaTeX file whenever I save with :w. However, a terminal ...
2
votes
1answer
40 views

Automatically save a file that has been previously saved

I am new to vim and was wondering if there is a way for files that have already been manually saved to be automatically saved (every few seconds). I currently make a lot of new files (for testing ...
0
votes
1answer
23 views

Is there a way to tell what autocmds have run?

If the autocmd has an obvious side effect, this is not too hard to tell; but sometimes the result is more subtle and it would be nice to just see "Hey, here's all the autocmds that ran on startup." I ...
0
votes
2answers
89 views

How to match autocmd pattern for unique file

I'm trying to make autocommands that will run only when the buffer is a man page (:Man) but I can't get the right pattern as i'm not too familiar with regexp and globs. here's what i've tried so far: ...
0
votes
1answer
67 views

autocmd for markdown textwidth=100 failing

I want to set my markdown files to have textwidth=100 but cannot get it working. The strange thing is that it works sometimes and sometimes not. My autocmd is: augroup auFileTypes autocmd! ...
0
votes
0answers
42 views

BufRead autocmd error for “*.*” and E45

I have vim version 7.4.1689. It was running quite smoothly. But recently I noticed a problem that I didn't have before. Whenever I run :help <something> in command mode the following error shows ...
1
vote
1answer
177 views

How to do a conditional key mapping dynamically?

I know that I can do a conditional key mapping by map-expression: map [key] [condition] ? [foo] : [bar] But now my situation is somehow awkward. I want to map <C-h> to <C-w>h if I have ...
2
votes
0answers
60 views

Preventing autocmds from being redundantly repeated

I'm trying to figure out what is the proper way to prevent autocmds from being redundantly repeated. Here are articles which I have already read: Remove augroups around autocmds in .vimrc (related ...
0
votes
0answers
247 views

Exclamation mark after autocommands

I'm trying to understand what does exclamation mark after autocommands mean. Sometimes it is possible to see something like this: function! LangSpecificOptions() if (&filetype == 'markdown' || ...
1
vote
0answers
59 views

Why does this autocommand works on neovim but not on vim?

I have this little augroup that contains a simple autocommand that hides the /home/devs/ text on top of nerdtree: augroup HideHOME autocmd! FileType nerdtree autocmd FileType nerdtree syntax ...
1
vote
1answer
49 views

Opening up most recent file automatically when vim is started without command line arguments

I have found myself falling into a workflow where I'm often starting vim by running $ vim and then opening up the most recent file once inside. I was wondering how to detect: when vim is launched ...
0
votes
1answer
122 views

How to print a message after `autocmd` is done

I'm using ctags to generate tag file so that I can jump to declaration or to definition while working with C/C++ project. To make ctags work automatically while entering vim, I add such a line in my ...
0
votes
0answers
22 views

How can I make Vim not remember a command?

I have set up an autocommand, that makes some changes to the file I'm working on, whenever I save. Everything works nice and dandy, except one thing. Whenever I save, and press . afterwards, or undo ...
1
vote
1answer
133 views

Unmapping filetype mappings

I'm trying to unmap some key sequences mapped by python filetype plugin. While I know a better way, I'm still curious if it can be done with autocommands. Here's what I've got so far: augroup ...
2
votes
2answers
103 views

alternative of `BufWinLeave` autocmd that triggers when buffer goes invisible from the screen

The BufWinLeave event is not trigger when the buffer is still visible in another window, which includes the case when it is shown in a window in another tab. This is a annoying since only visible in ...
5
votes
2answers
158 views

Why can't I paste commands into vi?

I've been using vi for 40 years. A week ago I upgraded; Disaster struck! The upgrade was to VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 4 2018 23:38:28) I run this on xterm under Cygwin (...
0
votes
1answer
49 views

How to use a regexp to search/match specific pattern only for the custom statusline and/or tabline?

I got this regexp from google which is for matching specific glyphs in vim-nerdtree. autocmd FileType nerdtree syntax match {hl-group} /\v{glyph}/ containedin=ALL But obviously it won't work on ...
1
vote
1answer
131 views

In autocmd-patterns, how to match a vim variable?

In my .vimrc, I want to execute a bash file test.sh when I save a specific file, say test.txt. However, both files are in /long/list/of/folders/which/makes/an/ugly/looking/line/. Hence I would like ...
-1
votes
1answer
119 views

Automatic highlighting non ASCII character when loading 'vim' filetype buffer

I want to include a new highlight group and autocommand that will automatically highlight non-ASCIIs as soon as either a vimscript or a Python file is loaded in buffer (i.e. any file with filetype '...
3
votes
1answer
65 views

Beep upon using a mapping

Well, I try to use the following convention. ± (as unused key) is used for increase search where / is used for regular search. The implementation: set noincsearch nmap ± <esc>:set ...
3
votes
1answer
75 views

autocmd changes only applying to new files

I've been going through learn vim the hard way and am currently adding abbreviations via autocmd. I've added the following to my .vimrc augroup outputs autocmd! autocmd FileType php :...
3
votes
1answer
358 views

Using Pandoc with vim keybindings

I am trying to define a keymapping in vimrc to compile my markdown file with Pandoc. So I am using this: autocmd FileType markdown nmap <F9> :!pandoc % -o %:r.pdf <cr> But, in markdown ...
1
vote
1answer
55 views

C++: different auto-indentation for function protoypes versus continuation lines

I have the following options setup for C++ and Python development in vim: autocmd BufEnter *.cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=80 noexpandtab cindent cinoptions=:0,l1,t0,g0,(...
0
votes
1answer
75 views

How to un-silent exec in vim only if there is an error?

I have a few hotkeys mapped in my .vimrc (see below) for compiling and running autohotkey scripts but I can either be annoyed by the quest for the any key or I can run them silent and be unaware if ...
2
votes
0answers
49 views

the matching pattern for TabClosed autocmd

If I want to setup a TabClosed autocmd for a specific tab page only, what should I do? Can I use the autocmd {pat} argument? Is this {pat} still matched against the filename? Moreover, the t: ...