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?
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
).
: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.
: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?
Feb 11, 2018 at 16:27
gvim --servername GVIM "+normal 76G" myfile.tex
but it doesn't unfold.
Feb 11, 2018 at 16:34
gvim --servername VIMTEX --remote '+normal 76GzO<CR>' myfile.tex
(for some reason, the zO
(open folds) and carriage return are needed.
Mar 26, 2018 at 16:39