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

autocmd vimenter isn't run by MacVim

As a solution to the problem described in the question Why does vim not obey my expandtab in python files?, I have added this to my vimrc: let g:use_tabs = 1 let g:indent_width = 4 let g:tab_width = 4 function! SetIndent() if g:use_tabs …
Tyilo
  • 28,998
  • 40
  • 113
  • 198
1
vote
1 answer

Use variables/lists as an autocmd pattern

Is it possible to use variables or lists to pass patterns to vim's autocmd? Here is an example: " Automatically source .vimrc if there have been any changes let candidates = [ ".vimrc", "_vimrc", "vimrc", ".gvimrc", "_gvimrc", "gvimrc" ] augroup…
Saucier
  • 4,200
  • 1
  • 25
  • 46
1
vote
1 answer

how to move buffer position in vimscript

I'm trying to use an autocmd to check for the existence of a certain file when a file is opened. If the file exists, I want to do a vsplit, and move the vsplit buffer to the right. Something like: function! CheckForFile() let…
d0c_s4vage
  • 3,947
  • 6
  • 23
  • 32
1
vote
1 answer

vim: new file's directory did not match the current working directory when autocmd was applied

I'm starting using vim to edit my python code and I want vim to save codes under different folders according to different suffixes like '.py'. So, I added this into my gvimrc file (I'm using MacVim indeed, but the same problem appears on vim) au…
Yang Yushi
  • 725
  • 4
  • 20
1
vote
1 answer

How to setup a file pattern for autocmd to not match the command line buffer?

I have an au command to check if a file had been changed: autocmd CursorHold * checktime But when I launch a command line window with q: or with q/ than I get the following error: Error detected while processing CursorHold Auto commands for…
Gabor Marton
  • 2,039
  • 2
  • 22
  • 33
1
vote
4 answers

In vim, how can I automatically maximize the help window

When I display a vim helpfile by running e.g. :h au, the help is displayed in a horizontal split window: Currently I always run Ctrl+w _ but I would prefer the help buffer to open in a maximized window automatically. I've tried to create an…
jottr
  • 3,256
  • 3
  • 29
  • 35
1
vote
2 answers

Vimscript autocmd function fail

" ---------------------------------------------------------------------------- " Functions " ---------------------------------------------------------------------------- function! g:UltiSnips_Complete() call UltiSnips#ExpandSnippet() if…
Michaelslec
  • 905
  • 1
  • 9
  • 20
1
vote
1 answer

How to set two autocmd BufWritePre in .vimrc

On save/write in VIM I want to trim trailing whitespace and ensure that the file's line endings are UNIX and not DOS. Both of these commands work on their own, but I can't figure out how to get them to BOTH run on write/save of a file in…
Jesse Atkinson
  • 10,586
  • 13
  • 42
  • 45
0
votes
1 answer

Vim autocmd read .vim file

I put the SyntaxAttr.vim file in the ~/.vim/autoload folder. I want to use autocmd command to set the autoload event. How should I do it. Autoload the SyntaxAttr.vim.
cklin
  • 1
  • 1
0
votes
0 answers

How to add file creation date, user, file name, and file path to header template when creating a new file in VIM / GVIM (v7.4)?

I have a default header file that is loaded by the following command in my ~/.vimrc : autocmd bufnewfile * so /home/username/.vim/header.txt It looks like this: ###################################################### # File name: # File path: …
randyest
  • 1
  • 2
0
votes
0 answers

Vim autocmd inoremap works wrong when just single character in "<>"

I've been using vim to write html files recently. I'm so sick of the <...> and <\...>, so I write some inoremap for convenience in a vim file: autocmd Filetype html inoremap <>i autocmd Filetype html inoremap
paradoxD
  • 17
  • 5
0
votes
1 answer

:hi Vertsplit doesn't run on autocmd from init.vim

I've been setting up my init.vim file to use NeoVim on Windows 10, and ran into an issue I'm struggling to understand. At the start of my file, I set up a couple of :hi(ghlight) autocmds, and only the VertSplit seems to be ignored on starting. Even…
e_nicolai
  • 108
  • 5
0
votes
1 answer

vim - Run ex command to go to line from function in normal mode

I have a function setup to run on InsertEnter autocmd. In the function I want to jump to a specific line. So what I have tried (simplified) is this so far: function JumpToLineBeforeScroll() echom "function runs" exe ":10" return…
0
votes
0 answers

How to change cursorline color when changing to command mode

This code changes the cursorline color when in insert, normal and replace mode at least but doesn't really work in visual mode and doesn't work at all in command mode. Whats wrong? function Pain() local colors = { bg = "#202328", fg =…
MikiS
  • 11
  • 4
0
votes
1 answer

Exclude help and plugin pages from autocmd pattern

I want to write command like autocmd BufAdd * if &filetype != 'help' | echo 'foo', but it didn't work. I've tried different options: &l:filetype, &buftype, &l:buftype; tried with toggled filetype setting, but nothing changed. Global command autocmd…
pas
  • 13
  • 1
  • 3