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

Run a command every time any key is pressed

I want to run a function every time the user presses any key. I have already looked through the autocommand documentation and there does not seem to be one for this. Is there any function I do not ...
1
vote
1answer
32 views

Combine FileType with other events

I'd like to combine two events: FileType and TextChangedI. According to this awesome book I can do that, by adding a comma between both events like this: :autocmd BufWritePre,BufRead *.html :normal gg=...
0
votes
0answers
27 views

Cannot understand how to group autocommands in this case

I downloaded a program called calcurse and it allows me to make notes by making temporary files in /tmp folder. The note files are named as calcurse-note.[some random alphanumeric characters after ...
1
vote
1answer
22 views

Only allow syntax and without other autocmds in popup

I write a lf-like file browser demo as below. Now there is a problem: when preview a file in popup, it can be slow if there exists a lot of autocmds, so I abandon autocmd by vimcmd("noautocmd let ...
2
votes
2answers
46 views

Buffer scope variable not exists when run autocmd BufUnload

Describe the issue I use a vim plugin that when use Vim to open a ipynb (python notebook) file, will call system function to use jupytext create corresponding python file to enable use like, YCM to ...
0
votes
2answers
48 views

How can i make this autocmd BufEnter command work?

i am setting the default vim-statusline, and i made this line on my colorscheme: hi MyStatusLineDevIcon ctermfg=7 ctermbg=0 cterm=NONE So i can color the devicons on my statusline.vim config I call ...
0
votes
2answers
48 views

Can I use a variable in autocmd pat?

I have 3 languages and any can be a source or target so I need some flexibility. I am successfully loading a language translation specific setup with this: let g:tr_source = 'dyu' let g:tr_target =...
1
vote
1answer
35 views

Adding new filetypes with vim commentary

I'm trying to add include an unsupported filetype, gf, with vim commentary. The comments are simple, just prepend -- to any line, as in the Haskell tradition. According to the vim-commentary git, ...
2
votes
1answer
47 views

Why are nested FileType autocommands triggered even ++nested is not used?

From :h autocmd-nested, it says "By default, autocommands do not nest." But nested FileType events are triggered anyway without using ++nested. As seen in this test: autocmd BufNewFile,...
2
votes
1answer
144 views

Disabling relativenumber in Command Mode

I have au InsertEnter * set norelativenumber au InsertLeave * set relativenumber So that I have relativenumber in normal mode but not insert mode. I want to extend this to command mode. I tried ...
2
votes
1answer
54 views

Print bound autocmds to a file

I would like to print all of my current autocmds to a file so that I can grep through and do further analysis. From within vim, the list of autocmds can be found with :autocmd, but this prints to a ...
0
votes
1answer
20 views

ctags: can you ignore matching tags for a specific file extension?

small background: I have a code base with multiple languages: C, C++, Python, Sh, Makefile, Perl. I configure my ctags generation right now to just do: C,C++,Python,Sh. I point vim at the ctags tag ...
1
vote
1answer
46 views

Different word boundaries in command mode

I very commonly use CTRL-W to adjust a previous path in the command line, like I'll bring up the directory of the current file or perhaps a previous :e ... command from history that's close, and use ...
0
votes
0answers
24 views

vim: is possible to use mouse to move lines around

Question: Is possible to use mouse to move lines around? Requirements & Clarification I do know keyboard solutions. normal mode ddp d2j'}p dapggp alike. cmdline commands, :co. '<,'>m'a etc....
1
vote
1answer
34 views

Vim BufLeave event weird behaviour with <c-w><c-f>

How to reproduce Run vim --clean on a file that contains another filename. Now run these commands :set number relativenumber :autocmd BufLeave * set norelativenumber | echoerr "BufLeave ...
1
vote
1answer
162 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
66 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
44 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
56 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
63 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 ...
1
vote
1answer
50 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
76 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
19 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
23 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
28 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
72 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
77 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
87 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
25 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
41 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
20 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
63 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
46 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
102 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
35 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
32 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 ...
2
votes
2answers
181 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
80 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
38 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
168 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
19 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
50 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
53 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
14 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
27 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
75 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
77 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
28 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&...

1
2 3 4 5 6