Skip to content

Commit

Permalink
Changed wording and added an autocmd for '$ vim -q filename'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainl committed Oct 1, 2016
1 parent 721a0a8 commit de278c9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Features

### Global features
### Global features (available from any window)

- quickfix buffers are hidden from `:ls` and buffer navigation
- optional mappings for `:cnext`, `:cprevious`, `:lnext`, `:lprevious` that wrap around the beginning and end of the list
Expand All @@ -14,10 +14,10 @@
- quit Vim if the last window is a location/quickfix window
- close the location window automatically when quitting parent window

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

- disable soft-wrapping in the location/quickfix window
- disable relative numbers in the location/quickfix window
- disable soft-wrapping
- disable relative numbers
- optional Ack.vim-inspired mappings
- filter and restore the current list
- perform commands on each line in the current list
Expand Down Expand Up @@ -56,6 +56,7 @@ on Windows.

* Export more options?
* Add a gifcast to the README?
* Add titles to saved lists, e.g. to display in :ListLists?

## DONE

Expand Down
36 changes: 32 additions & 4 deletions autoload/qf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ endfunction

function qf#JumpToFirstItemOfFileChunk() abort
let l:chunk_file_path = qf#GetFilePath(getline('.'))

while line('.') - 1 != 0 && l:chunk_file_path == qf#GetFilePath(getline(line('.') - 1))
normal! k
endwhile
Expand All @@ -120,9 +121,11 @@ function qf#JumpFileChunk(down) abort
let l:start_file_path = qf#GetFilePath(getline('.'))
let l:direction = a:down ? 'j' : 'k'
let l:end = a:down ? '$' : 1

while l:start_file_path == qf#GetFilePath(getline('.')) && getline('.') != getline(l:end)
execute 'normal! ' . l:direction
endwhile

call qf#JumpToFirstItemOfFileChunk()
endfunction

Expand Down Expand Up @@ -155,6 +158,7 @@ function qf#WrapCommand(direction, prefix)
catch /^Vim\%((\a\+)\)\=:E\%(776\|42\):/
endtry
endif

if &foldopen =~ 'quickfix' && foldclosed(line('.')) != -1
normal zv
endif
Expand All @@ -170,12 +174,14 @@ function qf#DoList(line, cmd)
else
let prefix = "c"
endif

if v:version >= 705 || v:version == 704 && has("patch858")
if a:line == 1
let modifier = ""
else
let modifier = "f"
endif

try
execute prefix . modifier . "do " . a:cmd
catch /^Vim\%((\a\+)\)\=:E\%(553\|42\):/
Expand All @@ -185,6 +191,7 @@ function qf#DoList(line, cmd)
silent execute prefix . "first"
while 1
execute a:cmd

silent execute a:line == 1 ? prefix . "next" : prefix . "nfile"
endwhile
catch /^Vim\%((\a\+)\)\=:E\%(553\|42\):/
Expand All @@ -210,8 +217,10 @@ function qf#RestoreList()
if exists("b:isLoc")
if b:isLoc == 1
let lists = getwinvar(winnr("#"), "qf_location_lists")

if len(lists) > 0
call setloclist(0, getwinvar(winnr("#"), "qf_location_lists")[0], "r")

let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0]
else
echo "No filter applied. Nothing to restore."
Expand All @@ -220,13 +229,15 @@ function qf#RestoreList()
if exists("g:qf_quickfix_lists")
if len(g:qf_quickfix_lists) > 0
call setqflist(g:qf_quickfix_lists[0], "r")

let w:quickfix_title = g:qf_quickfix_titles[0]
else
echo "No filter applied. Nothing to restore."
endif
endif
endif
endif

call qf#ResetLists()
endfunction

Expand All @@ -248,6 +259,7 @@ function qf#SetStatusline()
if exists("b:isLoc")
if b:isLoc == 1
let titles = getwinvar(winnr("#"), "qf_location_titles")

if len(titles) > 0
return titles[-1]
else
Expand Down Expand Up @@ -280,8 +292,9 @@ function qf#SetStatusline()
endfunction

