3

Is there a way to open just the quickfix list without jumping to the first result when using :lt? I am using :lt to populate the location list with tags that match with the following binding:

nmap <expr> <Leader>t ":lt /" . input("", "", "tags") . "<CR>:lop<CR><C-k><C-o><C-j>"

which works to some degree. Given that <C-k> and <C-j> are mappings for the associated window movement commands, this breaks down if the quickfix window is below some complex set of splits. :h tag-matchlist and :h quickfix don't seem to offer any helpful information. However, some options like :cgete seem like the functionality is there, as they specify "but don't jump to the first error", which isn't an option for :lt as it specifies"Jump to tag" as part of its behavior.

So, the new question is: how can I populate the location list with tags matching a pattern without jumping to the first match?

I am currently working on trying to get it to work with :taglist() and :lgete.

2
  • 3
    While commands like :make do jump to the first result (unless suppressed with !), I don't see that behavior for :copen, nor is it documented. Please check that you don't have some customization (:autocmd) that provides this behavior. Nov 6, 2019 at 7:41
  • I don't have any au setup that would do this. Even with a completely empty .vimrc, doing :lt /<match> will always jump to the first result. I worded this incorrectly in that this is a behavior of :lt, not :cope/:lop.
    – ThoseKind
    Nov 6, 2019 at 15:21

1 Answer 1

3

The jump is caused by the :ltag command, not by :lopen. Unfortunately, though that command takes an optional [!], it's meaning is different than that to :make and friends, which can suppress the jump with !.

As :ltag is just a variant of :tag, the ! there is concerned with abandoning the current file, as :help tag-! explains.

I guess the right way to solve this issue is through skipping :ltag and using low-level functions like taglist() to obtain the tags and setloclist() to populate the location list.

3
  • Doing nmap <expr> <Leader>z ":call setloclist(0, taglist(\"" . input("", "", "tag") . "\"))<CR>:lop<CR>" works, so thanks for the tips on this. However, the location list only shows the files. Looking at :echo taglist("setup_"), it has a 'name 'field that I think would be useful to show. :h setqflist allows custom 'text', but I am having trouble setting it. I've tried using map(), but haven't had any luck. Do you have any suggestions for this?
    – ThoseKind
    Nov 6, 2019 at 17:01
  • You don't need to use <expr> here; I would first move the implementation into a function, and then, yes, use map(), maybe with another inner function. Nov 6, 2019 at 20:05
  • Without <expr>, I can't pause to wait for user input as far as I understand, right? I've gotten to the point where I'm doing nmap <expr> <Leader>t ":call setloclist(0, map(taglist(\"" . input("", "", "tags") . "\"), \"extend(v:val, {'text': v:val['name']})\"))<CR>:lop<CR>". This works if I get rid of the input() call, but when I put it back in it doesn't wait for input before continuing. I will try pulling it out into a function, unless you have further input (no pun intended).
    – ThoseKind
    Nov 6, 2019 at 20:28

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.