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
1
vote
1answer
56 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
26 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
22 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
27 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
57 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 ...
0
votes
1answer
20 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
73 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
17 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
20 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
23 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
36 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
67 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
26 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
23 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
39 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
59 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
22 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
63 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
31 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
29 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
48 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
107 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
44 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
30 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
72 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
26 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
31 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
26 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
59 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
74 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
22 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
15 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
31 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
75 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
132 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
40 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
10 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
35 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
111 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
24 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
45 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
26 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
29 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
57 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
50 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
391 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
2 3 4 5 6