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.
Related
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
The :Gstatus window has specific mappings for that particular buffer. In my case, I would like to change the cc mapping to not only execute :Gcommit but also go into insert mode afterwards.
It seems like the user robodendron figured out how to do this as shown in https://github.com/tpope/vim-fugitive/issues/647, but I'm don't know what he means when he says "changing the order should be enough." Also, I would ask this on the Git issues page, but it seems like the user NicolasWebDev already tried that and no one got back to him.
I can add mappings by creating a after/ftplugin/gitcommit.vim file, but modifying an existing mapping seems to be more difficult since the mapping is defined after the filetype is set.
Also, I could modify the source code mappings, but we all know that's more of a temporary fix.
I am not sure about trying to alter :Gstatus mappings, but you can start insert mode when entering the commit buffer.
Add the following to your vimrc file:
augroup turbo_commit
autocmd!
autocmd BufEnter COMMIT_EDITMSG startinsert
augroup END
For more help see:
:h :autocmd
:h :augroup
:h BufEnter
:h startinsert
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'.
I have the following problem, or lets say idea, with vim. When I am writing latex documents I want automatically open a file ~/.vim/latex_hints, where I collected some hints, shortcuts, workarounds,..., in vsplit on the right side. The hint file should be loaded read only and automatically closing when I close the latex document.
After a few experiments I added the following commands to my vimrc:
function Handletexfile()
setlocal cc=80
setlocal wrap
setlocal textwidth=80
belowright vsplit +setl\ ro\ nomodifiable ~/.vim/latex_hints
endfunction
autocmd BufRead,BufNewFile *.tex call Handletexfile()
and
function Handletexfileexit()
let tablist = []
call extend(tablist, tabpagebuflist(tabpagenr()))
for b in tablist
echo b . " ". bufname(b)
if bufname(b) =~ "vim/.*_hints"
echo "Close buffer..". b
execute "bdelete! ".b
endif
endfor
endfunction
autocmd BufWinLeave *.* call Handletexfileexit()
When I open a tex file, my hint file is displayed on the right side as read only and not modifiable. But when I close using :q or :wq the buffers open in the current tab are listed and the one matching to the hint file is selected by the if statement. But I get the following output
1 abstract.tex
2 ~/.vim/latex_hints
Close buffer..2
and my vim crashes with an segfault.
The first part of your requirement translates pretty straightforward into Vimscript:
autocmd BufWinEnter <buffer> belowright vsplit +setl\ ro ~/.vim/latex_hints
Put this into ~/.vim/after/ftplugin/tex.vim, or prepend :autocmd FileType tex to the above command.
The latter part is more complex; on BufWinLeave, you'd have to check all other windows for the opened cheat file with bufwinnr(), go to it (:wincmd w), and :close it.
As an alternative use the preview window with your hint file. The preview window gives you some advantages:
It is small and out of the way
Can close it easily via <c-w>z from any other window
Can jump to the preview window from any window easily via <c-w>P (jump back via <c-w>p)
You can do this via the :pedit command. For example:
autocmd BufWinEnter <buffer> pedit +setl\ ro ~/.vim/latex_hints
Personally I feel like it would be better to create command or mapping to open your hints files as you may eventually out grow the file as time goes on. I would also set the 'bufhidden' to wipe and un-list the buffer with 'nobuflisted'.
You may also want to look into getting a nice snippet plugin.
So, I'm pretty happy that I've discovered how to set highlighting when I open a particular file in vim. I'm doing this for JavaScript files, so most of them are 'hi jsStringD' and 'hi jsFunction' etc.
I use this to trigger it:
if has("autocmd")
augroup JavaScript
au!
au BufReadPost *.js call SetUpJavaScript()
augroup END
...
I also want to change the color of 'Normal' or foreground text, but only for JavaScript files.
This works to set the color:
execute 'hi Normal ctermfg=' normalText
But how do I limit it only to a certain filetype? This results in all files having 'Normal' highlighted to that color.
EDIT: Just to clarify, I open a JavaScript file and it works. I open another file (say a .jade file) and 'Normal' color remains the 'normalText' value.
Use an autocmd that only fires for the javascript file type
autocmd FileType javascript execute 'hi Normal ctermfg=' normalText
However I think this will have problems if you switch between multiple files in one session since highlighting is global.
To work around this you could add another FileType autocmd that fires on BufEnter (or something like that) that sets a default Normal highlighting.
Something like this would work (Although it will change the highlighting in splits when you change focus)
autocmd BufEnter * if (&filetype ==# 'javascript') | execute 'hi Search ctermfg=' . normalText | else | execute 'hi Search ctermfg=' . defualtText | endif