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

commenting out/in a paragraph (haml)

Expand Messages
  • Алексей Данченков
    Hi! I just started diving into vi (and just subscribed to the mailing list) and so far learned a basic moving around/editing commands. While I am going through
    Message 1 of 7 , Feb 7, 2012

      Hi!

      I just started diving into vi (and just subscribed to the mailing list) and so far learned a basic moving around/editing commands. While I am going through the basic book, is there a fast way to comment out a paragraph with -# in the same column with the cursor position (indenting the lines accordingly)?

      Let's say I have a piece of code:

      %table
        - unless paginate(@clients).nil?
          %tr
            %th
              =t('index.name')
            %th
              =t('index.address')
            %th
              =t('index.phone')
          =render :partial => 'client', :collection => @clients
      

      and I want to comment out 9 lines (or a paragraph?) between - unless and =render :partial with -# in one column like that...

      %table
      -# - unless paginate(@clients).nil?
      -# %tr
      -# %th
      -# =t('index.name')
      -# %th
      -# =t('index.address')
      -# %th
      -# =t('index.phone')
      -# =render :partial => 'client', :collection => @clients

      ...and then be able to comment them in again. What command would that be?

      Cheers, Alexei

      --
      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
    • Ben Fritz
      ... I believe there s some commenting plugins out there, but I ve never used them, so I cannot speak much on them. The easiest way to insert the same text in
      Message 2 of 7 , Feb 7, 2012
        On Feb 7, 5:51 am, Алексей Данченков <adanchen...@...> wrote:
        > Hi!
        >
        > I just started diving into vi (and just subscribed to the mailing list) and
        > so far learned a basic moving around/editing commands. While I am going
        > through the basic book, is there a fast way to comment out a paragraph with
        > -# in the same column with the cursor position (indenting the lines
        > accordingly)?
        >
        > Let's say I have a piece of code:
        >
        > %table
        >   - unless paginate(@clients).nil?
        >     %tr
        >       %th
        >         =t('index.name')
        >       %th
        >         =t('index.address')
        >       %th
        >         =t('index.phone')
        >     =render :partial => 'client', :collection => @clients
        >
        > and I want to comment out 9 lines (or a paragraph?) between - unless
        > and =render
        > :partial with -# in one column like that...
        >
        > %table
        >
        >   -# - unless paginate(@clients).nil?
        >   -#   %tr
        >   -#     %th
        >   -#       =t('index.name')
        >   -#     %th
        >   -#       =t('index.address')
        >   -#     %th
        >   -#       =t('index.phone')
        >
        >   -#   =render :partial => 'client', :collection => @clients
        >
        > ...and then be able to comment them in again. What command would that be?
        >

        I believe there's some commenting plugins out there, but I've never
        used them, so I cannot speak much on them.

        The easiest way to insert the same text in the same position in a
        range of lines, is to use blockwise-visual mode (often called "column
        edit" or "column select" in other editors). To enter blockwise-visual
        mode, press CTRL-V in normal mode. If CTRL-V pastes for you (or does
        some other action instead of blockwise visual mode), you can instead
        use CTRL-Q.

        Once in blockwise visual mode, move the cursor to the last line you
        want to insert text on. Depending on how your code is formatted, you
        might be able to use } to hit the next blank line, use ap to select a
        "paragraph" text object, use 'j' and 'k' repeatedly, use a search, or
        any other way of moving the cursor. Vim has plenty of cursor motion
        commands, and I've never coded in haml, so I'm not sure what ways to
        move efficiently about haml code are best.

        After you have all the lines selected, press I to insert text just
        before the selection on all lines, or A to enter text just after. Type
        the desired text, press <Esc>, and Vim will populate all lines with
        your text.

        That's a lot of explanation, but it should really only be a few
        keystrokes. For example, if all goes well, you can type:

        CTRL-V
        }
        I
        -#
        <Esc>

        or

        CTRL-V
        9j
        I
        -#
        <Esc>

        The takeaway message is "use blockwise visual mode for inserting text
        on lots of lines at once".

        To uncomment, go into blockwise visual mode with CTRL-V, highlight all
        the inserted comments, and press d to delete them.

        Notes:
        * I mentioned the "ap" text object previously, but this changes the
        visual mode on you, so you'll need to force visual-block mode after
        using. Something like:
        v
        ap
        CTRL-V
        I
        -#
        <Esc>
        * It's much easier to use counts on j/k if you turn on the
        'relativenumber' option, so you can use my "9j" suggestion without
        actually counting lines

        --
        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
      • ConcreteVitamin
        Hi Alexei, ... Change 999 and 1000 to corresponding lines. ... -- You received this message from the vim_use maillist. Do not top-post! Type your reply below
        Message 3 of 7 , Feb 7, 2012
          Hi Alexei,

          You can do a replace command:

          :999,1000s/^/[You comment notation]/g

          Change 999 and 1000 to corresponding lines.

          On Wed, Feb 8, 2012 at 6:21 AM, Ben Fritz <fritzophrenic@...> wrote:


          On Feb 7, 5:51 am, Алексей Данченков <adanchen...@...> wrote:
          > Hi!
          >
          > I just started diving into vi (and just subscribed to the mailing list) and
          > so far learned a basic moving around/editing commands. While I am going
          > through the basic book, is there a fast way to comment out a paragraph with
          > -# in the same column with the cursor position (indenting the lines
          > accordingly)?
          >
          > Let's say I have a piece of code:
          >
          > %table
          >   - unless paginate(@clients).nil?
          >     %tr
          >       %th
          >         =t('index.name')
          >       %th
          >         =t('index.address')
          >       %th
          >         =t('index.phone')
          >     =render :partial => 'client', :collection => @clients
          >
          > and I want to comment out 9 lines (or a paragraph?) between - unless
          > and =render
          > :partial with -# in one column like that...
          >
          > %table
          >
          >   -# - unless paginate(@clients).nil?
          >   -#   %tr
          >   -#     %th
          >   -#       =t('index.name')
          >   -#     %th
          >   -#       =t('index.address')
          >   -#     %th
          >   -#       =t('index.phone')
          >
          >   -#   =render :partial => 'client', :collection => @clients
          >
          > ...and then be able to comment them in again. What command would that be?
          >

          I believe there's some commenting plugins out there, but I've never
          used them, so I cannot speak much on them.

          The easiest way to insert the same text in the same position in a
          range of lines, is to use blockwise-visual mode (often called "column
          edit" or "column select" in other editors). To enter blockwise-visual
          mode, press CTRL-V in normal mode. If CTRL-V pastes for you (or does
          some other action instead of blockwise visual mode), you can instead
          use CTRL-Q.

          Once in blockwise visual mode, move the cursor to the last line you
          want to insert text on. Depending on how your code is formatted, you
          might be able to use } to hit the next blank line, use ap to select a
          "paragraph" text object, use 'j' and 'k' repeatedly, use a search, or
          any other way of moving the cursor. Vim has plenty of cursor motion
          commands, and I've never coded in haml, so I'm not sure what ways to
          move efficiently about haml code are best.

          After you have all the lines selected, press I to insert text just
          before the selection on all lines, or A to enter text just after. Type
          the desired text, press <Esc>, and Vim will populate all lines with
          your text.

          That's a lot of explanation, but it should really only be a few
          keystrokes. For example, if all goes well, you can type:

          CTRL-V
          }
          I
          -#
          <Esc>

          or

          CTRL-V
          9j
          I
          -#
          <Esc>

          The takeaway message is "use blockwise visual mode for inserting text
          on lots of lines at once".

          To uncomment, go into blockwise visual mode with CTRL-V, highlight all
          the inserted comments, and press d to delete them.

          Notes:
          * I mentioned the "ap" text object previously, but this changes the
          visual mode on you, so you'll need to force visual-block mode after
          using. Something like:
          v
          ap
          CTRL-V
          I
          -#
          <Esc>
          * It's much easier to use counts on j/k if you turn on the
          'relativenumber' option, so you can use my "9j" suggestion without
          actually counting lines

          --
          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 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
        • Benjamin R. Haskell
          ... Not built-in, no. I find The NERD Commenter¹ extremely useful. c toggles commenting on the current line, or visually-selected region. I
          Message 4 of 7 , Feb 7, 2012
            On Tue, 7 Feb 2012, Алексей Данченков wrote:

            >
            > Hi!
            >
            > I just started diving into vi (and just subscribed to the mailing
            > list) and so far learned a basic moving around/editing commands. While
            > I am going through the basic book, is there a fast way to comment out
            > a paragraph with -# in the same column with the cursor position
            > (indenting the lines accordingly)?

            Not built-in, no. I find The NERD Commenter¹ extremely useful.

            <Leader>c<Space> toggles commenting on the current line, or
            visually-selected region. I use ',' as my leader character², so it's
            <,><c>< >.

            I also find VIM Addon Manager³ even more useful. If you set that up
            first, you'll be able to install the commenter via:

            :InstallAddons The_NERD_Commenter

            --
            Best,
            Ben

            ¹: http://www.vim.org/scripts/script.php?script_id=1218
            = https://github.com/scrooloose/nerdcommenter

            ²: See:
            :help mapleader

            ³: https://github.com/MarcWeber/vim-addon-manager

            --
            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
          • Jean-Michel Pichavant
            ... Hi, There are several way to do it. If you go to www.vim.org and search for comment line you ll end up with this page:
            Message 5 of 7 , Feb 8, 2012
              Алексей Данченков wrote:
              >
              > Hi!
              >
              > I just started diving into vi (and just subscribed to the mailing
              > list) and so far learned a basic moving around/editing commands. While
              > I am going through the basic book, is there a fast way to comment out
              > a paragraph with |-#| in the same column with the cursor position
              > (indenting the lines accordingly)?
              >
              > Let's say I have a piece of code:
              >
              > |%table
              > - unless paginate(@clients).nil?
              > %tr
              > %th
              > =t('index.name <http://index.name>')
              > %th
              > =t('index.address')
              > %th
              > =t('index.phone')
              > =render :partial => 'client', :collection => @clients
              > |
              >
              > and I want to comment out 9 lines (or a paragraph?) between |- unless|
              > and |=render :partial| with |-#| in one column like that...
              >
              > |%table
              >
              >
              > -# - unless paginate(@clients).nil?
              > -# %tr
              > -# %th
              > -# =t('index.name <http://index.name>')
              > -# %th
              > -# =t('index.address')
              > -# %th
              >
              > -# =t('index.phone')
              >
              > -# =render :partial => 'client', :collection => @clients
              > |
              >
              > ...and then be able to comment them in again. What command would that be?
              >
              > Cheers, Alexei
              >
              > --
              > 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

              Hi,

              There are several way to do it.

              If you go to www.vim.org and search for "comment line" you'll end up
              with this page:
              http://www.vim.org/scripts/script.php?script_id=1528
              You should be able to edit it and add any custom comments.

              If you don't want to install plugins, there are also tips on vim.org
              that may help you:
              http://vim.wikia.com/wiki/Commenting_out_a_range_of_lines

              Cheers,

              JM

              --
              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
            • Rich Healey
              I use tpope s commentary.vim, it s super short but does an awesome job. In this instance just select the lines and press -- You received this message from
              Message 6 of 7 , Feb 8, 2012
                I use tpope's commentary.vim, it's super short but does an awesome job.

                In this instance just select the lines and press \\

                --
                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
              • Алексей Данченков
                ... Thanks, everybody! I believe I better learn a few things without use of plugins as Ben recommends and once I am used to it and know more of vim, I d use
                Message 7 of 7 , Feb 9, 2012
                  > I just started diving into vi (and just subscribed to the mailing list) and
                  > so far learned a basic moving around/editing commands. While I am going
                  > through the basic book, is there a fast way to comment out a paragraph with
                  > -# in the same column with the cursor position (indenting the lines
                  > accordingly)?
                  >
                  > ...and then be able to comment them in again. What command would that be?
                  >

                  I believe there's some commenting plugins out there, but I've never
                  used them, so I cannot speak much on them.

                  The easiest way to insert the same text in the same position in a
                  range of lines, is to use blockwise-visual mode (often called "column
                  edit" or "column select" in other editors). To enter blockwise-visual
                  mode, press CTRL-V in normal mode. If CTRL-V pastes for you (or does
                  some other action instead of blockwise visual mode), you can instead
                  use CTRL-Q.

                  Once in blockwise visual mode, move the cursor to the last line you
                  want to insert text on. Depending on how your code is formatted, you
                  might be able to use } to hit the next blank line, use ap to select a
                  "paragraph" text object, use 'j' and 'k' repeatedly, use a search, or
                  any other way of moving the cursor. Vim has plenty of cursor motion
                  commands, and I've never coded in haml, so I'm not sure what ways to
                  move efficiently about haml code are best.

                  After you have all the lines selected, press I to insert text just
                  before the selection on all lines, or A to enter text just after. Type
                  the desired text, press <Esc>, and Vim will populate all lines with
                  your text.

                  That's a lot of explanation, but it should really only be a few
                  keystrokes. For example, if all goes well, you can type:

                  CTRL-V
                  }
                  I
                  -#
                  <Esc>

                  or

                  CTRL-V
                  9j
                  I
                  -#
                  <Esc>

                  The takeaway message is "use blockwise visual mode for inserting text
                  on lots of lines at once".

                  To uncomment, go into blockwise visual mode with CTRL-V, highlight all
                  the inserted comments, and press d to delete them.

                  Notes:
                  * I mentioned the "ap" text object previously, but this changes the
                  visual mode on you, so you'll need to force visual-block mode after
                  using. Something like:
                  v
                  ap
                  CTRL-V
                  I
                  -#
                  <Esc>
                  * It's much easier to use counts on j/k if you turn on the
                  'relativenumber' option, so you can use my "9j" suggestion without
                  actually counting lines

                  --
                  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

                  Thanks, everybody! I believe I better learn a few things without use of plugins as Ben recommends and once I am used to it and know more of vim, I'd use the NERD Commenter or commentary.vim as suggested.

                  Cheers, Alexei

                  --
                  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
                Your message has been successfully submitted and would be delivered to recipients shortly.