'How to close the location list after opening an entry from it in Vim?
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”?
Solution 1:[1]
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>
Solution 2:[2]
If you are using the quickfix
window, and e.g.: lopen 10
, you can still do :lopen 10 | lcl
.
And I'd recommend to read this article in the Vim Wiki(a).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Zsolt Botykai |