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
0answers
4 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
26 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
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/....
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
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
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
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
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 ...
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 ~/....
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,...
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 ...
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'...
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
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 ...
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
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 ...
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 ...
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
vote
1answer
62 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
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 ...
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
117 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
71 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
60 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
58 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
2 3 4 5 6