function qf#SetList(pat, reject)
let operator = a:reject == 0 ? "=~" : "!~"
let operator = a:reject == 0 ? "=~" : "!~"
let condition = a:reject == 0 ? "||" : "&&"

if exists("b:isLoc")
if b:isLoc == 1
call setloclist(0, filter(getloclist(0), "bufname(v:val['bufnr']) " . operator . " a:pat " . condition . " v:val['text'] " . operator . " a:pat"), "r")
Expand All @@ -295,6 +308,7 @@ function qf#AddList()
if exists("b:isLoc")
if b:isLoc == 1
let locations = getwinvar(winnr("#"), "qf_location_lists")

if len(locations) > 0
call add(locations, getloclist(0))
call setwinvar(winnr("#"), "qf_location_lists", locations)
Expand All @@ -311,9 +325,17 @@ function qf#AddList()
endif
endfunction

" sets the proper title for the current window
" sets the proper title for the current window after :Keep and :Reject
" - location window:
" :lgrep foo sample.txt [keep: 'bar']
" :lgrep foo sample.txt [reject: 'bar']
" - quickfix window:
" :grep foo sample.txt [keep: 'bar']
" :grep foo sample.txt [reject: 'bar']
function qf#SetTitle(pat, reject)
let str = a:reject == 0 ? "filter" : "reject"
" did we use :Keep or :Reject?
let str = a:reject == 0 ? "keep" : "reject"

if exists("b:isLoc")
if b:isLoc == 1
let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0] . " [" . str . ": '" . a:pat . "']"
Expand All @@ -331,10 +353,12 @@ function qf#SetTitle(pat, reject)
endif
endfunction

" store the current title
function qf#AddTitle(title)
if exists("b:isLoc")
if b:isLoc == 1
let titles = getwinvar(winnr("#"), "qf_location_titles")

if len(titles) > 0
call add(titles, a:title)
call setwinvar(winnr("#"), "qf_location_titles", titles)
Expand All @@ -351,10 +375,12 @@ function qf#AddTitle(title)
endif
endfunction

" replace the current title
function qf#ReuseTitle()
if exists("b:isLoc")
if b:isLoc == 1
let titles = getwinvar(winnr("#"), "qf_location_titles")

if len(titles) > 0
let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0]"
endif
Expand All @@ -373,13 +399,15 @@ let s:last_saved_list = ''

function qf#SaveList(add, name) abort
if a:name != ''
let curname = a:name
let curname = a:name
let s:last_saved_list = curname
else
if s:last_saved_list == ''
echomsg 'No last saved list'

return
endif

let curname = s:last_saved_list
endif

Expand Down
44 changes: 24 additions & 20 deletions doc/qf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ vim-qf--short for "vim-quickfix"--is a small collection of settings,
commands and mappings put together to make working with the location/quickfix
list/window smoother.

Here are the features provided globally by this plugin:
These "global" features are available from any window:

- quickfix buffers are hidden from |:ls| and buffer navigation
- optional mappings for |:cnext|, |:cprevious|, |:lnext|, |:lprevious|
Expand All @@ -34,10 +34,10 @@ Here are the features provided globally by this plugin:
- quit Vim if the last window is a location/quickfix window
- close the location window automatically when quitting parent window

And the local features:
These "local" features are only available in location/quickfix windows:

- disable soft-wrapping in the location/quickfix window
- disable relative numbers in the location/quickfix window
- disable soft-wrapping
- disable relative numbers
- optional Ack.vim-inspired mappings
- filter and restore the current list
- perform commands on each line in the current list
Expand Down Expand Up @@ -79,7 +79,7 @@ on Windows... >
==============================================================================
3. CONFIGURATION *qf-configuration*

Available global mappings:
Global mappings:

<Plug>QfCprevious ............................. |QfCprevious|
<Plug>QfCnext ................................. |QfCnext|
Expand All @@ -89,12 +89,12 @@ Available global mappings:
<Plug>QfCtoggle ............................... |QfCtoggle|
<Plug>QfLtoggle ............................... |QfLtoggle|

Available local mappings:
Local mappings:

