1

In Vim, :cw command shows the quickfix window if there are any errors and let the cursor jump to the first recognized error in the quickfix window (not in the buffer where there is an error). Is there a command to do the same job but not jump to the first error, but stay in where it was?

1 Answer 1

2

If your problem is that the quickfix window steals the focus from the window you are currently working in, the solution is quite simple. Add these lines to your ~/.vimrc:

augroup quickfix
  autocmd!
  autocmd Syntax qf wincmd p
augroup END

It's not the :cw[indow] command that jumps your cursor on the first matching line in the buffer, it's the command that created the list displayed in the quickfix window that does that.

Suppose you have:

foo
foobar
foobarbaz

and you do:

:vim foo %

your cursor is automatically positioned on the first matching line, without :cw.

If you do:

:vim foo % | cw

your cursor is still positioned on the first matching line so that behavior is not linked with :cw.

But if you do:

:vim /foo/j % | cw

your cursor stays put. See :help :vimgrep.

You should check the documentation of the command you are using to see if it has an equivalent of that j flag.

6
  • :make command has an equivalent flag (!), however, if I run :make! | cw, it still automatically jumps. Can you explain this?
    – xuhdev
    Jul 2, 2014 at 0:12
  • OK, I think we have misunderstanding here. I mean, :cw command automatically let the cursor jump to the first error line of the quickfix window, NOT in the buffer.
    – xuhdev
    Jul 2, 2014 at 0:22
  • What would be your desired behaviour, then? Going to the last line in the list? Going to the line in the list that is closest to the current line in the buffer? Going to an arbitrary line? A random line? Don't you think it's somewhat logical to start fixing errors with… the first one?
    – romainl
    Jul 2, 2014 at 7:19
  • My desired behavior is to create this new quickfix window, but the cursor remain where it is.
    – xuhdev
    Jul 2, 2014 at 7:28
  • So your problem is that the quickix window is focused upon :cw but you want the focus to stay on the current window, is that right?
    – romainl
    Jul 2, 2014 at 7:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .