I use {/} a lot for navigating around, but when I do this I never intend to open a fold and jump to blank lines within the fold.

How can I nremap { and } to skip over folds?

1 Answer 1


Thanks to @romainl for this answer on super user. I couldn't have written this without their help!

You can use the foldopen option to determine which set of motions will or won't open a fold. From :h 'foldopen'

                        *'foldopen'* *'fdo'*
'foldopen' 'fdo'    string (default: "block,hor,mark,percent,quickfix,
            {not in Vi}
            {not available when compiled without the |+folding|
    Specifies for which type of commands folds will be opened, if the
    command moves the cursor into a closed fold.  It is a comma separated
    list of items.
    NOTE: When the command is part of a mapping this option is not used.
    Add the |zv| command to the mapping to get the same effect.
    (rationale: the mapping may want to control opening folds itself)

As for which values are allowed, and which commands they affect, refer to this table:

item        commands ~
all         any
block       "(", "{", "[[", "[{", etc.
hor         horizontal movements: "l", "w", "fx", etc.
insert      any command in Insert mode
jump        far jumps: "G", "gg", etc.
mark        jumping to a mark: "'m", CTRL-O, etc.
percent     "%"
quickfix    ":cn", ":crew", ":make", etc.
search      search for a pattern: "/", "n", "*", "gd", etc.
                (not for a search pattern in a ":" command)
                Also for |[s| and |]s|.
tag         jumping to a tag: ":ta", CTRL-T, etc.
undo        undo or redo: "u" and CTRL-R

As you can see, the { and } motions are in block, so if you run:

:set foldopen-=block

that should fix it for you.


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.