Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [autocmd]

`autocmd`s are commands executed automatically on certain events. Questions on creating or modifying `autocmd` definitions are appropriate for this tag.

0
votes
1answer
23 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
15 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 ...
0
votes
1answer
42 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 '...
1
vote
1answer
28 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
36 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 :...
2
votes
1answer
99 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
26 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
25 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
31 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: ...
0
votes
0answers
43 views

E20: mark not set error occurs sometimes

I am editing latex1 prose in vim. For paragraph reformatting, I am using the par text formatter. I have set up the following autocommand for latex-files, to map A-q for reformatting the whole ...
0
votes
0answers
21 views

Auto source fail when saving shell and tmux runtime configuration

I am auto source the vimrc file whenever I save the file by autocmd! BufWritePost .vimrc source % I would like to apply this to all file needed to source, however the following lines seems not ...
1
vote
1answer
29 views

Does FileType only works when vim acctually knowns the type by default?

I need to mapping some action only for the feature file (which end with .feature) I've tried autocmd FileType feature nnoremap .... in the vimrc, but it won't work when I editing the feature file ...
0
votes
1answer
46 views

Statusline – update variables on file change

I'm currently learning Vimscript, but I'm stuck at a particular problem. I'm creating a statusline which shows the full path (~) of the file currently displayed in the buffer. Instead of just using %...
1
vote
1answer
22 views

Put error into quickfix window

I can customize some error display in my file like highlight all white space at the end of each line by: :match ErrorMsg /\s\+$/ Can I put all the error I found into quickfix windows that I can go ...
0
votes
1answer
12 views

What is making my configuration enter operator pending mode on new session? [duplicate]

I've been reading through Learn Vimscript the Hard Way and trying some exercises. When I got into the autocommands/autogroups part, I've thought of creating an autocommand to automatically trim ...
0
votes
1answer
36 views

How can I automatically preform operations when a vim *window* is resized?

I'm setting up NeoFormat/ALEfix-style code reformatting, and I'd really like to have it automatically and fluidly reformat the code as the window is resized. This is possible for whole-viewport vim-...
1
vote
0answers
48 views

Vim not recognizing markdown and tex files

Here is a sample of my .vimrc, that doesn't do a thing (the autocmd does not work) when I open a .md or .tex file, but works fine for .py files: augroup filetype_python autocmd FileType python ...
1
vote
2answers
74 views

Vim autocommand based on username - print message

I have a function in my bashrc that checks if a file is writable with [ -w "$1" ]. If it is, I open it with vim normally. If it's not, I open with sudo via sudo env HOME="$HOME" vim -u ~/.vimrc "$1" ...
2
votes
1answer
40 views

Renaming an augroup in vimrc

Let's say I rename a augroup in my vimrc; what happens then? Do the autocmds inside that augroup get loaded twice? For example, let's say I rename the following augroup augroup testgroup autocmd! ...
0
votes
0answers
66 views

Display output of a shell command in vim-airline status upon every save

I have access to both vim8.xx and neovim. For the vim-airline plugin for filetype tex, I'd like to add the output from the following shell command each time the buffer is saved to disk. texcount -sum ...
1
vote
1answer
37 views

Dynamically toggle formatoptions based on input

Question: Is there a way to control the indentation + comment leader input, when adding a new line? Details: I am trying to set formatoptions-=cro when inserting a new line (in specific syntax region)...
0
votes
1answer
30 views

autocmd buffer local mapping if not *.py file

As the title stated autocmd BufRead,BufNewFile not-py-file nnoremap <buffer> <F3> :call some_func<CR> is what I want to acheive, but I don't know how to implement that not-py-file ...
1
vote
1answer
130 views

Substitute all tabs with four blank spaces

The following command will substitute all tabs in a file with four blank spaces: %s/\t/ /g In order to run this command whenever I open a new file I included it in my .vimrc by adding: autocmd ...
0
votes
0answers
99 views

Disable paste mode entirely

I get what paste mode does for you, but I have never found it particularly useful. I would like to completely deactivate it. I don't see an option to do so when looking at :help paste. However, I ...
1
vote
0answers
48 views

How vim doesn't expand Ex commands in autocmd?

I'm trying to pass a command to 'vim-tmux-runner' on each file save with au bellow. autocmd FileWritePost,BufWritePost *.py :VtrSendCommandToRunner python manage.py test <afile>:p:h:t Where: :...
0
votes
0answers
52 views

`au BufNewFile * startinsert` slows opening new files down a lot

If I want to always start in insert mode in new files, I can do so with this line in my rc. au BufNewFile * startinsert Doing so when starting a new instance of VIM works quite well. But if I open a ...
5
votes
1answer
196 views

Strange behaviour of autocmd

After starting neovim with nvim -u NONE, why do the following commands :term :au BufWinEnter,WinEnter <buffer> startinsert :tabnew leave me in insert mode in the new tab, and how can I avoid ...
2
votes
1answer
79 views

How to use “FocusGained” to stop my cursor from moving

I tend to use GVim a lot. Very frequently, I'll click on some other window and then when I click on vim to regain focus, my cursor will end up in some random location depending on where I clicked. I ...
1
vote
0answers
36 views

Lint when finished writing a line

How could I have ale lint when finishing typing a line? Maybe on new line? let g:ale_lint_on_text_changed = 'never' autocmd NewLine ALELint
0
votes
2answers
34 views

