1

I would like to map a key so I can quick close all folds but keep unfolded on current cursor and keep cursor's position too.
Through :h fold I can use zMzv but it can't keep cursor's position.

  • 1
    Oddly enough, I tried zMzv today and it kept the correct cursor position... curious. – D. Ben Knoble Nov 7 '17 at 0:06
  • I should be more clear about this, I mapped to a key so that it will contain <CR> at the end and reset cursor to next line. – Tuyen Pham Nov 7 '17 at 0:13
  • Why do you need the <CR> though? I.e., why doesn’t for example nnoremap <leader>zo zMzv do the trick? – D. Ben Knoble Nov 7 '17 at 0:17
  • Sorry about the question, you're right. But screen will blink because close and open fold task - the output. mark seems sovled it, but Idk why. – Tuyen Pham Nov 7 '17 at 0:28
2

You can set a mark at the beginning of your mapping and then jump there at the end. For example:

nnoremap <leader>zv :normal mazMzv`a<CR>
  • :-) No worries. – B Layer Nov 6 '17 at 6:12
  • 1
    I am curious if am I missing something? If I press zx , zv , zMzv, etc.. the folds change but the cursor does not move. So I don't understand why the mark is necessary. – Mass Nov 6 '17 at 20:17
  • If you map zx to a key: nnoremap <space>zx :zx<CR> for i.e, ` zx` will change cursor's position. – Tuyen Pham Nov 7 '17 at 0:12

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.