New answers tagged

2

You can examine a match and then decide what to do. Whether to use multiple autocommands or "bar-newline-backslash" is a matter of style. augroup mywritepost | au! autocmd BufWritePost *.md if expand("<afile>") =~? '\.latex\.md$' autocmd BufWritePost *.md call s:makepdf() autocmd BufWritePost *.md else autocmd BufWritePost *.md ...


-1

To prospective downvoters...hold steady. I am realizing that the autocmd pattern matching is really neutered and might not be able to solve the problem as I lay it out. I'd delete this until I can confirm one way or another but I can't...it's been accepted. There's more to the autocmd pattern than *. See :h file-pattern. That gives a little more flexibility ...


2

I believe the problem you're having is due to the command being registered with -buffer, which means it's only available in buffers of filetype "elm" and for some reason are not available in the autocmd. Why that is happening, I can't really tell... The event you're using (BufWritePost) is a buffer-specific example and I'd also expect it to run while the ...


1

Looks like you try to add an autocommand but remove it instead: 3. Removing autocommands *autocmd-remove* :au[tocmd]! [group] {event} {pat} [++once] [++nested] {cmd} Remove all autocommands associated with {event} and {pat}, and add the command {cmd}. ... Try it without exclamation mark. Also, generally it is a good ...


2

Use :execute like this: augroup LaunchShowContext | au! autocmd BufEnter * \ if get(w:, 'contextlist_open') \ | execute 'autocmd! CursorHold <buffer> call ShowContext()' \ | endif augroup end But note (at least) three problems: 1) You examine window-variable contextlist_open, while expecting buffer-specific event ...


3

The InsertCharPre event doesn't trigger for characters such as <Enter> or <Tab>. Instead, use an insert-mode mapping to call a function after pressing <Enter>: inoremap <CR> <CR><C-O>:call MyFunc()<CR> Or use a map-<expr> and have your function return the string to be inserted. Start that with "\r" if you'd ...


0

There are two possibilities: Move the check to after plugins have been loaded, e.g. by hooking into the VimEnter event, as outlined by @ChristianBrabandt's answer. Force early loading of the plugin: runtime! plugin/goyo.vim " Try loading the plugin. if exists(":Goyo") " ...


Top 50 recent answers are included