I am currently using the following mapping to search for knows tags:

nnoremap <expr> <Leader>t "<ESC>:tselect /" . input("") . "<ESC>"

I also use this mapping to grep all files below the closest tags file:

noremap <expr> <Leader>g "<ESC>:vimgrep /" 
\ . escape(input('/'), '/') 
\ . "/ " 
\ . fnamemodify(findfile('tags', ';'), ':p:h') 
\ . "/**<CR>:cope<CR>"
  1. Is there an easy way to get :tselect results to show up in the quickfix menu, so that I can browse and preview the buffers that contain the matches?
  2. For :vimgrep, how can I show just the menu, rather than automatically opening matches?
  3. Is there a way to open the selected result from the menu in a new split, or replace the current buffer based on user input?

NOTE: I am trying to learn more about Vim, so I prefer to not just install plugins.

  • Not related to your question, but why not just nnoremap <leader>t :tselect ? You can tab-complete :tselect that way.
    – D. Ben Knoble
    Nov 3, 2019 at 3:51
  • @D.BenKnoble I honestly didn't know it worked like that. Thanks for the tip.
    – ThoseKind
    Nov 3, 2019 at 17:24

2 Answers 2


You can use the ":ltag" command which adds the matching tags to the location list for the current window. You can then use the location list commands to browse the matches.

BTW, the location list feature was originally developed in 2005 to add support for this command.

  • 1
    nnoremap <expr> <Leader>t "<ESC>:ltag /" . input("") . "<CR>:lop<CR>" Using the mapping above this is almost exactly what I want. Is there a way to keep focus on the currently opened file and not open the first match?
    – ThoseKind
    Nov 3, 2019 at 17:22
  • This is definitely jank, but assuming moving up and down between splits is done with <C-k> and <C-j> respectively, I can do: nmap <expr> <Leader>t "<ESC>:lt /" . input("") . "<CR>:lop<CR><C-k><C-o><C-j>". This works, but do you have any better ideas?
    – ThoseKind
    Nov 3, 2019 at 17:41
  • The location list feature is super annoying. It duplicates various facets and commands of quicklist. Quicklist has :cope to open the window, the list thing has :lope and so on. One problem is that if you have custom keybindings for going back and forth through a quicklist, they don't work in a location list. User interface clusterf____.
    – Kaz
    Feb 19, 2021 at 1:47
  • Location list link for the lazy - :lopen & :lclose May 28, 2021 at 18:12
  1. Check out :help taglist()—it returns a dictionary of tag-related items. Unfortunately, the quickfix list works with exact locations (file, line, and column). Tags provide an Ex command to get to the tag, often a special search pattern. (Example from some vimscript: <C-y> ../links/vim/plugin/pbcopy_op.vim /^vnoremap <silent> <C-y> :<C-u>call pbcopy#operator(visualmode(), 1)<CR>$/;" —we get a tag name, file, and search command, rather than line numbers and such.) So it may be difficult to get these matches into the quickfix list. But the function does give you enough information to build your own "tag list" buffer from which you could navigate.
  2. Use the /j flag: vimgrep /pattern/j | copen
  3. From :help quickfix-window:
                    *CTRL-W_<Enter>* *CTRL-W_<CR>*
You can use CTRL-W <Enter> to open a new window and jump to the error there.
  • This is all super useful, thanks. Building from this via some Googling, things can be "previewed" in a new vertical split with the following: autocmd! FileType qf nnoremap <buffer> <leader><Enter> <C-w><Enter><C-w>L
    – ThoseKind
    Nov 3, 2019 at 17:36
  • You can also :ptag for tags and :pedit generally
    – D. Ben Knoble
    Nov 3, 2019 at 17:43
  • The only problem I've found with those is that they don't populate the location list. The stuff I'm trying to do is a bit jank, but it seems that :lt and then the ghetto "preview" fits my fancy a bit better. Either way, thanks for all the input!
    – ThoseKind
    Nov 3, 2019 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.