2

I'm using Syntastic plugin. I have some files with some errors (Warnings) that I can't change. When I have a file opened with error messages, and I quit the file(buffer) pressing :q, the error messages are still visible(another buffer), so I have to press :q twice to completely exit when editing a file.

So, how do I press :q just once with a file with a buffer containing my file and another buffer (location list) containing Syntastic errors? I've searched a little bit and the command to close the location list is :lcl.

When I exit a buffer with :q, if the location list for that buffer is active, I want to close it with the location list within, calling :lcl. I'm reading some autocmd BufLeave and BufWinLeave and trying to create a mapping for this, but I cant know the difference between the two. Can someone help me?

Remembering, :w, :q, :q!, :wq should all work as intended.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • Strangely, this only happens when I save *and* quit, as in `:x`/`:wq`, *and* there are changes. I might just have different config options, though. – trysis Mar 17 '17 at 14:24

2 Answers2

3

As lcl work even if there is no error window you can map q to lcl and q

cnoremap q<cr> \|lcl\|q<cr>

As suggested an abbreviation seems better

cabbrev q lcl\|q

(note the \ before |, without it does the abbreviation then quit )

mb14
  • 22,276
  • 7
  • 60
  • 102
  • The problem is that sometimes I have other buffers or tabs opened with files I still have to edit. I've update my question with more information about what I want to accomplish. – Somebody still uses you MS-DOS Nov 09 '10 at 13:58
  • This is great. It works perfectly. Just a question: to map :q! as well, should I create another cnoremap with :q! (it works, I tested) or is it possible to remap both :q and :q! in a single line? – Somebody still uses you MS-DOS Nov 09 '10 at 15:18
  • If you remap q (without ) to lcl:q (without the trailing )that will work for both, but the error list will be closed before you enter return, which is kind of weird. I would do 2 remaps. – mb14 Nov 09 '10 at 15:22
  • You're right, 2 remaps is the way to go. But I found a little bug, when I enter :wq it says "it's not a command editor wlcl". – Somebody still uses you MS-DOS Nov 09 '10 at 15:31
  • Never use `cnoremap` for this, but `:cnoreabbrev`. – Benoit Nov 09 '10 at 20:21
  • What about cabbrev? http://vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev – Somebody still uses you MS-DOS Nov 09 '10 at 21:31
  • 1
    @benoit: maybe cabbrev is better indeed, but why NEVER ? – mb14 Nov 10 '10 at 09:30
  • @somebody I change the mapping so It will work with wq. It seems than the abbrev works better anyway – mb14 Nov 10 '10 at 09:43
  • @Benoit: thanks for giving some hints, I searched about cabbrev because of your comment. And I agree with @mb14: could you explain a little more why "never" use? :) – Somebody still uses you MS-DOS Nov 10 '10 at 12:05
  • @mb14: the second solution with cabbrev still has problems with :wq. Using the first solution now works. I'm going to mark your question as accepted. If I have problems in the future, I'll get in touch in these comments :). Thanks for all your effort, I'm grateful for all these people like you in SO helping people. – Somebody still uses you MS-DOS Nov 10 '10 at 12:12
  • I believe I would need to create a script to be called. Now, if I try to quit and it doesn't have a location list, it shows an error. I should call lcl only if lcl exists. – Somebody still uses you MS-DOS Nov 10 '10 at 12:49
  • What I mean with “never” is “never when you want to alias commands, do a remapping of “name of the command”. mapping ignores word boundaries, whereas abbreving has been designed for that use. – Benoit Nov 10 '10 at 13:20
  • @mb14 and @Benoit: I came up with "cabbrev q =(getcmdtype()==':' && getcmdpos()==1 ? 'silent!lcl\|q' : 'q')", wq still doesn't work, I'm going to try to figure out. – Somebody still uses you MS-DOS Nov 10 '10 at 21:20
  • I added "cabbrev wq w\|silent!lcl\|q". Now, wq works. Do you know any possible caveats of using this approach (both cabbrev)? Thanks for your time! – Somebody still uses you MS-DOS Nov 10 '10 at 21:28
1

I realize this question is old and that the answer was accepted sometime ago. I tried using the accepted answer but it does not seem to work any more.

I did however find a workaround from this question, should others run in to this.

Basically, use a script to check if there are any other remaining windows open and if the last remaining window is a location-list, quit.

:autocmd WinEnter * if &buftype ==# 'quickfix' && winnr('$') == 1 | quit | endif

I think this may not be ideal but works well enough in the meantime.

Community
  • 1
  • 1
jmreicha
  • 3,155
  • 7
  • 32
  • 39