问题
I need exactly the opposite behavior of this question. My observation is that upon pressing enter on a line in location list window, the window will be closed and the main window will display the content of the selected file. As a contrary, quickfix window doesn't have this behavior, i.e., it remains opened after the selection.
I have checked my autocmd and there is no special handling for location list or quickfix list.
An example - :lgrep hi * to populate the location list. lopen to open the location list window. Press enter on any line.
回答1:
Syntastic and the location-list window
Syntastic by default closes the location list window when no errors are present. Therefore if you use something like :lgrep which does not mark any of the results as errors then the location-list window will close once you leave the location-list window, e.g. like using <cr> to jump to a location.
Syntastic provides a way to tweak this via g:syntastic_auto_loc_list variable. Setting this to 0 will disable the auto-close functionality.
Set the following in your vimrc file:
let g:syntastic_auto_loc_list = 0
To learn more about this variable see: :h 'syntastic_auto_loc_list'.
Generic Vim debugging
Often the easiest way to test if your vimrc or a plugin is causing problem is it compare the functionality to a vanilla vim config (or at least more vanilla). Do this by starting up Vim without a vimrc. I use the following invocation:
vim -N -u NONE
Once you have started up Vim in this manner you can test for you bug and see if it is present.
- If the bug is still present then it that means it is probably a part of Vim nature or a bug with Vim itself. In this case I suggest you do more read the documentation via
:h :help,:h :helpgrep, and:h bug-reports - If the bug is not present then the error is occurring due to something in your
vimrcor plugin. This often means you need to disable portions of your vimrc/plugins to try and find the culprit. A fast way is to use a binary search.
Slightly more complicated debugging with :verbose
Often a bug is easier to track down directly by using :verbose to see where something was last set. (See :h :verbose)
- Mappings will display were they are last set. e.g.
:verbose nmap <leader>foo. See:h :map-verboseand:h map-listing. - Settings will display where they were last set as well. e.g.
:verbose set shiftwidth. See:h :set-verbose. - Autocomd's will display where they are last defined. e.g.
:verbose autocmd BufEnter. See:h :autocmd-verboseand:h autocmd-list.
Advanced debugging with 'verbosefile'
Another way to debug something is to use 'verbose'/:verbose and 'verbosefile' to effectively log what Vim is doing.
Example of using :verbose and 'verbosefile' to debug your bug.
- Do
:lgrepcommand - Open location-list window via
:lopen - Set
'verbosefile'via:set verbosefile=~/verbose.txt :15verbose normal <c-v><cr>- Now open the log file via
:sp ~/verbose.txt - Search the log file for anything suspicious. e.g.
closeorlclosein your case - Once found it will show you the
autocmdor function that is causing the closing. - If
autocmdlook to revise it. - If a function you may need to look at
:scriptnamesto figure out which file the is associated with script local functions. See:scriptnamesand:h <SID>.
I find using Tim Pope's scriptease.vim makes this process easier by providing the :Verbose command which will setup 'verbosefile' for you as well as open it right afterwards in the preview window. Scriptease also provides a nice wrapper around :scriptnames via :Scriptnames. In general scriptease.vim provides many helpful methods to debugging and reloading plugins.
More help
:h 'syntastic_auto_loc_list'
:h syntastic
:h -u
:h -N
:h :help
:h :helpgrep
:h bug-reports
:h :map
:h map-listing
:h :set
:h set-option
:h :set-verbose
:h :autocmd-verbose
:h autocmd-list
:h 'verbose'
:h :verbose
:h 'verbosefile'
:h :scriptnames
:h <SID>
:h :normal
:h c_CTRL-V
回答2:
Use :cw to get quickfix window. It will appear horizontally split to current window. and :ccl to return back to selected result
来源:https://stackoverflow.com/questions/32405480/vim-keep-location-list-window-open-after-selecting-a-file