├── README.md ├── autoload └── togglequickfix.vim └── plugin └── toggle-quickfix.vim /README.md: -------------------------------------------------------------------------------- 1 | # Toggle Quickfix Window 2 | 3 | `quickfix` is a special buffer for viewing errors and warnings from command 4 | `:make` or matching lines from vim plugin [grep][grep]. 5 | 6 | This plugin provides one simple key binding to toggle quickfix window 7 | instead of using the redundant command `:copen` and `:close`. 8 | 9 | ## Installation 10 | 11 | Installing with [pathogen.vim](https://github.com/tpope/vim-pathogen) 12 | is recommended. Copy and paste: 13 | 14 | ```sh 15 | cd ~/.vim/bundle 16 | git clone git://github.com/drmingdrmer/vim-toggle-quickfix.git 17 | ``` 18 | 19 | Or just copy all of the files in to `~/.vim`. 20 | 21 | ## Key Binding 22 | 23 | To use `Ctrl-g Ctrl-o` to toggle quickfix and location list window, 24 | add these following lines into your `.vimrc`: 25 | 26 | ``` 27 | nmap window:quickfix:loop 28 | ``` 29 | 30 | Then `` loops over these 3 state: 31 | 32 | ``` 33 | quickfix locationlist 34 | -------- ------------ 35 | closed closed 36 | once open closed 37 | twice closed open 38 | three times closed closed 39 | forth times ... 40 | ``` 41 | 42 | [grep]: https://github.com/vim-scripts/grep.vim.git 43 | -------------------------------------------------------------------------------- /autoload/togglequickfix.vim: -------------------------------------------------------------------------------- 1 | fun! togglequickfix#ToggleQuickfix() "{{{ 2 | let nr = winnr("$") 3 | cwindow 4 | let nr2 = winnr("$") 5 | if nr == nr2 6 | cclose 7 | endif 8 | endfunction "}}} 9 | 10 | fun! togglequickfix#ToggleLocation() "{{{ 11 | let nr = winnr("$") 12 | lwindow 13 | let nr2 = winnr("$") 14 | if nr == nr2 15 | lclose 16 | endif 17 | endfunction "}}} 18 | 19 | fun! togglequickfix#IsOpened(typ) "{{{ 20 | if a:typ == "qf" 21 | let ids = getqflist({'winid' : 1}) 22 | else 23 | " query location list window 24 | let ids = getloclist(0, {'winid' : 1}) 25 | endif 26 | 27 | return get(ids, "winid", 0) != 0 28 | endfunction "}}} 29 | 30 | fun! togglequickfix#Has(typ) "{{{ 31 | if a:typ == "qf" 32 | let elts = getqflist() 33 | else 34 | " query location list window 35 | let elts = getloclist(0) 36 | endif 37 | 38 | return len(elts) > 0 39 | endfunction "}}} 40 | 41 | " status machine 42 | " ql 43 | " v 44 | " xx -> qx -> xl 45 | " ^ | 46 | " `---------' 47 | let s:sts = { 48 | \"xx":"qx", 49 | \"ql":"qx", 50 | \"qx":"xl", 51 | \"xl":"xx", 52 | \} 53 | 54 | fun! togglequickfix#Loop() "{{{ 55 | let status = "" 56 | if togglequickfix#IsOpened("qf") 57 | let status = "q" 58 | else 59 | let status = "x" 60 | endif 61 | 62 | if togglequickfix#IsOpened("locl") 63 | let status .= "l" 64 | else 65 | let status .= "x" 66 | endif 67 | 68 | while 1 69 | let status = s:sts[status] 70 | if status[0] == 'q' 71 | if togglequickfix#Has('qf') 72 | copen 73 | else 74 | continue 75 | endif 76 | else 77 | cclose 78 | endif 79 | 80 | if status[1] == 'l' 81 | if togglequickfix#Has('locl') 82 | lopen 83 | else 84 | continue 85 | endif 86 | else 87 | lclose 88 | endif 89 | 90 | break 91 | endwhile 92 | 93 | endfunction "}}} 94 | -------------------------------------------------------------------------------- /plugin/toggle-quickfix.vim: -------------------------------------------------------------------------------- 1 | nnoremap window:quickfix:loop :call togglequickfix#Loop() 2 | nnoremap window:quickfix:toggle :call togglequickfix#ToggleQuickfix() 3 | nnoremap window:location:toggle :call togglequickfix#ToggleLocation() 4 | --------------------------------------------------------------------------------