Permalink
Browse files

vim: better quickfix interaction

  • Loading branch information...
majutsushi committed Apr 6, 2013
1 parent adaa37c commit 7dc8e020979f2f084c6a8ba9ae31567756039a12
Showing with 22 additions and 7 deletions.
  1. +1 −3 vim/vim/ftplugin/qf.vim
  2. +21 −4 vim/vimrc
View
@@ -1,7 +1,5 @@
" Author : Jan Larres <jan@majutsushi.net>
" Website : http://majutsushi.net
-" Created : 2012-03-11 17:01:26 +1300 NZDT
-" Last changed : 2012-05-14 23:57:42 +1200 NZST
let b:stl = "#[FileName][Quickfix List]#[FunctionName]"
@@ -12,6 +10,6 @@ setlocal foldmethod=marker
setlocal foldmarker=Entering\ directory,Leaving\ directory
nnoremap <buffer> <silent> zq zM:g/error:/normal zv<CR>
nnoremap <buffer> <silent> zw zq:g/warning:/normal zv<CR>
-nnoremap <buffer> <silent> q :close<CR>
+nnoremap <buffer> <silent> q :call QuickfixToggle()<CR>
" normal zq
View
@@ -792,6 +792,27 @@ function! QFDo(command)
endfor
endfunction
+" QuickfixToggle() {{{2
+" Source: http://learnvimscriptthehardway.stevelosh.com/chapters/38.html
+function! QuickfixToggle()
+ if s:quickfix_is_open
+ cclose
+ let s:quickfix_is_open = 0
+ execute s:quickfix_return_to_window . "wincmd w"
+ else
+ let s:quickfix_return_to_window = winnr()
+ if &lines / 4 < 10
+ botright copen 10
+ else
+ execute 'botright copen ' . &lines / 4
+ endif
+ let s:quickfix_is_open = 1
+ endif
+endfunction
+
+let s:quickfix_is_open = 0
+nnoremap <leader>q :call QuickfixToggle()<cr>
+
" RunShellCommand() {{{2
function! s:RunShellCommand(cmdline)
botright new
@@ -1987,10 +2008,6 @@ inoremap <M-l> <Esc>la
inoremap <M-k> <Esc>gka
inoremap <M-j> <Esc>gja
-" quickfix
-nnoremap <expr> <leader>co &lines / 4 < 10 ? ':botright copen 10<cr>'
- \ : ':botright copen <C-r>=&lines / 4<cr><cr>'
-
" display the number of matches of current search pattern
nnoremap g/ :%s/<C-R>=&ignorecase ? '\c' : '\C'<CR><C-R>///gne<CR>

0 comments on commit 7dc8e02

Please sign in to comment.