Loading ...
Sorry, an error occurred while loading the content.

RE: Remapping space to toggle folds breaks 4c commands

Expand Messages
  • David Fishburn
    Excellent, and thanks for updating the tip online as well. ... From: Pavel A. Papushev [mailto:ppa-nsu@mail.ru] Sent: Tuesday, June 03, 2003 2:14 AM To: David
    Message 1 of 5 , Jun 3, 2003
    • 0 Attachment
      Excellent, and thanks for updating the tip online as well.

      -----Original Message-----
      From: Pavel A. Papushev [mailto:ppa-nsu@...]
      Sent: Tuesday, June 03, 2003 2:14 AM
      To: David Fishburn
      Cc: vim@...
      Subject: Re: Remapping space to toggle folds breaks 4c<space> commands


      Hi!
      Sunday, June 1, 2003, 3:30:44 AM, you wrote:
      DF> I am trying out this Vim tip:
      DF> [...]
      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> else
      DF> if foldclosed('.') < 0
      DF> . foldclose
      DF> else
      DF> . foldopen
      DF> endif
      DF> endif
      DF> " Clear status line
      DF> echo
      DF> return "\<Space>"
      DF> endfunction

      DF> " Map this function to Space key.
      DF> noremap <space> :call ToggleFold()<CR>
      DF> [...]
      DF> I frequently use commands like this:
      DF> If I have a variable named:
      DF> prev_line_nbr
      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
      DF> behaviour.

      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>

      Explanation:
      - '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.

      --
      Best regards,
      Pavel ;)
    Your message has been successfully submitted and would be delivered to recipients shortly.