quickfix.vim 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. " }}}
  35. " Global map removal on qf window close. {{{
  36. autocmd BufWinLeave *
  37. \ if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win |
  38. \ unlet! g:qfix_win |
  39. \ call UnmapQfPrefNext() |
  40. \ endif
  41. " }}}
  42. " Open quickfix window after any grep invocation (Glog and Ggrep). {{{
  43. autocmd QuickFixCmdPost *grep* cwindow |
  44. \ setlocal nocursorline |
  45. \ let g:qfix_win = bufnr("$") |
  46. \ call MapQfPrevNext()
  47. " }}}
  48. " <TAB> and <BSLASH> map adding helper. {{{
  49. function! MapQfPrevNext()
  50. exec "nmap <silent> <tab> :cprev<CR>"
  51. exec "nmap <silent> <bslash> :cnext<CR>"
  52. endfunction
  53. " }}}
  54. " <TAB> and <BSLASH> map removal helper. {{{
  55. function! UnmapQfPrefNext()
  56. exec "nunmap <tab>"
  57. exec "nunmap <bslash>"
  58. endfunction
  59. " }}}
  60. endif