How do I setup an autocommand to trigger for the preview window's buffer solely? I have one that works on the quickfix window because its filetype is qf, so I can setup a FileType autocommand for it. I've checked quickfix window's buffer FileType but it's empty.
There's no explicit event, but you can easily check for the preview window via the 'previewwindow' option, and combine that with another event, e.g. WinEnter:
:autocmd WinEnter * if &previewwindow | ... | endif
The currently accepted answer didn't solve the problem for me because it only triggered when the preview window was entered, not when it was created.
Thanks to this vim tip, I found that BufWinEnter does fire on preview window creation.
autocmd! BufWinEnter * if &previewwindow | call s:previewWinSettings() | endif
The only times it won't fire are if using :pedit on an already-loaded buffer.
Related
Currently, I'm trying to clean the quickfix window while using cscope and to do that I'm using these commands:
augroup quickfix
autocmd!
autocmd BufRead qf set modifiable
autocmd FileType qf
\ set modifiable |
\ set hidden |
\ execute ":%s/<<.*>>//g"
augroup END
This way whenever a file is opened the <<>> tags are removed. However, since by default the quickfix window is nomodifiable I'm having to force it.
During testing I found that the replacement is executed but the quickfix window is still nomodifiable afterward; therefore I cannot edit its content or use it as notes. Modifiable can be set by hand once the window is opened, but this is not convenient. Maybe I`m missing something or using the wrong event. Can someone explain what is wrong?
It's not urgent to deal with autogroup before you are familiar to them enough.
Just try or do it in your .vimrc with a line like below:
au BufRead errors.err set ma hidden | execute ":%s/<<.*>>//g"
then the quickfix file (usually named as 'errors.err') should be modifiable.
(If you use a different name, substitute it for the 'errors.err', or use a pattern like '*.err'.)
See :h au for further info.
I suspect there is something inherently inefficient about your process of using the quickfix list, but if you wanted to abuse it this way and make it modifiable the following works for me:
au! FileType qf set ma hidden | execute ":%s/<<.*>>//g"
au! BufReadPost quickfix set ma
See :h CTRL-W-<Enter> for some further information.
The vim plugin vdebug opens several splits when it starts the debugger. One of those is DebuggerWatch at the top right. I read somewhere I can set an autocmd to listen for that buffer opening and take action. In this case I want to run :resize 100 to maximize the height. I know how to set an autocmd by filetype or by file glob, but not by a buffer name that is not a file. How do I write an autocmd for this?
I was able to resize on entering the buffer like this:
augroup vdebugwatchpanellarger
autocmd!
autocmd BufEnter DebuggerWatch resize 999
autocmd BufEnter DebuggerStack resize 999
augroup END
This is helpful because at least if I navigate to one of these buffers it will resize them. But I haven't been able to get it resizing on loading the buffer yet. I tried BufRead, BufNew, BufAdd instead of BufEnter. No effect.
The plugin sets the :help 'syntax' option of the "DebuggerWatch" window to debugger_watch so using the :help Syntax event should work:
augroup vdebugwatchpanellarger
autocmd!
autocmd Syntax debugger_watch resize 999
augroup END
I love the linters and the quickfix window, but on occasion I don't want to fix anything and simply want to exit the file. The current issue is that when I close the file, the quickfix window stays open. I know I can use :qa to exit both at the same time, but I often forget to.
I spent a few hours trying to figure out how to close the quickfix buffer if it was the only open window/buffer left, but had no luck.
Anyone else know how to handle this better?
That feature is part of my vim-qf plugin but you don't really need a full-fledged plugin for such a mundane task. Actually, there have been many snippets floating around the internet for many years. Here is one:
augroup MyGroup
autocmd!
if exists('##QuitPre')
autocmd QuitPre * if &filetype != 'qf' | silent! lclose | endif
endif
augroup END
Basically, it closes the current quickfix/location window if it is the last remaining window in the current tab page.
Reference:
:help :augroup
:help :autocmd
:help exists()
:help QuitPre
if version >= 700
" automatically close quickfix if it's the only window left
autocmd WinEnter * if winnr('$') == 1 && &buftype == "quickfix" | quit | endif
endif
In neovim, when my completion plugin is triggered, it will print out the methods signature in a preview window
The preview window though, contains line numbers which is something I want to disable. So far, I though this would work
function! Preview_func()
if &pvw
setlocal nonum
endif
endfunction
autocmd * BufCreate call Preview_func()
But no dice. Any ideas?
In autocommand definition file pattern ( here: * ) should come after event ( BufCreate ); also base on which autocompletion plugin you are using there may be an entrance to preview window or not so also check with WinEnter event:
autocmd WinEnter * call Preview_func()
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 autocmd to solve the issue:
"Automatically maximize help buffers
augroup filetype_help
autocmd!
autocmd BufWinEnter,FileType help wincmd _
augroup END
which only works sporadically.
EDIT:
I have done some further debugging.
Opening a certain help page the first time, e.g. :h au displays it maxmimized when having above augroup in my .vimrc.
Closing the helpfiles window via :q and then reopening the same helpfile a second time causes the help file to be displayed in a split as in the screenshot above.
Closing the helpfiles buffer window via :bd and then reopening it, causes it to being displayed maximized as desired.
How can I rewrite my augroup so that it also maximizes an already opened help buffer?
The BufWinEnter event matches the help filename, so the help pattern (which is fine for a FileType match) won't work. The 'filetype' option is only set once for a buffer, so when it is reused (after :q, but not after :bd), your maximization fails, in the way you've reported.
Instead, have the :autocmd match all buffers, and check for the 'buftype':
augroup filetype_help
autocmd!
autocmd BufWinEnter * if &l:buftype ==# 'help' | wincmd _ | endif
augroup END
I assume you'd like the help window to be horizontally maximized.
Sorry, I can't reproduce your bug (tried on MacVim 7.4-258 and vim 7.4-258), but here are some suggestions:
Try changing wincmd _ to set winheight=9999 in your augroup script.
How about opening the help in a new tab with wincmd T instead?
I think you can achieve your goal of getting your help buffers to be maximized more simply by putting the following in your .vimrc (or wherever), instead of the augroup/autocmd:
:set helpheight=9999
|CTRL-W_o| CTRL-W o close all but current window (like |:only|)