RE: Remapping space to toggle folds breaks 4c commands
- Excellent, and thanks for updating the tip online as well.
From: Pavel A. Papushev [mailto:ppa-nsu@...]
Sent: Tuesday, June 03, 2003 2:14 AM
To: David Fishburn
Subject: Re: Remapping space to toggle folds breaks 4c<space> commands
Sunday, June 1, 2003, 3:30:44 AM, you wrote:
DF> I am trying out this Vim tip:
DF> " If there is no fold at current line, just moves forward. " If it
DF> is present, reverse it's state. function! ToggleFold()
DF> if foldlevel('.') == 0
DF> normal! l
DF> if foldclosed('.') < 0
DF> . foldclose
DF> . foldopen
DF> " Clear status line
DF> return "\<Space>"
DF> " Map this function to Space key.
DF> noremap <space> :call ToggleFold()<CR>
DF> I frequently use commands like this:
DF> If I have a variable named:
DF> I would be on the p and type "4c ". That would change 4 characters.
DF> Unfortunately, the space is eaten by the toggle command. So I tried
DF> to return a "\<Space>" hoping that would provide the usual
Piet Delport already explained you that you shouldn't redefine <space>
in operator-pending mode. It's useless to return "\Space" because it is
not used anyhow at all. I want to add, that there is more shorter way to
do exactly what you want:
nnoremap <silent> <space>
\ :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<cr>
- 'normal! za' toggles folds.
- 'silent!' allows to avoid error message when current line doesn't
delong to fold.
- (foldlevel('.')?'':'l') adds forward moving only if current line
doesn't delong to fold.