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
8 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
27 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>...
41
votes
3answers
13k views

Why should I use augroup?

I understand how auto commands work, and how to use them, but I'm somewhat unsure of what augroup is for. I read in :help augroup *:aug* *:augroup* :...
1
vote
1answer
88 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
46 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/....
0
votes
2answers
268 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
20 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
20 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
2answers
56 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
0answers
12 views

Change match highlights 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 ...
0
votes
2answers
274 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 ...
0
votes
1answer
36 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
19 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
1answer
19 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
53 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 ...
2
votes
1answer
30 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
26 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
2answers
84 views

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 ~/....
1
vote
0answers
46 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 ...
3
votes
1answer
96 views

Event SourcePost doesn't exist

While searching for autocommands event I noticed that there are no SourcePost event. This is strange, because nearly all of other event have a Post version of it (e.g. FileAppendPost, BufWritePost, ......
16
votes
2answers
5k views

What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?

I've gone through the autocmd.txt help, but the information about this is scattered and not always present (eg. with BufRead). Could someone who understands this well list the order of these events -...
7
votes
1answer
1k views

Trouble to call a bash command from vimrc with autocommands | “Error: no previous command” (neovim)

basically i want to test within my vimrc, if /home/$USER/.dotfiles/nvim/bundle/vim-snippets/snippets was symlinked to /home/$USER/.dotfiles/nvim/snippets If not, it should create the symlink. the ...
0
votes
1answer
40 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
29 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
39 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
24 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
29 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,...
3
votes
1answer
51 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
2answers
23 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'...
1
vote
1answer
72 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
14 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
56 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
93 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
32 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 ...
1
vote
2answers
95 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 ...
39
votes
5answers
8k views

How do I save a file in a directory that does not yet exist?

Suppose I start Vim to edit a new file in a directory that is not yet created: vim nonExisitingDirectory/newFile.txt Vim will happily show me an empty buffer and I can start writing my new file. But ...
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
33 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
62 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
36 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
19 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
48 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 ...
1
vote
1answer
27 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
52 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 ...
3
votes
2answers
363 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
23 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
2 3 4 5 6