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
3
votes
1 answer

How to change vim working directory when navigating on NERDtree

in NERDtree if you press C it changes the root of the NERDtree for the folder under the cursor. i'd like to change vim's working directory (like when you use: :lcd \path\to\directory) by using this command. anyone knows a way of doing it??
vhoyer
  • 764
  • 8
  • 16
3
votes
2 answers

Insert vim variables into text for comment shortcut

I have a simple goal: Map Ctrl-C, a command I don't think I've ever used to kill vim, to automatically insert at the beginning of a line the correct character(s) to comment out that line according to the file's filetype. I figured I could use an…
physicsmichael
  • 4,793
  • 11
  • 35
  • 54
3
votes
1 answer

Run/Toggle command for certain filetypes only

I found this nice plugin for distraction free writing named Goyo, which is really well done. I setup autocmds to enable Goyo based on the filetype, so if I work on a markdown or textfile Goyo gets initialized automatically. If I leave the buffer or…
Saucier
  • 4,200
  • 1
  • 25
  • 46
3
votes
3 answers

How to prevent global defaults from overriding 'filetype=vim' specific settings in .vimrc when automatically sourcing .vimrc?

Context I have my .vimrc automatically being sourced with: autocmd! BufWritePost ~/.vimrc source ~/.vimrc I also set defaults for spacing: set tabstop=2 softtabstop=2 shiftwidth=2 expandtab Later on, I use the FileType event to override the spacing…
Pedro Cattori
  • 2,735
  • 1
  • 25
  • 43
3
votes
2 answers

Automatically append current date to file name when saving in Vim

I'm using vim to take notes while reading academic articles. I prefer to have a new text file for each note I've taken, but organizing them becomes tedious. What I would like to do is set an autocommand to detect if I'm in a certain directory,…
3
votes
4 answers

How do I tidy up my vimrc file?

My Vim configuration file is getting bigger (15KB+). And I try not to make my vim launch slower by sourcing more (larger) files at startup. For the same purpose I use only essential plugins and I try to keep the number of plugin as less as possible.…
Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
2
votes
2 answers

Vim: Saving on FocusLost and executing auto command

I've setup my vim editor (I use MacVim) to save files automatically when the focus is lost: autocmd FocusLost * silent! wall I also automatically strip trailing whitespace from python files using this auto command: autocmd BufWritePre *.py…
GaretJax
  • 7,462
  • 1
  • 38
  • 47
2
votes
3 answers

How to get the Help window to always open in the same position?

I do this for opening help pages in vertical window: cabbrev help vert botright help this way, it is ok, but a bit disturbing, and it is spamming my :history a bit too. I would like to get Vim to not expand this, just run the command. So when I…
kissgyorgy
  • 2,947
  • 2
  • 32
  • 54
2
votes
2 answers

Autocmd InsertEnter in init.lua to highligh cursor does not work

I am migrating from a well tested and used for years init.vim to a new init.lua. The last two lines do not show errors but they do not work. The idea is to show an underline when I enter insert mode and remove it when in normal mode. In…
Samuel Gómez
  • 877
  • 1
  • 6
  • 7
2
votes
1 answer

Vim - calling buffer events when moving to other window with same buffer

if I have a file open in vim and use the command ":split", it splits the same buffer into two windows. In my vimrc I have this commands: autocmd BufEnter * set cursorline autocmd BufEnter * set cursorcolumn autocmd BufLeave * set…
DasOhmoff San
  • 865
  • 6
  • 19
2
votes
1 answer

How to make vim move cursor a character to theright on insertleave?

Since mac os x's terminal.app does not support many of the vim visual aspects, including the cursor change from block to line when switching to insert mode, I use osascript to accopmlisch something similar. In my .vimrc file I've written: autocmd…
romeovs
  • 5,785
  • 9
  • 43
  • 74
2
votes
1 answer

Autocomplete a python Shebang (in a non .py file) by mapping to an autocmd

I am learning Vim and I have successfully set up my .vimrc file such that whenever I make a new python .py file, the appropriate shebang and header are auto-generated. Yay me! However, when building terminal pipelines I don't always like to include…
Dave L
  • 77
  • 11
2
votes
1 answer

Vim: Understanding local settings - when to use buffer local vs setlocal?

In a line like autocmd InsertEnter setlocal foo=bar, are and setlocal redundant? What are the functional differences between each of the following? autocmd InsertEnter setlocal foo=bar autocmd InsertEnter set…
Kvass
  • 8,294
  • 12
  • 65
  • 108
2
votes
1 answer

how to auto update file path in file header with autocmd in vi/vim?

I have a function in my .vimrc that automatically updates the file I'm currently editing with the timestamp (Modified) of the last 'save' (:w). I would like to also update the Filename and Filepath. I have an autocmd that updates the filename…
2
votes
1 answer

vim function only works properly the first time

I wrote a function in vim to insert text in "paste"-mode. If I leave the insert mode, the script also leaves the paste mode (set nopaste). Therefore I used the autocommand InsertLeave. The Problem is, that the "set paste" command works only the…
miu
  • 1,234
  • 2
  • 18
  • 34