How to create a key map to open and close the quick delete window in Vim

If I use :lopen , Vim opens the quickfix window, and if I use :lcl in the error window (or the Quickfix window itself), it closes it.

What I want to do in my .vimrc is to create a map that opens a quick fix:

 nnoremap <F2> :lopen 10<CR> 

but when I press F2 again, it closes it using :lcl .

Is there a way to find out if the quickfix window is open and then run :lcl ?

+6
source share
2 answers
+4
source

Here is another way to do this, possibly missing some gory details, but it works:

 function! ToggleQuickFix() if exists("g:qwindow") lclose unlet g:qwindow else try lopen 10 let g:qwindow = 1 catch echo "No Errors found!" endtry endif endfunction nmap <script> <silent> <F2> :call ToggleQuickFix()<CR> 

If there are no errors, the lopen function will not work, so I will try to catch it if it opens a window and creates a variable. then if he does not close it.

The most interesting thing is that this approach can be used for everything that you would like to switch.

+2
source

Source: https://habr.com/ru/post/918998/


All Articles