Vdebug - maximize DebuggerWatch window on load - vim

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

Related

Make quickfix buffer modifiable

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.

Highlight lines longer that 80 characters in vim in multiple tabs of the same file

From these two questions:
Vim 80 column layout concerns
Vim syntax coloring: How do I highlight long lines only?
I've extracted the following config for my .vimrc:
augroup vimrc_autocmds
autocmd BufEnter * highlight OverLength ctermbg=darkred ctermfg=whitee guibg=#FFD9D9
autocmd BufEnter * match OverLength /\%>80v.\+/
augroup END
This works fine for highlighting lines longer that 80 characters in vim,
but when I open another tab of the same file using:
:tab split
the highlighting doesn't work in the new tab, only in the original one. How can I achieve the same effect for the new tab?
Here is a cleaned up version of your snippet:
highlight OverLength ctermbg=darkred ctermfg=white guibg=#FFD9D9
augroup vimrc_autocmds
autocmd!
autocmd BufEnter,WinEnter * call matchadd('OverLength', '\%>80v.\+', -1)
augroup END
The autocommands in that group are properly cleared when/if you reload your vimrc.
The BufEnter event is only triggered once, you need to listen to another event, WinEnter, which is triggered when a window gets the focus.
matchadd() is more flexible than :match and allows you to set the priority of the highlighting (useful if you rely on hlsearch).

Exclude quickfix buffer from `:bnext` `:bprevious`

The quickfix buffer (opened with :cope after a :make for instance) is included in the :bnext :bprevious navigation which I use very frequently (having mapped it to the arrow keys). I never want to navigate to the quickfix buffer that way however. Is there a good way to exclude it?
Here is a simple solution:
augroup qf
autocmd!
autocmd FileType qf set nobuflisted
augroup END
See :help 'buflisted'.

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 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|)

sourcing vimrc when opening a file in tab page?

I have a the following in my vimrc to highlight any lines that go past 80 columns:
highlight ColorColumn ctermfg=red ctermbg=bg
call matchadd('ColorColumn', '\%81v.\+', 100)
It works great in most cases. However, I've noticed that if i open a file in a new tab, it doesn't work at all. I'm able to fix this by :source $MYVIMRC. But the issue is, when I source my vimrc I lose my indentLines plugin. I've done a little testing, and I have found that the indentLines goes away anytime the vimrc is sourced in an open instance of vim. Still, I am unable to determine why the 2 lines shown above are not being called when I open a file in a new tab. Any ideas?
my vimrc
The matchadd() only affects the current window. In order to have it on all windows you can add the following to your .vimrc:
if exists("*matchadd")
augroup colorColumn
au!
au BufEnter * call matchadd('ColorColumn', '\%81v.\+', 100)
augroup END
endif
Edit: As pointed by Ingo on the comments, the BufEnter will trigger many times when it is not necessary. The lines below correct this issue:
if exists("*matchadd")
augroup colorColumn
au!
au VimEnter,WinEnter * call matchadd('ColorColumn', '\%81v.\+', 100)
augroup END
endif

Resources