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

Re: commenting out/in a paragraph (haml)

Expand Messages
  • Алексей Данченков
    ... 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 1 of 7 , Feb 9, 2012
    • 0 Attachment
      > 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.