Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### Anti-features

Many plugins interact with the quickfix/location list/window in ways that are more or less incompatible with vim-qf. I have put considerable effort in making most vim-qf features optional so it should be possible to disable individual features in case of conflict but well… you never know.
Many plugins interact with the quickfix/location list/window in ways that are more or less incompatible with vim-qf. I have put considerable effort into making most vim-qf features optional so it should be possible to disable individual features in case of conflict but well… you never know.

**If one of your plugins somehow already manages the quickfix/location list/window, then you should probably look elsewhere.**

Expand All @@ -26,7 +26,7 @@ Many plugins interact with the quickfix/location list/window in ways that are mo

- (optional) open the location/quickfix window automatically after `:make`, `:grep`, `:lvimgrep` and friends if there are valid locations/errors

- (optional) automatically set the height of location/quickfix windows to the number of list items if less than Vim's default height (10) or the user's prefered height
- (optional) automatically set the height of location/quickfix windows to the number of list items if less than Vim's default height (10) or the user's preferred height

### Local features (available only in location/quickfix windows)

Expand All @@ -36,10 +36,6 @@ Many plugins interact with the quickfix/location list/window in ways that are mo

![filter][1]

- perform commands on each line in the current list

- perform commands on each file in the current list

- jump to next group of entries belonging to same file ("file grouping"):

![group][2]
Expand Down Expand Up @@ -72,27 +68,9 @@ If you are using Vim 8.0 or above, move this directory to:

See `:help package`.

### Method 3

If you are using Vim 7.4 or below, move the files in this directory to their standard location:

