Wednesday, September 29, 2010

Re: Split windows and spanning width of screen

On 09/29/2010 06:44 PM, Thomas Adam wrote:
> Also:
>
> * Is there a way to always map the command ":copen" to provide:
>
> :botright copen

I don't open the quickfix window manually often enough that I've
made such a mapping. But I believe this wiki page points out
some techniques for doing what you're asking:
http://vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev

However, I mostly find that I'm lazier than that. I'd like the
quickfix window to open automatically. My most common use of
the quickfix window is in conjunction with the Grep plugin:
http://www.vim.org/scripts/script.php?script_id=311

This plugin does the ":botright copen" command automatically
after a search has been performed. I often already have the
quickfix window open because of a prior search, so if I use
something like :cfile to populate the quickfix list, I often
don't need to manually open the quickfix window.

But I've also mapped <F4> and <s-F4> to be, essentially, :cnext
and :cprev, with the added benefit that a ":botright copen" is
done automatically in case the window isn't open. So if the
window's not already open, I can do <F4><s-F4> to bounce forward
and backward, just to get the side-effect of :botright copen.
If all that fails, I just manually type :botright copen myself
:-)

Below are my mappings for <F4> and <s-F4>. Recently I added
another feature (based on a posting in this newsgroup, IIRC).
When a "diff" window is active, the above mappings go forward
and backward through the diffs instead of through the quickfix
list. Finally, I also like to scroll the window to put the
match in the center of the screen, which is what the "normal zz"
commands are doing.

-------- Start of mappings for message browsing ---------
function! GotoPrev()
if &diff
normal [czz
else
botright copen
wincmd p
try
cprev
normal zz
catch
echo "No previous QuickFix messages"
endtry
endif
endfunction

function! GotoNext()
if &diff
normal ]czz
else
botright copen
wincmd p
try
cnext
normal zz
catch
echo "No more QuickFix messages"
endtry
endif
endfunction

" Setup message browsing using F4/Shift-F4. If the current
" window is in diff mode, does diff next/prev; otherwise,
" does :cnext/:cprev for QuickFix messages, opening the
" QuickFix window if necessary.
" Automatically scrolls the message to the center of the window.
inoremap <silent> <F4> <C-O>:call GotoNext()<CR>
nnoremap <silent> <F4> :call GotoNext()<CR>
inoremap <silent> <S-F4> <C-O>:call GotoPrev()<CR>
nnoremap <silent> <S-F4> :call GotoPrev()<CR>
-------- End of mappings for message browsing ---------

Michael Henry

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment