Questions tagged [autocmd]

Vim commands you can specify to be executed automatically when reading or writing a file, when entering or leaving a buffer or window, and when exiting Vim

Vim's documentation on autocmd: http://vimdoc.sourceforge.net/htmldoc/autocmd.html

113 questions
1
vote
1 answer

Vim autocmd does not map properly a mapping

I want to create a plugin which maps a certain localleader mapping to a function call. I have a ftplugin/javascript.vim file with the following content: augroup javascript_pluginName au! echom "The plugin is loaded for JS" au FileType…
Kokozaurus
  • 639
  • 7
  • 22
1
vote
0 answers

(Neo)vim FocusGained not working as expected

I've setup the Base16 color theme, including Base16-shell and Base16-vim, ( for my terminal (iTerm2) and Neovim. So that I can change themes from the command line I created a bash function that lets me say color and the base16-shell script…
Mark Nichols
  • 1,407
  • 2
  • 19
  • 25
1
vote
2 answers

vim - set filetype in autocmd FileType

I'd like to change filetype in autocmd FileType hook. Thre reason is that I'd like to use NeoMutt syntax file for .muttrc instead of Vim's default syntax file. I've installed NeoMutt's syntax files with Plug manager: Plug 'neomutt/neomutt.vim' And…
1
vote
1 answer

Indent code using vim autocommand

I want use the indent linux utility to indent the current file on saving. I tried autocmd BufWritePre *.[ch] :!indent -kr -nut % in my .vimrc file (~/.vim). Manually I tried that command :!indent -kr -nut % it works only after prompting me to…
1
vote
1 answer

Vim: toggle list in insert mode

I'm trying to toggle the list setting when I enter Insert mode because I find trailing characters appearing & disappearing as I type distracting. These settings don't seem to work (list is still enabled when I enter insert mode): set list if…
Kvass
  • 8,294
  • 12
  • 65
  • 108
1
vote
2 answers

How can I add or/and modify a version-number in Vimrc autocmd

I love to work with Vim. I use the autocmd in ~.vimrc like: :fun LastMod() : if line("$") > 20 : let l = 20 : else : let l = line("$") : endif : exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " . : \…
amaz1ng
  • 13
  • 5
1
vote
1 answer

Executing C code with F5 key in Vim

I want to save and execute my codes that's written in C programming language with just pressing F5 key in vim (in normal mode). So I added this line to .vimrc file : :autocmd FileType c nnoremap :w!:!clear && gcc % && ./ But…
user7274303
1
vote
1 answer

Autocmd in vim not calling the function

" Python logger-print and vice-versa function! SetPrintLogMaps() echom "called" nnoremap lp "lyy"lp"l5cawprint^[ nnoremap ll "lyy"lp"lcawself.logger.info(^O$)^[ endfunction autocmd BufWrite,BufRead…
1
vote
1 answer

vim autocmd: Event based removal and addition of group commands

I am using quickfix and I have it set up so that a cwindow is run right after a Quick fix command. Also, I have a template file for my C++ source files which I want to be copied at the beginning of my new source files. Here is my .vimrc: augroup…
cauthon14
  • 269
  • 1
  • 3
  • 14
1
vote
1 answer

is it possible to set BufLeave autocmd in vim on the fly?

What I want to do: Inside a file/buffer in vim, especially an unnamed one (for example, created with :enew), sometimes I feel the content I'm writing is worth saving (say, I suddenly want to send it via an email), but don't feel the particular need…
1
vote
1 answer

Autocmd bufnewfile causing "Trailing characters" error on relative paths

I am having issue with my .vimrc file. I have completed an autocommand for all python and sh files. I have included both below. All works as expected when using a direct path ie: gvim test.py If I use a path relative to the cwd, however, such…
kennedyl
  • 181
  • 1
  • 12
1
vote
0 answers

Vim multiple autocmd on BufWritePre

I am using both Chiel92/vim-autoformat and ntpeters/vim-better-whitespace. The first is for autoformat code and the second is for remove extra whitespace. Both of them I hope to use autocmd to call them on save files. It seems that I am not using…
dragonxlwang
  • 462
  • 5
  • 13
1
vote
1 answer

Vimrc autocmd runs command instead of mapping

I want to add a hotkey to my vim to run my python files, so I have added the following line to my vimrc: autocmd FileType python map :w|!python3 % But on opening the file instead of running autocmd, it runs python with my file. For me this…
1
vote
1 answer

In Vim, is it possible to set a variable based on the first lines in the file that is being opened?

I would like vim to detect and store the number of commented lines (prefixed with #) from the start of a file and then use a variable with the stored value to change a vim-setting in a file-specific manner. Example: If I open this file: # Comment…
joelostblom
  • 43,590
  • 17
  • 150
  • 159
1
vote
1 answer

autocmd not applied from ~/.vimrc

How can I get my vim to apply the autocmd without manual reloading of ~/.vimrc? And why is the ... Filetype tsv ... never applied at all? My ~/.vimrc set ts=10 autocmd BufWrite * :echom "Writing buffer!" autocmd Filetype tsv set ts=20 sts=20…
Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118