Unable to detect filetype which is set forcefully inside a custom plugin

I have following line in my vimrc- autocmd BufRead,BufNewFile *.COB,*.PCO set filetype=cobol "force filetype as cobol for .COB and .PCO files And I have put below lines in my custom plugin at the ...
1
vote
1answer
62 views

formatoptions for hybrid (short markup + long paragraphs) content

I am trying to write my PhD thesis in vim using LaTeX So the documents will have two distinct types of content - markups that are relatively short, and paragraph text that is rather long. \begin{...
1
vote
2answers
73 views

How to not trigger InsertLeave inside an imap?

When you want to leave insert mode, it's possible to avoid to trigger the InsertLeave event by pressing Ctrl-C instead of Esc. But when I try to use this method inside an insert mapping, it still ...
1
vote
1answer
32 views

autocmd! tries to parse comment

The docs say: :autocmd adds to the list of autocommands regardless of whether they are already present. When your .vimrc file is sourced twice, the autocommands will appear twice. To avoid ...
0
votes
0answers
44 views

Setting path on VimEnter autocmd

I am trying to follow Exclude some paths from :find path to set my path for Rails projects. Here is the code: let g:project_find_path = '.,' . system("git ls-tree -d HEAD --name-only | tr '\n' : | ...
1
vote
1answer
243 views

Clear ALL autocommands

I have many autocommands in my vimrc. Some of them do have the augroup wrapping to make them not duplicate when re-sourcing the vimrc, but many do not. Rather than try to wrap all of them at this ...
2
votes
2answers
55 views

Using `TabEnter` and `FileType` in the same `autocmd`

I would like to set set spell whenever I open a tex file. My first attempt is autocmd FileType tex setlocal spell I am using setlocal here because I may open other files in new tabs after opening a ...
0
votes
0answers
56 views

Execute an autocmd inside a particular window split

I am trying to achieve a layout similar to the one below. I can do it manually but I want Vim to start in this layout. There are three screen splits. On the left, NERDTree is displayed. On the top, ...
1
vote
0answers
54 views

How does one automatically run a function when any error message appears?

I would like to play sounds for accessibility reasons. Do I need to patch and compile (neo)vim to provide some sort of OnError autocmd? edit: more generically I'm looking for a way to hook into ...
1
vote
1answer
266 views

Delay before running vim command?

This is probably just a bandaid for a greater problem, but I had the following code for MacVim (GUI mode) in my .vimrc autocmd GUIEnter * winpos 100 50 The problem is it's not working properly on ...
2
votes
1answer
197 views

Vim never shows line number for Python files even though I have `.vimrc`

I found it strange that I can never have Vim show line number automatically for .py files, even if I have this as my ~/.vimrc set background=dark autocmd FileType py,c set number Strangely enough, ...
0
votes
0answers
73 views

How to close the Tagbar panel when it's the last window in a tab?

How to close the Tagbar panel when it's the last window in a tab? It is often remains when file is closed.
2
votes
1answer
139 views

How do you clear highlighting if you edit text?

I find it obnoxious that highlight search stays on until you manually turn it off. If I have edited some text after searching, 99% of the time that means I found what I was looking for and I don't ...
1
vote
1answer
77 views

Focus on file when when opening when permanent window for file explorer is enabled

I have a permanent window for file explorer enabled by netrw_altv=1 option. The problem is that when I run vim with file or directory as an argument the window with file explorer is focused. How can I ...
0
votes
1answer
26 views

Deleting an autocmd after it's run

I have this function that I rarely run and it uses matchaddpos. This function highlights at a set position so if I edit text, the same spot is highlighted even though the contents have shifted. I ...
2
votes
1answer
277 views

Set formatoptions for a specific file

In my ftplugin/plaintext.vim script, I have the formatoptions set for editing mostly prose: setlocal formatoptions=tcroqan1j However, in very specific instances -- particularly, Python's idiomatic ...
0
votes
1answer
61 views

norm ^E command works when I type it manually, but fails in an autoloaded vim file. Why?

(Vim 8.0, Windows 7) I wanted to make an autocmd for loading a certain file, that scrolls down five lines from the beginning of the file. It does other things too, so the autocmd itself (inside of an ...
1
vote
2answers
171 views

QuickFixCmdPost autocommand after Glog

I run Glog! from fugitive to populate the quickfix window and set the following autocmd for QuickFixCmdPost (The following questions general and are not specific to Glog, I just use it as example) ...
3
votes
1answer
157 views

autocmd with quickfix window

How can set BufEnter or WinEnter autocmds for entering quickfix window? I tried autocmd WinEnter quickfix echo 'winenter' autocmd BufEnter quickfix echo 'bufenter' None of them works. I doubt that ...
2
votes
1answer
231 views

BufWinLeave * mkview with unnamed file: Error 32

Following this good piece of advice, I have added these lines to my .vimrc. augroup AutoSaveFolds autocmd! autocmd BufWinLeave * mkview autocmd BufWinEnter * silent loadview augroup END It ...
1
vote
2answers
167 views

Are commands in filetype plugins rerun every time the buffer is loaded?

Every time I switch back and forth between two buffers, vim tries to re-load some file specific commands. The error message is E174: Command already exists: add ! to replace it` I am using ...