{ ............................................. |QfPreviousFile|
} ............................................. |QfNextFile|

Available options:
Options:

qf_mapping_ack_style .......................... |qf_mapping_ack_style|
qf_statusline ................................. |qf_statusline|
Expand All @@ -118,7 +118,7 @@ Example: >
Scope: global ~
Default: none ~

Go up and down the location list and wrap around.
Go up and down the current location list and wrap around.

Example: >
Expand Down Expand Up @@ -172,7 +172,7 @@ Jump to the next group of lines corresponding to a file.
Value: numeric ~
Default: 0 ~

Ack.vim-inspired mappings available only in the quickfix window:
Ack.vim-inspired mappings available only in location/quickfix windows:

s - open entry in a new horizontal window
v - open entry in a new vertical window
Expand All @@ -189,7 +189,7 @@ Add the line below to your vimrc to enable this feature: >
Value: numeric ~
Default: 1 ~

Open quickfix window at the bottom.
Open the quickfix window at the bottom of the screen.

Add the line below to your vimrc to disable this feature: >
Expand All @@ -200,7 +200,7 @@ Add the line below to your vimrc to disable this feature: >
Value: numeric ~
Default: 1 ~

Open location list windows at the bottom.
Open location list windows at the bottom of the screen.

Add the line below to your vimrc to disable this feature: >
Expand Down Expand Up @@ -228,7 +228,7 @@ is focused:

*:Keep*

Removes all entries that don't contain the given argument, either in the
Remove all entries that don't contain the given argument, either in the
filename or in the description. Note: the argument is not a regular
expression pattern.

Expand All @@ -238,7 +238,7 @@ is focused:
>
*:Reject*

Removes all entries that contain the given argument in the filename or
Remove all entries that contain the given argument in the filename or
in the description. Note: the argument is not a regular expression
pattern.

Expand All @@ -248,11 +248,11 @@ is focused:
>
*:Restore*

Restores the list to its original state.
Restore the list to its original state.

*:Doline*

Executes an Ex command on every line in the current list.
Execute an Ex command on every line in the current list.
Aliased to the built-in `:cdo` and `:ldo` when applicable.

Example: >
Expand All @@ -261,7 +261,7 @@ is focused:
<
*:Dofile*

Executes an Ex command on every file in the current list.
Execute an Ex command on every file in the current list.
Aliased to the built-in `:cfdo` and `:lfdo` when applicable.

Example: >
Expand All @@ -270,7 +270,7 @@ is focused:
<
*:SaveList*

Saves the current quickfix/location list and associates it
Save the current quickfix/location list and associates it
with a given name. If no name is supplied the last saved
list is used.

Expand All @@ -288,7 +288,7 @@ is focused:
<
*:LoadList*

Replaces the current quickfix/location list with one or more saved named
Replace the current quickfix/location list with one or more saved named
lists. If no name is supplied, the last saved list is used.

Example: >
Expand All @@ -305,7 +305,7 @@ is focused:
<
*:ListLists*

Lists all currently saved lists.
List all currently saved lists.

Example: >
Expand All @@ -315,7 +315,7 @@ is focused:
<
*:RemoveList*

Removes given lists. With a bang all saved lists are removed.
Remove given lists. With a bang all saved lists are removed.

NOTE: In most cases it is possible to only type a few characters to
disembiguate commands. Assuming you don't already have custom commands with
Expand Down Expand Up @@ -399,6 +399,10 @@ a proper plugin come from Barry Arthur's Area 41 plugin:

- https://github.com/dahu/Area-41

The named lists feature is the brainchild of Nelo-T. Wallus:

- https://ntnn.de/

==============================================================================
7. TODO *qf-todo*

Expand Down
1 change: 1 addition & 0 deletions plugin/qf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ augroup qf
" :lvimgrep and friends if there are valid locations/errors
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
autocmd VimEnter * cwindow

" automatically close corresponding loclist when quitting a window
autocmd QuitPre * if &filetype != 'qf' | silent! lclose | endif
Expand Down

0 comments on commit de278c9

Please sign in to comment.