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

Re: Automatically open fold with in normal mode?

Expand Messages
  • David Fishburn
    ... I use the following for mine (using the space bar, not the enter key): nnoremap :exe silent! normal! .((foldclosed( . ) 0)? zMzxzt :
    Message 1 of 4 , Aug 16, 2013
    • 0 Attachment

      On Fri, Aug 16, 2013 at 9:32 AM, Jürgen Krämer <jottkaerr@...> wrote:

      Hi,

      Reckoner wrote:
      >
      > I'm using vim 7.3 on windows 8.
      >
      > Is there a way to setup a normal mode mapping where if I hit <enter> on a folded section, it will open that section (as in zO). The trick is that I only want that mapping to work *while on a folded line* and not otherwise  map <enter> elsewhere.
      >
      > Possible?

      use the following mapping:

        nnoremap <expr> <cr> foldclosed(line('.')) == -1 ? "\<cr>" : "zO"


      Reckoner,

      I use the following for mine (using the space bar, not the enter key):
      nnoremap  <silent> <space> :exe 'silent! normal! '.((foldclosed('.')>0)? "zMzxzt" : 'zc')<cr>

      Which came originally from Vim Tip 108, which when moved to the wiki is now part of:

      And of course changes from discussions on this list.

      Whether that helps or not.
      You can try both in different scenarios, when the fold is in different spots (top of window, bottom, middle and so on).

      David

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
       
      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Reckoner
      ... Thanks for all the great tips and the reference link. I wound up using: nnoremap foldclosed(line( . )) == -1 ? : zA nnoremap
      Message 2 of 4 , Aug 16, 2013
      • 0 Attachment
        On Friday, August 16, 2013 7:00:15 AM UTC-7, David Fishburn wrote:
        > On Fri, Aug 16, 2013 at 9:32 AM, Jürgen Krämer <jott...@...> wrote:
        >
        >
        >
        > Hi,
        >
        >
        >
        >
        > Reckoner wrote:
        >
        > >
        >
        > > I'm using vim 7.3 on windows 8.
        >
        > >
        >
        > > Is there a way to setup a normal mode mapping where if I hit <enter> on a folded section, it will open that section (as in zO). The trick is that I only want that mapping to work *while on a folded line* and not otherwise  map <enter> elsewhere.
        >
        >
        > >
        >
        > > Possible?
        >
        >
        >
        > use the following mapping:
        >
        >
        >
        >   nnoremap <expr> <cr> foldclosed(line('.')) == -1 ? "\<cr>" : "zO"
        >
        >
        >
        >
        > Reckoner,
        >
        >
        > I use the following for mine (using the space bar, not the enter key):
        >
        > nnoremap  <silent> <space> :exe 'silent! normal! '.((foldclosed('.')>0)? "zMzxzt" : 'zc')<cr>
        >
        >
        >
        > Which came originally from Vim Tip 108, which when moved to the wiki is now part of:
        > http://vim.wikia.com/wiki/Folding%c2%a0
        >
        >
        >
        > And of course changes from discussions on this list.
        >
        >
        > Whether that helps or not.
        > You can try both in different scenarios, when the fold is in different spots (top of window, bottom, middle and so on).
        >
        >
        >
        > David

        Thanks for all the great tips and the reference link. I wound up using:

        nnoremap <expr> <s-cr> foldclosed(line('.')) == -1 ? "\<cr>" : "zA"
        nnoremap <expr> <cr> foldlevel(line('.')) ? "za" : "\<cr>"

        BTW, is there a way to set the foldlevel using a mapping? I use the
        SimpylFold plugin, which is great, but automatically sets the foldlevel to expr, which prohibits me from manually folding.

        Thanks!


        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      Your message has been successfully submitted and would be delivered to recipients shortly.