Is there a way to automatically close the current location list in Vim when the user selects an entry from it, i.e., navigates to a listed location?
The scenario in question is similar to the one in the “How to open a file in a list of files in Vim?” question. I have an external program that creates a list of locations (across multiple files) that is then loaded using the lgetfile
command. When the list is opened, e.g., using the lopen 10
command, the location list window remains open even after a location is selected.
As an alternative, I would accept any solution that allows me to have a Vim command calling a function with a single argument, based on which an external program is run to write a list of files and locations. I would want to open this list (either in the current or a split window) and be able to select a file (i.e., using ↑, ↓ for navigation and Return to select), so that the list is closed and the selected file is opened—much the same as the plugin buffer explorer works, just with a custom list of files instead of the list of buffers.
Maybe there is a (popular and maintained) plugin that could do that for me—perhaps with the added functionality of “Open in a new tab” and “Open in a split window”?
While there are several commands for navigating the quickfix list, these are the most common ones that you need to be aware of: :copen - Open the quickfix list window. :ccl or :cclose - Close the quickfix list window. :cnext or :cn - Go to the next item on the list.
You can also save your edits with ex commands. Type :w to save (write) your file but not quit vi; type :q to quit if you haven't made any edits; and type :wq to both save your edits and quit.
One can use the following mapping to automatically issue
the :lclose
command each time Return is
pressed in the quickfix or location list windows:
:autocmd FileType qf nmap <buffer> <cr> <cr>:lcl<cr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With