# Unix-like systems
~/.vim/after/ftplugin/qf.vim
~/.vim/autoload/qf.vim
~/.vim/autoload/qf/*.vim
~/.vim/doc/qf.txt
~/.vim/plugin/qf.vim

# Windows
%userprofile%\vimfiles\after\ftplugin\qf.vim
%userprofile%\vimfiles\autoload\qf.vim
%userprofile%\vimfiles\autoload\qf\*.vim
%userprofile%\vimfiles\doc\qf.txt
%userprofile%\vimfiles\plugin\qf.vim

## Documentation

You can use this command to get help on vim-qf:
The full documentation is available through this command:

:help vim-qf

Expand Down
149 changes: 68 additions & 81 deletions after/ftplugin/qf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,20 @@
" 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
" 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
" 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
" We don't want quickfix buffers to pop up when doing :bn or :bp
set nobuflisted

if exists("b:undo_ftplugin")
Expand All @@ -37,54 +26,59 @@ else
let b:undo_ftplugin = "setl wrap< rnu< nu< bl<"
endif

" are we in a location list or a quickfix list?
let b:qf_isLoc = get(get(getwininfo(win_getid()), 0, {}), 'loclist', 0)
" Are we in a location window or a quickfix window?
" 0 -> quickfix window
" 1 -> location window
let b:qf_isLoc = win_getid()
\ ->getwininfo()
\ ->get(0, {})
\ ->get("loclist", 0)

" customize the statusline
" 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")
let qf_at_bottom = (b:qf_isLoc == 1 && get(g:, 'qf_loclist_window_bottom', 1))
\ || (b:qf_isLoc == 0 && get(g:, 'qf_window_bottom', 1))
" Mappings inspired by Ack.vim
if get(g:, "qf_mapping_ack_style", 0)
let qf_at_bottom = (get(b:, "qf_isLoc", 0) && get(g:, "qf_loclist_window_bottom", 1))
\ || (!get(b:, "qf_isLoc", 0) && get(g:, "qf_window_bottom", 1))

" open entry in a new vertical window.
" Open entry in a new vertical window
if qf_at_bottom
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
" 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

if qf_at_bottom && &splitbelow
" open entry in a new horizontal window and move quickfix to bottom
" Open entry in a new horizontal window and move quickfix to bottom
nnoremap <silent> <buffer> s <C-w><CR><C-w>p<C-w>J<C-w>p

" preview entry under the cursor and move quickfix to bottom
" Preview entry under the cursor and move quickfix to bottom
nnoremap <silent> <buffer> p :call qf#preview#PreviewFileUnderCursor()<CR><C-w>J
else
" open entry in a new horizontal window
" Open entry in a new horizontal window
nnoremap <silent> <buffer> s <C-w><CR>

" preview entry under the cursor
" Preview entry under the cursor
nnoremap <silent> <buffer> p :call qf#preview#PreviewFileUnderCursor()<CR>
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
" Open entry and close the location/quickfix window
if get(b:, "qf_isLoc", 0)
nnoremap <silent> <buffer> O <CR>:lclose<CR>
else
nnoremap <silent> <buffer> O <CR>:cclose<CR>
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

let b:undo_ftplugin .= "| execute 'nunmap <buffer> s'"
\ . "| execute 'nunmap <buffer> v'"
\ . "| execute 'nunmap <buffer> t'"
Expand All @@ -93,76 +87,75 @@ if exists("g:qf_mapping_ack_style")
\ . "| 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
" :10,15Filter <-- same as :10,15Keep
" :10,15Filter! <-- same as :10,15Reject
command! -buffer -range -nargs=1 -bang Filter call qf#filter#FilterList(<q-args>, expand("<bang>") == "!" ? 1 : 0, <line1>, <line2>, <count>)

" keep entries matching the argument or range
" usage:
" Keep entries matching the argument or range
" Usage:
" :Keep foo
" :10,15Keep
command! -buffer -range -nargs=? Keep call qf#filter#FilterList(<q-args>, 0, <line1>, <line2>, <count>)

" reject entries matching the argument or range
" usage:
" Reject entries matching the argument or range
" Usage:
" :Reject foo
" :10,15Reject
command! -buffer -range -nargs=? Reject call qf#filter#FilterList(<q-args>, 1, <line1>, <line2>, <count>)

" restore the location/quickfix list
" usage:
" 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
" Save current location/quickfix list and associate it with a given name or the
" last used name
" Usage:
" :SaveList foobar
" :SaveList
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
" Like SaveList, but add to a potentially existing named list
" Usage:
" :SaveListAdd foobar
" :SaveListAdd
command! -buffer -nargs=? -complete=customlist,qf#namedlist#CompleteList SaveListAdd call qf#namedlist#SaveList(1, <q-args>)

" replace location/quickfix list with named lists
" Replace location/quickfix list with named lists
" Usage:
" :LoadList foobar
command! -buffer -nargs=+ -complete=customlist,qf#namedlist#CompleteList LoadList call qf#namedlist#LoadList(0, <q-args>)
" like LoadList but append instead of replace
" Like LoadList but append instead of replace
" Usage:
" :LoadListAdd foobar
command! -buffer -nargs=+ -complete=customlist,qf#namedlist#CompleteList LoadListAdd call qf#namedlist#LoadList(1, <q-args>)

" list currently saved lists
" List currently saved lists
" Usage:
" :ListLists
command! -buffer ListLists call qf#namedlist#ListLists()
" remove given lists or all
" Remove given lists or all
" Usage:
" :RemoveList foobar
" :RemoveList!
command! -buffer -nargs=* -bang -complete=customlist,qf#namedlist#CompleteList RemoveList call qf#namedlist#RemoveList(expand("<bang>") == "!" ? 1 : 0, <q-args>)

" 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
" 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

" Move forward and backward in list history (in a quickfix or location window)
" Move forward and backward in list history (in a location/quickfix window)
nnoremap <silent> <buffer> <Plug>(qf_older) :<C-u>call qf#history#Older()<CR>
nnoremap <silent> <buffer> <Plug>(qf_newer) :<C-u>call qf#history#Newer()<CR>

" Jump to previous and next file grouping (in a quickfix or location window)
" Jump to previous and next file grouping (in a location/quickfix window)
nnoremap <silent> <buffer> <Plug>(qf_previous_file) :<C-u>call qf#filegroup#PreviousFile()<CR>
nnoremap <silent> <buffer> <Plug>(qf_next_file) :<C-u>call qf#filegroup#NextFile()<CR>

let b:undo_ftplugin .= "| delcommand Filter"
\ . "| delcommand Keep"
" Decide where to open the location/quickfix window
if (get(b:, "qf_isLoc", 0) && get(g:, "qf_loclist_window_bottom", 1))
\ || (!get(b:, "qf_isLoc", 0) && get(g:, "qf_window_bottom", 1))
wincmd J
endif

let b:undo_ftplugin .= "| delcommand Keep"
\ . "| delcommand Reject"
\ . "| delcommand Restore"
\ . "| delcommand Doline"
\ . "| delcommand Dofile"
\ . "| delcommand SaveList"
\ . "| delcommand SaveListAdd"
\ . "| delcommand LoadList"
Expand All @@ -175,10 +168,4 @@ let b:undo_ftplugin .= "| delcommand Filter"
\ . "| execute 'nunmap <buffer> <Plug>(qf_next_file)'"
\ . "| 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
Loading