1

In order to switch between relative and absolute line numbering upon entering command-line, I noremap <expr> <CR> to "someStuff".

Unfortunately this breaks the foldopen-ing feature for forward searches.

It already happens with the following line

cnoremap <CR> <CR>

MWE

entire .vimrc

set foldmethod=marker
"default foldopen
set foldopen=block,hor,mark,percent,quickfix,search,tag,undo
cnoremap <CR> <CR>

text file

{{{
lkj
}}}

maneuver : normal-mode-type /lkj<CR>

and the fold does not open

comment the cnoremap reload and do the same, the fold does open

Attempts

I somewhat managed to walk around the issue with a silly hack such as :

cnoremap <CR> <CR>i<C-c>

unfortunately this breaks the repeat (.) history.

The following works :

cnoremap <CR> <CR>mf.u`f

except at the opening of a vim session, when the . repeat does nothing.

Is there some way to achieve the cnoremapping <CR> <CR> in a fully transparent way ?

3

As :h 'foldopen' states:

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)

So you should add the zv to your mapping, e.g. cnoremap <cr> <cr>zv

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.