From f6121fb1a918f182ef69656165c145e535ee2fa8 Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Tue, 31 Dec 2019 13:57:47 +0100 Subject: [PATCH] Support count for (qf_qf_previous) and friends A count was ignored for (qf_qf_previous), (qf_qf_next), (qf_loc_previous), and (qf_loc_next). This is a rather simple implementation, and thus may not yet behave entirely as expected. The count is only passed on to `:[cl]previous` and `:[cl]next`, but it is ignored when we wrap using `:[cl]first` and `:[cl]last`. So `100(qf_qf_previous)` while at the top of the list will only jump to the end, not to the 100-to-last item in the list. Also, `:[cl]previous` and `:[cl]next` do not throw when the count is greater than the number of items moved, e.g. `:3previous` while on the 2nd entry in the list will move to the 1st entry, so it doesn't wrap in that case. I think both of these limitations are acceptable, but I'll gladly implement something a bit more complex to handle these cases. Wanted to check with you first, though, before doing unnecessary work. --- autoload/qf/wrap.vim | 6 +++--- plugin/qf.vim | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/autoload/qf/wrap.vim b/autoload/qf/wrap.vim index b543780..b582130 100644 --- a/autoload/qf/wrap.vim +++ b/autoload/qf/wrap.vim @@ -24,17 +24,17 @@ set cpo&vim " TODO (romainl): Built-in :cn/:cp/:ln/:lp stop at the beginning " and end of the list. This allows us to wrap " around. -function! qf#wrap#WrapCommand(direction, prefix) +function! qf#wrap#WrapCommand(direction, prefix, count) if a:direction == "up" try - execute a:prefix . "previous" + execute a:count . a:prefix . "previous" catch /^Vim\%((\a\+)\)\=:E553/ execute a:prefix . "last" catch /^Vim\%((\a\+)\)\=:E\%(325\|776\|42\):/ endtry else try - execute a:prefix . "next" + execute a:count . a:prefix . "next" catch /^Vim\%((\a\+)\)\=:E553/ execute a:prefix . "first" catch /^Vim\%((\a\+)\)\=:E\%(325\|776\|42\):/ diff --git a/plugin/qf.vim b/plugin/qf.vim index b4277cc..881b02c 100644 --- a/plugin/qf.vim +++ b/plugin/qf.vim @@ -34,12 +34,12 @@ nmap QfLtoggle (qf_loc_toggle) nmap QfSwitch &filetype ==# 'qf' ? 'p' : 'b' " Go up and down quickfix list -nnoremap (qf_qf_previous) : call qf#wrap#WrapCommand('up', 'c') -nnoremap (qf_qf_next) : call qf#wrap#WrapCommand('down', 'c') +nnoremap (qf_qf_previous) : call qf#wrap#WrapCommand('up', 'c', v:count1) +nnoremap (qf_qf_next) : call qf#wrap#WrapCommand('down', 'c', v:count1) " Go up and down location list -nnoremap (qf_loc_previous) : call qf#wrap#WrapCommand('up', 'l') -nnoremap (qf_loc_next) : call qf#wrap#WrapCommand('down', 'l') +nnoremap (qf_loc_previous) : call qf#wrap#WrapCommand('up', 'l', v:count1) +nnoremap (qf_loc_next) : call qf#wrap#WrapCommand('down', 'l', v:count1) " Toggle quickfix list nnoremap (qf_qf_toggle) : call qf#toggle#ToggleQfWindow(0)