New answers tagged

3

You can use the BufRead event in combination with a buffer-local mapping. For example, if I want o in Normal mode to echo Math is rad only when I'm editing a file named foo.bar: autocmd BufRead foo.bar nnoremap <buffer> o :echo "Math is rad"<CR> See: :h autocmd-events :h BufRead :h autocmd-patterns :h map-local


2

Vim’s command separator is |, but it cannot come after certain commands. In this case the simplest workaround is execute: autocmd Event pattern execute '0read !cmd' | 6 Another solution is to use multiple autocommands, as they are executed in sequence: autocmd Event pattern 0read !cmd autocmd Event pattern 6


2

The patterns used in auto-commands are different from normal regexes. In :help file-pattern you'll see that you actually need \\\{m,n\} to specify repetition of an item. So, in your case, what you actually want is: autocmd BufNewFile ~/Documents/wiki/diary/[0-9]\\\{4\}-[0-9]\\\{2\}-[0-9]\\\{2\}.mkd :silent 0r !vimwiki-diary-template.py Note that in some of ...


1

A couple of other tips-n-tricks: with tpope/scriptease, you can use :Vedit (and other variants) to fill the location list with all runtimepath entries matching the provided file (e.g., :Vedit ftplugin/tex.vim) to actually put an autocommand on a specific filetype, such as "automatically run :Require on clojure files when they save," you can use a &...


4

Vim will load filetype-specific commands from an ftplugin. See :help ftplugin. In short, you can create a file under ~/.vim/ftplugin (or %HOME%\vimfiles\ftplugin on Windows), or better ~/.vim/after/ftplugin (or %HOME%\vimfiles\after\ftplugin) named after the filetype for which it should be loaded. For example, when a file is detected with filetype=tex, Vim ...


2

From :h i_CTRL-C (emphasis mine): Quit insert mode, go back to Normal mode. Do not check for abbreviations. Does not trigger the InsertLeave autocommand event. However, you could remap <C-c> as follows: inoremap <C-c> <C-c>:doautocmd InsertLeave<CR> if you really want to use Ctrl+c. See: :h i_CTRL-C :h :doautocmd :h InsertLeave


2

Let's look into vim source code: There is a function which is called when a change was made: https://github.com/vim/vim/blob/85629985b71035608a37ba3bde86968481490d46/src/change.c#L429 This function triggers foldUpdate: https://github.com/vim/vim/blob/85629985b71035608a37ba3bde86968481490d46/src/change.c#L537 Which does folding (including foldexpr): https://...


1

You can update your autocmd to check whether the buffer is of a type that can accept the :write command. For example: autocmd TextChanged,TextChangedI * \ if &buftype ==# '' || &buftype == 'acwrite' | \ silent write | \ endif See :help 'buftype' to see the types of buffer and particularly the ones you might want to :write.


1

After checking out the modes in :h mode(), I use: augroup auto_checktime autocmd! " Notify if file is changed outside of vim " Trigger `checktime` when files changes on disk " https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044 " https://vi.stackexchange.com/questions/13692/...


Top 50 recent answers are included