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

Help enhancing folds

Expand Messages
  • Clint Harames
    I need assistance from one of you vim experts. I would like to map a key such that anytime it is pressed it will toggle folds open and closed. But I want the
    Message 1 of 5 , Jul 2, 2004
    • 0 Attachment
      I need assistance from one of you vim experts.
      I would like to map a key such that anytime it is pressed it will toggle
      folds open and closed. But I want the folds to intelligently close
      based on 'ifdef.
      In other words, in the example below, I want all sections of code
      between 'ifdef and 'else (lines 3-8) to be folded away as I press the
      mapped key, but then unfolded as I press the key again (without
      affecting any other folds).
      Thanks,
      -Clint

      always @(posedge clk_xgmii_rx) begin
      xgxs_mac_rxd <= #TP xgxs_mac_rxd_unreg;
      `ifdef NO_XGMII_LED
      xgmii_lo_rx_led <= #TP 32'd0; // For no LED drive
      xgmii_hi_rx_led <= #TP 32'd0; //
      xgmii_ctrl_lo_rx_led <= #TP 4'd0; //
      xgmii_ctrl_hi_rx_led <= #TP 4'd0; //
      `else
      xgmii_lo_rx_led <= #TP xgmii_lo_rx; // For LED drive
      xgmii_hi_rx_led <= #TP xgmii_hi_rx; //
      xgmii_ctrl_lo_rx_led <= #TP xgmii_ctrl_lo_rx; //
      xgmii_ctrl_hi_rx_led <= #TP xgmii_ctrl_hi_rx; //
      `endif
      End

      Would become:
      always @(posedge clk_xgmii_rx) begin
      xgxs_mac_rxd <= #TP xgxs_mac_rxd_unreg;
      +-- 6 lines: 'ifdef FPGA----------------------------------------------
      xgmii_lo_rx_led <= #TP xgmii_lo_rx; // For LED drive
      xgmii_hi_rx_led <= #TP xgmii_hi_rx; //
      xgmii_ctrl_lo_rx_led <= #TP xgmii_ctrl_lo_rx; //
      xgmii_ctrl_hi_rx_led <= #TP xgmii_ctrl_hi_rx; //
      `endif
      end
    • David Fishburn
      ... I have the following in my vimrc: Tip: 108 Toggle a fold with a single keystroke {{{ Toggle fold state between closed and opened. Based on Vim tip:
      Message 2 of 5 , Jul 2, 2004
      • 0 Attachment
        > -----Original Message-----
        > From: Clint Harames [mailto:c.harames@...]
        > Sent: Friday, July 02, 2004 1:43 PM
        > To: vim@...
        > Subject: Help enhancing folds
        >
        > I need assistance from one of you vim experts.
        > I would like to map a key such that anytime it is pressed it
        > will toggle folds open and closed. But I want the folds to
        > intelligently close based on 'ifdef.
        > In other words, in the example below, I want all sections of
        > code between 'ifdef and 'else (lines 3-8) to be folded away
        > as I press the mapped key, but then unfolded as I press the
        > key again (without affecting any other folds).
        > Thanks,
        > -Clint
        >
        > always @(posedge clk_xgmii_rx) begin
        > xgxs_mac_rxd <= #TP xgxs_mac_rxd_unreg; `ifdef NO_XGMII_LED
        > xgmii_lo_rx_led <= #TP 32'd0; // For no LED drive
        > xgmii_hi_rx_led <= #TP 32'd0; //
        > xgmii_ctrl_lo_rx_led <= #TP 4'd0; //
        > xgmii_ctrl_hi_rx_led <= #TP 4'd0; // `else
        > xgmii_lo_rx_led <= #TP xgmii_lo_rx; // For LED drive
        > xgmii_hi_rx_led <= #TP xgmii_hi_rx; //
        > xgmii_ctrl_lo_rx_led <= #TP xgmii_ctrl_lo_rx; //
        > xgmii_ctrl_hi_rx_led <= #TP xgmii_ctrl_hi_rx; // `endif End
        >
        > Would become:
        > always @(posedge clk_xgmii_rx) begin
        > xgxs_mac_rxd <= #TP xgxs_mac_rxd_unreg;
        > +-- 6 lines: 'ifdef FPGA----------------------------------------------
        > xgmii_lo_rx_led <= #TP xgmii_lo_rx; // For LED drive
        > xgmii_hi_rx_led <= #TP xgmii_hi_rx; //
        > xgmii_ctrl_lo_rx_led <= #TP xgmii_ctrl_lo_rx; //
        > xgmii_ctrl_hi_rx_led <= #TP xgmii_ctrl_hi_rx; // `endif end
        >

        I have the following in my vimrc:

        " Tip: 108 Toggle a fold with a single keystroke {{{
        " Toggle fold state between closed and opened.
        " Based on Vim tip:
        " http://www.vim.org/tips/tip.php?tip_id=108
        " 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

        " belong to fold.
        nnoremap <silent> <space>
        \ :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<cr>
        "}}}


        So in normal mode, if I hit space, it will toggle the fold.
        I use this constantly.

        HTH,
        Dave
      • Clint Harames
        A nice tip, but doesn t do what I need. The folds in my example don t already exist. I need something that can create folds based on the ifdef and will then
        Message 3 of 5 , Jul 6, 2004
        • 0 Attachment
          A nice tip, but doesn't do what I need. The folds in my example don't
          already exist. I need something that can create folds based on the
          'ifdef and will then close them.
          I suspect I'll have to figure out how to write some sort of VIM script,
          but I didn't know where to start.
          In the mean time I manually find the lines of interest (between `ifdef
          and `else), visual-select them and do :fold to get them out of the way.
          -Clint

          -----Original Message-----
          From: David Fishburn [mailto:fishburn@...]
          Sent: Friday, July 02, 2004 11:41 AM
          To: Clint Harames
          Cc: vim@...
          Subject: RE: Help enhancing folds



          > -----Original Message-----
          > From: Clint Harames [mailto:c.harames@...]
          > Sent: Friday, July 02, 2004 1:43 PM
          > To: vim@...
          > Subject: Help enhancing folds
          >
          > I need assistance from one of you vim experts.
          > I would like to map a key such that anytime it is pressed it
          > will toggle folds open and closed. But I want the folds to
          > intelligently close based on 'ifdef.
          > In other words, in the example below, I want all sections of
          > code between 'ifdef and 'else (lines 3-8) to be folded away
          > as I press the mapped key, but then unfolded as I press the
          > key again (without affecting any other folds).
          > Thanks,
          > -Clint
          >
          > always @(posedge clk_xgmii_rx) begin
          > xgxs_mac_rxd <= #TP xgxs_mac_rxd_unreg; `ifdef NO_XGMII_LED
          > xgmii_lo_rx_led <= #TP 32'd0; // For no LED drive
          > xgmii_hi_rx_led <= #TP 32'd0; //
          > xgmii_ctrl_lo_rx_led <= #TP 4'd0; //
          > xgmii_ctrl_hi_rx_led <= #TP 4'd0; // `else
          > xgmii_lo_rx_led <= #TP xgmii_lo_rx; // For LED drive
          > xgmii_hi_rx_led <= #TP xgmii_hi_rx; //
          > xgmii_ctrl_lo_rx_led <= #TP xgmii_ctrl_lo_rx; //
          > xgmii_ctrl_hi_rx_led <= #TP xgmii_ctrl_hi_rx; // `endif End
          >
          > Would become:
          > always @(posedge clk_xgmii_rx) begin
          > xgxs_mac_rxd <= #TP xgxs_mac_rxd_unreg;
          > +-- 6 lines: 'ifdef FPGA----------------------------------------------
          > xgmii_lo_rx_led <= #TP xgmii_lo_rx; // For LED drive
          > xgmii_hi_rx_led <= #TP xgmii_hi_rx; //
          > xgmii_ctrl_lo_rx_led <= #TP xgmii_ctrl_lo_rx; //
          > xgmii_ctrl_hi_rx_led <= #TP xgmii_ctrl_hi_rx; // `endif end
          >

          I have the following in my vimrc:

          " Tip: 108 Toggle a fold with a single keystroke {{{
          " Toggle fold state between closed and opened.
          " Based on Vim tip:
          " http://www.vim.org/tips/tip.php?tip_id=108
          " 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

          " belong to fold.
          nnoremap <silent> <space>
          \ :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<cr>
          "}}}


          So in normal mode, if I hit space, it will toggle the fold.
          I use this constantly.

          HTH,
          Dave
        • gumnos (Tim Chase)
          ... I don t know if it will help you towards a solution, but if your if/else/endif aren t nested, but all at just a top level, you can exploit a couple global
          Message 4 of 5 , Jul 6, 2004
          • 0 Attachment
            > The folds in my example don't already exist. I need something
            > that can create folds based on the 'ifdef and will then close

            I don't know if it will help you towards a solution, but if your
            if/else/endif aren't nested, but all at just a top level, you can
            exploit a couple global commands, something like

            :g/'ifdef/.,/'else/-1 fold
            :g/'else/.,/'endif/fold

            and if you've got an 'elseif construct, you can make it

            :g/'ifdef/.,/'else\|'endif/-1 fold
            :g/'elseif/.,/'else\|'endif/-1 fold
            :g/'else\>/.,/'endif/-1 fold

            If you want the 'endif lines included in the fold, you'd have to
            1) split out the 'else from the 'endif into two separate lines
            2) remove the -1 from any :g statement that goes to an 'endif

            All this can be wrapped in a function or keypress to generate
            your folds. You might also want to make sure than any existing
            such folds are cleared beforehand with either

            zE

            to clear all the folds, or something like

            :g/'ifdef\|'else\|'endif/norm zD

            which should just delete folds from the lines containing the
            ifdef/else/endif.

            Hopefully this will help you towards the solution you seek,

            -tim
          • Clint Harames
            That is exactly the kind of start I was looking for. Thanks, -Clint ... From: gumnos (Tim Chase) [mailto:gumnos@hotmail.com] Sent: Tuesday, July 06, 2004 7:51
            Message 5 of 5 , Jul 6, 2004
            • 0 Attachment
              That is exactly the kind of start I was looking for.
              Thanks,
              -Clint

              -----Original Message-----
              From: gumnos (Tim Chase) [mailto:gumnos@...]
              Sent: Tuesday, July 06, 2004 7:51 AM
              To: Clint Harames
              Cc: vim@...
              Subject: Re: Help enhancing folds

              > The folds in my example don't already exist. I need something
              > that can create folds based on the 'ifdef and will then close

              I don't know if it will help you towards a solution, but if your
              if/else/endif aren't nested, but all at just a top level, you can
              exploit a couple global commands, something like

              :g/'ifdef/.,/'else/-1 fold
              :g/'else/.,/'endif/fold

              and if you've got an 'elseif construct, you can make it

              :g/'ifdef/.,/'else\|'endif/-1 fold
              :g/'elseif/.,/'else\|'endif/-1 fold
              :g/'else\>/.,/'endif/-1 fold

              If you want the 'endif lines included in the fold, you'd have to
              1) split out the 'else from the 'endif into two separate lines
              2) remove the -1 from any :g statement that goes to an 'endif

              All this can be wrapped in a function or keypress to generate
              your folds. You might also want to make sure than any existing
              such folds are cleared beforehand with either

              zE

              to clear all the folds, or something like

              :g/'ifdef\|'else\|'endif/norm zD

              which should just delete folds from the lines containing the
              ifdef/else/endif.

              Hopefully this will help you towards the solution you seek,

              -tim
            Your message has been successfully submitted and would be delivered to recipients shortly.