6

I use the mapping nnoremap <leader>m :w \|silent make\|redraw!\|cw<CR> which allows me to run make while I am editing a file by pressing <leader>m.

It annoys me that if my cursor is in the middle of a line when I run this command, after the command finishes, my cursor is moved to the start of the line.

Is there any way to prevent this behavior? I noticed that even when I run :make, the same thing happens.

8

Go out with a bang

From :help :make:

  1. If [!] is not given the first error is jumped to.

Running :make! will execute the command given by 'makeprg' (just as :make does), but will not jump to the first position in the quickfix list. Thus, your cursor position remains intact.

The quickfix list will still be populated. Just as after running :make, :cfirst will jump to the first position; :copen will open the quickfix window; etc.

2

I did not find a way to fix this using the built-in :make command. I decided to install Neomake instead, with the mapping nnoremap <leader>m :w\|:Neomake!<CR>. This fixed my issue.

  • 1
    It looks like this command is following the behavior of :make in terms of how ! works. It seems that :make! will do what you're looking for. – tommcdo May 27 '15 at 21:41
  • Yes, that's exactly what I was looking for! If you write this as an answer, I'll mark it as the correct answer. – sid-kap May 28 '15 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.