When I jump to line (:76) I end up on a fold, but it doesn't open.

I can quickly unfold the fold and it gets to the right line, but I want to have the fold unfold automatically to save keystrokes.

Is there a way this can be achieved?

up vote 5 down vote accepted

The foldopen setting controls which commands will open folds. In :help 'foldopen' we can see the list of possible values:

            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

From reading the documentation you'd expect that set foldopen+=jump would do the trick, but it doesn't work for :76, only 76G. I'm not sure if this is intentional or a bug in Vim.

Using set foldopen=all does work correctly; but may have unwanted side-effects (specifically, you can no longer move "over" a fold with j and k).

  • 2
    :76 is not considered a "jump" in vim and is not remembered in the jumplist (:jumps). 76G on the other hand is a jump (documented in :h jump-motions, so unlikely to be a bug). You may want to add that you can use zv after :76 to open the fold. – Mass Sep 4 '17 at 14:42
  • @Mass The OP doesn't want to have to type anything to open the fold,once they land on it. – Herb Wolfe Sep 4 '17 at 15:08
  • Just like :76, jumping while launching vim doesn't seem to open folds (example: gvim +76 myfile.tex... I'm using it with the option --servername with synctex). Is there a workaround? What's the Ex command for jumping? – PlasmaBinturong Feb 11 at 16:27
  • I have tried gvim --servername GVIM "+normal 76G" myfile.tex but it doesn't unfold. – PlasmaBinturong Feb 11 at 16:34
  • Something that worked for me to open folds from via the server capability: gvim --servername VIMTEX --remote '+normal 76GzO<CR>' myfile.tex (for some reason, the zO (open folds) and carriage return are needed. – PlasmaBinturong Mar 26 at 16:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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