When I move lines with m (e.g. :m+1) all my folds are closed. I can then open the folding with zv again and the cursor will be at the position I moved to. I use folding with {{{ }}} marks and have set foldmethod=marker in my .vimrc.

How can I prevent vim from closing folds when moving lines?

  • 1
    I can't reproduce this using vim -u NONE -U NONE -N. It might be an issue with your vimrc or a plugin. May 5, 2015 at 11:39
  • 2
    Happens for me even with -u NONE -U NONE -N. I use v7.4 on arch linux
    – dnieder
    May 5, 2015 at 13:39
  • 1
    @EvergreenTree I have the same problem. With vim -u NONE -U NONE -N fold-test and just setting foldmethod=marker. I'm running Vim 7.4.712 on Arch. If I try the same with Vim on Vim 7.4.160 on CentOS 7, I get exactly the opposite results (all folds open when using :m+1). And Vim 7.2.441 on CentOS 6 works fine... All fold* settings seem to be the same on these machines. May 5, 2015 at 13:41
  • 1
    That is very strange. This seems like a bug. May 5, 2015 at 14:35
  • 3
    That might be caused by patch 7.4.700 which tries to prevent, that folds get invalid on :move commands May 5, 2015 at 20:36

2 Answers 2


You can disable folding before doing :m+1 by using zi. And then enable it again with zi.

You can also add a special mapping for that in your .vimrc :

""move line up/down with Shift+up/down
nnoremap <S-Up> zi:m-2<CR>zi
nnoremap <S-Down> zi:m+<CR>zi
inoremap <S-Up> <Esc>zi:m-2<CR>zia
inoremap <S-Down> <Esc>zi:m+<CR>zia
  • This worked for me. (although I used different bindings) Dec 13, 2016 at 17:07

Folding is a pretty complicated mechanism (see another answer I gave about folds for a nuanced discussion of folding scanning).

In order to give a complete answer we will need to see what type of plugins you are loading when booting up an instance of vim.

I'd bet that there are a few plugins that are mucking with the default vim settings (vim -u NONE should have reproduced this). Any plugin that changes the foldmethod is a likely cause (I'd try to remove them 1 by 1 and see what causes the issue)

If you don't want to muck with your plugins at all I'd recommend manually tweaking the syntax + parsing settings and then open a test buffer to confirm your functionality. It can be a frustrating journey to get it to play nicely but with some relentless digging in :help you should be able to wrangle the beast that is folding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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