forked from romainl/vim-qf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qf.vim
executable file
·161 lines (133 loc) · 5.95 KB
/
qf.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
" vim-qf - Tame the quickfix window
" Maintainer: romainl <[email protected]>
" Version: 0.2.0
" License: MIT
" Location: after/ftplugin/qf.vim
" Website: https://github.com/romainl/vim-qf
"
" Use this command to get help on vim-qf:
"
" :help qf
"
" If this doesn't work and you installed vim-qf manually, use the following
" command to index vim-qf's documentation:
"
" :helptags ~/.vim/doc
"
" or read your runtimepath/plugin manager documentation.
let s:save_cpo = &cpo
set cpo&vim
" text wrapping is pretty much useless in the quickfix window
" but some users may still want it
execute get(g:, "qf_nowrap", 1) ? "setlocal nowrap" : "setlocal wrap"
" relative line numbers don't make much sense either
" but absolute numbers definitely do
setlocal norelativenumber
setlocal number
" we don't want quickfix buffers to pop up when doing :bn or :bp
set nobuflisted
let b:undo_ftplugin .= "| setl wrap< rnu< nu< bl<"
" are we in a location list or a quickfix list?
let b:qf_isLoc = !empty(getloclist(0)) || getwininfo(win_getid(winnr()))[0]['loclist']
" customize the statusline
if exists("g:qf_statusline")
execute "setlocal statusline=" . g:qf_statusline.before . "%{qf#statusline#SetStatusline()}" . g:qf_statusline.after
endif
" inspired by Ack.vim
if exists("g:qf_mapping_ack_style")
" open entry in a new horizontal window
nnoremap <silent> <buffer> s <C-w><CR>
" open entry in a new vertical window.
if (b:qf_isLoc == 1 && get(g:, 'qf_loclist_window_bottom', 1))
\ || (b:qf_isLoc == 0 && get(g:, 'qf_window_bottom', 1))
nnoremap <silent> <expr> <buffer> v &splitright ? "\<C-w>\<CR>\<C-w>L\<C-w>p\<C-w>J\<C-w>p" : "\<C-w>\<CR>\<C-w>H\<C-w>p\<C-w>J\<C-w>p"
else
" don't move quickfix to bottom if qf_loclist_window_bottom is 0
nnoremap <silent> <expr> <buffer> v &splitright ? "\<C-w>\<CR>\<C-w>L" : "\<C-w>\<CR>\<C-w>H"
endif
" open entry in a new tab.
nnoremap <silent> <buffer> t <C-w><CR><C-w>T
" open entry and come back
nnoremap <silent> <buffer> o <CR><C-w>p
" open entry and close the location/quickfix window.
if b:qf_isLoc == 1
nnoremap <silent> <buffer> O <CR>:lclose<CR>
else
nnoremap <silent> <buffer> O <CR>:cclose<CR>
endif
" preview entry under the cursor
nnoremap <silent> <buffer> p :call qf#preview#PreviewFileUnderCursor()<CR>
let b:undo_ftplugin .= "| execute 'nunmap <buffer> s'"
\ . "| execute 'nunmap <buffer> v'"
\ . "| execute 'nunmap <buffer> t'"
\ . "| execute 'nunmap <buffer> o'"
\ . "| execute 'nunmap <buffer> O'"
\ . "| execute 'nunmap <buffer> p'"
endif
" filter the location/quickfix list
" (kept for backward compatibility, use :Keep and :Reject instead)
" usage:
" :Filter foo <-- same as :Keep foo
" :Filter! foo <-- same as :Reject foo
command! -buffer -range -nargs=1 -bang Filter call qf#filter#FilterList(<q-args>, expand("<bang>") == "!" ? 1 : 0)
" keep entries matching the argument
" usage:
" :Keep foo
command! -buffer -range -nargs=? Keep call qf#filter#FilterList(<q-args>, 0)
" reject entries matching the argument
" usage:
" :Reject foo
command! -buffer -range -nargs=? Reject call qf#filter#FilterList(<q-args>, 1)
" restore the location/quickfix list
" usage:
" :Restore
command! -buffer -bar Restore call qf#filter#RestoreList()
" do something on each line in the location/quickfix list
" usage:
" :Doline s/^/---
command! -buffer -nargs=1 Doline call qf#do#DoList(1, <q-args>)
" do something on each file in the location/quickfix list
" usage:
" :Dofile %s/^/---
command! -buffer -nargs=1 Dofile call qf#do#DoList(0, <q-args>)
" save current location/quickfix list and associate it with a given name or the
" last used name
command! -buffer -nargs=? -complete=customlist,qf#namedlist#CompleteList SaveList call qf#namedlist#SaveList(0, <q-args>)
" like SaveList, but add to a potentially existing named list
command! -buffer -nargs=? -complete=customlist,qf#namedlist#CompleteList SaveListAdd call qf#namedlist#SaveList(1, <q-args>)
" replace location/quickfix list with named lists
command! -buffer -nargs=+ -complete=customlist,qf#namedlist#CompleteList LoadList call qf#namedlist#LoadList(0, <q-args>)
" like LoadList but append instead of replace
command! -buffer -nargs=+ -complete=customlist,qf#namedlist#CompleteList LoadListAdd call qf#namedlist#LoadList(1, <q-args>)
" list currently saved lists
command! -buffer ListLists call qf#namedlist#ListLists()
" remove given lists or all
command! -buffer -nargs=* -bang -complete=customlist,qf#namedlist#CompleteList RemoveList call qf#namedlist#RemoveList(expand("<bang>") == "!" ? 1 : 0, <q-args>)
" TODO: allow customization
" jump to previous/next file grouping
nnoremap <silent> <buffer> } :call qf#filegroup#NextFile()<CR>
nnoremap <silent> <buffer> { :call qf#filegroup#PreviousFile()<CR>
" quit Vim if the last window is a quickfix window
autocmd qf BufEnter <buffer> nested if get(g:, 'qf_auto_quit', 1) | if winnr('$') < 2 | q | endif | endif
autocmd qf BufWinEnter <buffer> nested if get(g:, 'qf_auto_quit', 1) | call qf#filter#ReuseTitle() | endif
let b:undo_ftplugin .= "| delcommand Filter"
\ . "| delcommand Keep"
\ . "| delcommand Reject"
\ . "| delcommand Restore"
\ . "| delcommand Doline"
\ . "| delcommand Dofile"
\ . "| delcommand SaveList"
\ . "| delcommand SaveListAdd"
\ . "| delcommand LoadList"
\ . "| delcommand LoadListAdd"
\ . "| delcommand ListLists"
\ . "| delcommand RemoveList"
\ . "| execute 'nunmap <buffer> }'"
\ . "| execute 'nunmap <buffer> {'"
\ . "| unlet! b:qf_isLoc"
" decide where to open the location/quickfix window
if (b:qf_isLoc == 1 && get(g:, 'qf_loclist_window_bottom', 1))
\ || (b:qf_isLoc == 0 && get(g:, 'qf_window_bottom', 1))
wincmd J
endif
let &cpo = s:save_cpo