Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active November 7, 2021 20:57
Show Gist options
  • Select an option

  • Save romainl/3c7ee68125f822ec550c to your computer and use it in GitHub Desktop.

Select an option

Save romainl/3c7ee68125f822ec550c to your computer and use it in GitHub Desktop.

Revisions

  1. romainl revised this gist Apr 12, 2020. 2 changed files with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion deprecation.md → list.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    # This gist is no longer maintained.

    See https://github.com/romainl/vim-qlist for an up-to-date version.
    See https://github.com/romainl/vim-qlist for an up-to-date version.

    ---

    [My Vim-related gists](https://gist.github.com/romainl/4b9f139d2a8694612b924322de1025ce).
    File renamed without changes.
  2. romainl revised this gist Mar 26, 2020. 2 changed files with 3 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions List.vim
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,3 @@
    " ATTENTION!
    " ATTENTION!
    " This gist is no longer maintained. See https://github.com/romainl/vim-qlist
    " ATTENTION!
    " ATTENTION!

    " This is an updated, more powerful, version of the function discussed here:
    " http://www.reddit.com/r/vim/comments/1rzvsm/do_any_of_you_redirect_results_of_i_to_the/

    3 changes: 3 additions & 0 deletions deprecation.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # This gist is no longer maintained.

    See https://github.com/romainl/vim-qlist for an up-to-date version.
  3. romainl revised this gist May 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion List.vim
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    " ATTENTION!
    " ATTENTION!
    " This gist is no longer maintained. See https://github.com/romainl/vim-ilist
    " This gist is no longer maintained. See https://github.com/romainl/vim-qlist
    " ATTENTION!
    " ATTENTION!

  4. romainl revised this gist Apr 25, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions List.vim
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    " ATTENTION!
    " ATTENTION!
    " This gist is no longer maintained. See https://github.com/romainl/vim-ilist
    " ATTENTION!
    " ATTENTION!

    " This is an updated, more powerful, version of the function discussed here:
    " http://www.reddit.com/r/vim/comments/1rzvsm/do_any_of_you_redirect_results_of_i_to_the/

  5. romainl revised this gist Apr 11, 2015. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions List.vim
    Original file line number Diff line number Diff line change
    @@ -60,17 +60,20 @@ function! List(command, selection, start_at_cursor, ...)
    cwindow
    endfunction

    " Override the built-in commands.
    " Override the built-in [I and ]I.
    nnoremap <silent> [I :call List("i", 0, 0)<CR>
    nnoremap <silent> ]I :call List("i", 0, 1)<CR>
    " Add [I and ]I for visual mode.
    xnoremap <silent> [I :<C-u>call List("i", 1, 0)<CR>
    xnoremap <silent> ]I :<C-u>call List("i", 1, 1)<CR>
    " Add the :Ilist command.
    command! -nargs=1 Ilist call List("i", 1, 0, <f-args>)

    " Override the built-in [D and ]D.
    nnoremap <silent> [D :call List("d", 0, 0)<CR>
    nnoremap <silent> ]D :call List("d", 0, 1)<CR>
    " Add [D and ]D for visual mode.
    xnoremap <silent> [D :<C-u>call List("d", 1, 0)<CR>
    xnoremap <silent> ]D :<C-u>call List("d", 1, 1)<CR>
    " Add the :Dlist command.
    command! -nargs=1 Dlist call List("d", 1, 0, <f-args>)
  6. romainl revised this gist Apr 11, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion List.vim
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ function! List(command, selection, start_at_cursor, ...)
    let qf_entries = []
    for line in lines
    if line !~ '^\s*\d\+:'
    let filename = line
    let filename = split(line, '\.\./')[-1]
    else
    let lnum = split(line)[1]
    let text = substitute(line, '^\s*.\{-}:\s*\S\{-}\s\s', "", "")
  7. romainl revised this gist Apr 11, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions List.vim
    Original file line number Diff line number Diff line change
    @@ -47,8 +47,8 @@ function! List(command, selection, start_at_cursor, ...)
    let filename = line
    else
    let lnum = split(line)[1]
    let text = join(split(line)[2:-1])
    let col = match(text, a:selection ? search_pattern : expand("<cword>")) + 1
    let text = substitute(line, '^\s*.\{-}:\s*\S\{-}\s\s', "", "")
    let col = match(text, a:selection ? search_pattern : expand("<cword>")) + 2
    call add(qf_entries, {"filename" : filename, "lnum" : lnum, "col" : col, "text" : text})
    endif
    endfor
  8. romainl revised this gist Apr 11, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion List.vim
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,10 @@ function! List(command, selection, start_at_cursor, ...)
    if line !~ '^\s*\d\+:'
    let filename = line
    else
    call add(qf_entries, {"filename" : filename, "lnum" : split(line)[1], "text" : join(split(line)[2:-1])})
    let lnum = split(line)[1]
    let text = join(split(line)[2:-1])
    let col = match(text, a:selection ? search_pattern : expand("<cword>")) + 1
    call add(qf_entries, {"filename" : filename, "lnum" : lnum, "col" : col, "text" : text})
    endif
    endfor

  9. romainl revised this gist Mar 29, 2015. 1 changed file with 11 additions and 9 deletions.
    20 changes: 11 additions & 9 deletions List.vim
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,16 @@
    " This is an updated, more powerful, version of the function discussed here:
    " http://www.reddit.com/r/vim/comments/1rzvsm/do_any_of_you_redirect_results_of_i_to_the/

    " This function shows ']I', '[I', ']D', '[D', ':ilist' and ':dlist' results — even spanning multiple files — in the quickfix window.
    " The purpose of this function is to make the results of ']I', '[I', ']D', '[D', ':ilist' and ':dlist'
    " easier to navigate and more persistant by using the quickfix window instead of the default list-like interface.

    function! List(command, selection, start_at_cursor, ...)
    " derive the commands used below from the first argument
    " Derive the commands used below from the first argument.
    let excmd = a:command . "list"
    let normcmd = toupper(a:command)

    " if we are operating on a visual selection, redirect the output of '[I', ']I', '[D' or ']D'
    " if we don't, redirect the output of ':ilist argument' or ':dlist argument'
    " If we are operating on a visual selection, redirect the output of '[I', ']I', '[D' or ']D'.
    " If we don't, redirect the output of ':ilist argument' or ':dlist argument'.
    let output = ""
    if a:selection
    if a:0 > 0 && len(a:1) > 0
    @@ -29,16 +30,16 @@ function! List(command, selection, start_at_cursor, ...)
    redir END
    endif

    " clean up the output
    " Clean up the output.
    let lines = split(output, '\n')

    " bail out on errors
    " Bail out on errors.
    if lines[0] =~ '^Error detected'
    echomsg 'Could not find "' . (a:selection ? search_pattern : expand("<cword>")) . '".'
    return
    endif

    " our results may span multiple files so we need to build a relatively complex list based on filenames
    " Our results may span multiple files so we need to build a relatively complex list based on filenames.
    let filename = ""
    let qf_entries = []
    for line in lines
    @@ -49,13 +50,14 @@ function! List(command, selection, start_at_cursor, ...)
    endif
    endfor

    " build the quickfix list from our results
    " Build the quickfix list from our results.
    call setqflist(qf_entries)

    " open the quickfix window if there is something to show
    " Open the quickfix window if there is something to show.
    cwindow
    endfunction

    " Override the built-in commands.
    nnoremap <silent> [I :call List("i", 0, 0)<CR>
    nnoremap <silent> ]I :call List("i", 0, 1)<CR>
    xnoremap <silent> [I :<C-u>call List("i", 1, 0)<CR>
  10. romainl revised this gist Mar 29, 2015. No changes.
  11. romainl revised this gist Mar 29, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion List.vim
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,10 @@ function! List(command, selection, start_at_cursor, ...)
    " derive the commands used below from the first argument
    let excmd = a:command . "list"
    let normcmd = toupper(a:command)
    let output = ""

    " if we are operating on a visual selection, redirect the output of '[I', ']I', '[D' or ']D'
    " if we don't, redirect the output of ':ilist argument' or ':dlist argument'
    let output = ""
    if a:selection
    if a:0 > 0 && len(a:1) > 0
    let search_pattern = a:1
  12. romainl revised this gist Mar 29, 2015. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion List.vim
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,16 @@
    " This is an updated, more powerful, version of the function discussed here:
    " http://www.reddit.com/r/vim/comments/1rzvsm/do_any_of_you_redirect_results_of_i_to_the/
    " that shows ]I, [I, ]D, [D, :ilist and :dlist results in the quickfix window, even spanning multiple files.

    " This function shows ']I', '[I', ']D', '[D', ':ilist' and ':dlist' results — even spanning multiple files — in the quickfix window.

    function! List(command, selection, start_at_cursor, ...)
    " derive the commands used below from the first argument
    let excmd = a:command . "list"
    let normcmd = toupper(a:command)
    let output = ""

    " if we are operating on a visual selection, redirect the output of '[I', ']I', '[D' or ']D'
    " if we don't, redirect the output of ':ilist argument' or ':dlist argument'
    if a:selection
    if a:0 > 0 && len(a:1) > 0
    let search_pattern = a:1
    @@ -24,11 +28,17 @@ function! List(command, selection, start_at_cursor, ...)
    silent! execute 'normal! ' . (a:start_at_cursor ? ']' : '[') . normcmd
    redir END
    endif

    " clean up the output
    let lines = split(output, '\n')

    " bail out on errors
    if lines[0] =~ '^Error detected'
    echomsg 'Could not find "' . (a:selection ? search_pattern : expand("<cword>")) . '".'
    return
    endif

    " our results may span multiple files so we need to build a relatively complex list based on filenames
    let filename = ""
    let qf_entries = []
    for line in lines
    @@ -38,7 +48,11 @@ function! List(command, selection, start_at_cursor, ...)
    call add(qf_entries, {"filename" : filename, "lnum" : split(line)[1], "text" : join(split(line)[2:-1])})
    endif
    endfor

    " build the quickfix list from our results
    call setqflist(qf_entries)

    " open the quickfix window if there is something to show
    cwindow
    endfunction

  13. romainl revised this gist Mar 27, 2015. 1 changed file with 3 additions and 14 deletions.
    17 changes: 3 additions & 14 deletions List.vim
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,12 @@
    " that shows ]I, [I, ]D, [D, :ilist and :dlist results in the quickfix window, even spanning multiple files.

    function! List(command, selection, start_at_cursor, ...)
    " derive the commands used below from the first argument
    let excmd = a:command . "list"
    let normcmd = toupper(a:command)
    let output = ""

    if a:selection
    if len(a:1) > 0
    if a:0 > 0 && len(a:1) > 0
    let search_pattern = a:1
    else
    let old_reg = @v
    @@ -24,32 +24,21 @@ function! List(command, selection, start_at_cursor, ...)
    silent! execute 'normal! ' . (a:start_at_cursor ? ']' : '[') . normcmd
    redir END
    endif

    " clean up the output
    let lines = split(output, '\n')

    " bail out on errors
    if lines[0] =~ '^Error detected'
    echomsg 'Could not find "' . (a:selection ? search_pattern : expand("<cword>")) . '".'
    return
    endif

    " our results may span multiple files so we need to build a relatively
    " complex list based on file names
    let filename = ""
    let qf_entries = []
    for line in lines
    if line =~ '^\S'
    if line !~ '^\s*\d\+:'
    let filename = line
    else
    call add(qf_entries, {"filename" : filename, "lnum" : split(line)[1], "text" : join(split(line)[2:-1])})
    endif
    endfor

    " build the quickfix list from our results
    call setqflist(qf_entries)

    " open the quickfix window if there is something to show
    cwindow
    endfunction

  14. romainl renamed this gist Mar 17, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  15. romainl renamed this gist Mar 17, 2015. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions gistfile1.vim → function.vim
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,9 @@
    " This is an updated, more powerful, version of the function discussed here:
    " http://www.reddit.com/r/vim/comments/1rzvsm/do_any_of_you_redirect_results_of_i_to_the/
    " that shows ]I, [I, ]D, [D, :ilist and :dlist results in the quickfix window, even spanning multiple files.

    function! List(command, selection, start_at_cursor, ...)
    " derive the commands used below from the first argument
    let excmd = a:command . "list"
    let normcmd = toupper(a:command)

    @@ -19,11 +24,18 @@ function! List(command, selection, start_at_cursor, ...)
    silent! execute 'normal! ' . (a:start_at_cursor ? ']' : '[') . normcmd
    redir END
    endif

    " clean up the output
    let lines = split(output, '\n')

    " bail out on errors
    if lines[0] =~ '^Error detected'
    echomsg 'Could not find "' . (a:selection ? search_pattern : expand("<cword>")) . '".'
    return
    endif

    " our results may span multiple files so we need to build a relatively
    " complex list based on file names
    let filename = ""
    let qf_entries = []
    for line in lines
    @@ -33,7 +45,11 @@ function! List(command, selection, start_at_cursor, ...)
    call add(qf_entries, {"filename" : filename, "lnum" : split(line)[1], "text" : join(split(line)[2:-1])})
    endif
    endfor

    " build the quickfix list from our results
    call setqflist(qf_entries)

    " open the quickfix window if there is something to show
    cwindow
    endfunction

  16. romainl revised this gist Mar 17, 2015. No changes.
  17. romainl revised this gist Mar 17, 2015. No changes.
  18. romainl revised this gist Mar 17, 2015. No changes.
  19. romainl created this gist Mar 17, 2015.
    52 changes: 52 additions & 0 deletions gistfile1.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    function! List(command, selection, start_at_cursor, ...)
    let excmd = a:command . "list"
    let normcmd = toupper(a:command)

    if a:selection
    if len(a:1) > 0
    let search_pattern = a:1
    else
    let old_reg = @v
    normal! gv"vy
    let search_pattern = substitute(escape(@v, '\/.*$^~[]'), '\\n', '\\n', 'g')
    let @v = old_reg
    endif
    redir => output
    silent! execute (a:start_at_cursor ? '+,$' : '') . excmd . ' /' . search_pattern
    redir END
    else
    redir => output
    silent! execute 'normal! ' . (a:start_at_cursor ? ']' : '[') . normcmd
    redir END
    endif
    let lines = split(output, '\n')
    if lines[0] =~ '^Error detected'
    echomsg 'Could not find "' . (a:selection ? search_pattern : expand("<cword>")) . '".'
    return
    endif
    let filename = ""
    let qf_entries = []
    for line in lines
    if line =~ '^\S'
    let filename = line
    else
    call add(qf_entries, {"filename" : filename, "lnum" : split(line)[1], "text" : join(split(line)[2:-1])})
    endif
    endfor
    call setqflist(qf_entries)
    cwindow
    endfunction

    nnoremap <silent> [I :call List("i", 0, 0)<CR>
    nnoremap <silent> ]I :call List("i", 0, 1)<CR>
    xnoremap <silent> [I :<C-u>call List("i", 1, 0)<CR>
    xnoremap <silent> ]I :<C-u>call List("i", 1, 1)<CR>
    command! -nargs=1 Ilist call List("i", 1, 0, <f-args>)

    nnoremap <silent> [D :call List("d", 0, 0)<CR>
    nnoremap <silent> ]D :call List("d", 0, 1)<CR>
    xnoremap <silent> [D :<C-u>call List("d", 1, 0)<CR>
    xnoremap <silent> ]D :<C-u>call List("d", 1, 1)<CR>
    command! -nargs=1 Dlist call List("d", 1, 0, <f-args>)