quickfix.vim 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. " Quickfix - Modeline and Notes {{{
  2. " vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
  3. "
  4. " cinaeco/dotfiles Quickfix Maps and Behaviors
  5. "
  6. " Some personal conventions:
  7. " - 'q' to close quickfix and location list windows.
  8. " - 'o' to open quickfix and location list entries.
  9. " (not all plugins have these maps)
  10. " - <TAB> and <BSLASH> for previous and next entries, so long as quickfix
  11. " is open.
  12. " (maps are cleared when quickfix is closed)
  13. " - quickfix should open after any grep invocation e.g. :Glog
  14. " (particularly for fugitive - tpope refuses this as default behaviour)
  15. "
  16. " TODO:
  17. " Perhaps this could be some less arbitrary rule?
  18. "
  19. " }}}
  20. if has("autocmd")
  21. " Quickfix Buffer remaps, 'q' and 'o'. {{{
  22. " - `q` to close qf buffer.
  23. " - `o` to open location entry under cursor.
  24. autocmd FileType qf nnoremap <silent> <buffer> q :ccl<CR>:lcl<CR>
  25. autocmd FileType qf nnoremap <silent> <buffer> o <CR>
  26. " }}}
  27. " Global maps on qf window open, '<TAB>' and '<BSLASH>'. {{{
  28. " - `<TAB>` and `<BSLASH>` for going to previous and next entry
  29. " - unmaps when qf buffer is closed.
  30. autocmd BufWinEnter quickfix
  31. \ setlocal nocursorline |
  32. \ let g:qfix_win = bufnr("$") |
  33. \ call MapQfPrevNext()
  34. \ endif
  35. " }}}
  36. " Global map removal on qf window close. {{{
  37. autocmd BufWinLeave *
  38. \ if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win |
  39. \ unlet! g:qfix_win |
  40. \ call UnmapQfPrefNext() |
  41. \ endif
  42. " }}}
  43. " Open quickfix window after any grep invocation (Glog and Ggrep). {{{
  44. autocmd QuickFixCmdPost *grep* cwindow |
  45. \ setlocal nocursorline |
  46. \ let g:qfix_win = bufnr("$") |
  47. \ call MapQfPrevNext()
  48. " }}}
  49. " <TAB> and <BSLASH> map adding helper. {{{
  50. function! MapQfPrevNext()
  51. exec "nmap <silent> <tab> :cprev<CR>"
  52. exec "nmap <silent> <bslash> :cnext<CR>"
  53. endfunction
  54. " }}}
  55. " <TAB> and <BSLASH> map removal helper. {{{
  56. function! UnmapQfPrefNext()
  57. exec "nunmap <tab>"
  58. exec "nunmap <bslash>"
  59. endfunction
  60. " }}}
  61. endif