Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close the location list after opening an entry from it in Vim?

Tags:

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”?

like image 896
dcn Avatar asked Jun 01 '12 08:06

dcn


People also ask

How do I close a quickfix list in Vim?

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.

How do I close one file in Vim?

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.


1 Answers

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>
like image 161
ib. Avatar answered Nov 15 '22 08:11

ib.