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

Moving text

Expand Messages
  • Jeff Lanzarotta
    Hello, Is there a simple way to move text on the currently line to a specific column on the same line? For example if the text on the current line started in
    Message 1 of 12 , Jul 1 12:45 PM
    • 0 Attachment
      Hello,

      Is there a simple way to move text on the currently line to a specific column on the same line? For example if the text on the current line started in column 10 and I wanted to move it to column 20, it there a way to do that?

      Thanks,

      Jeff

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---

    • Tim Chase
      ... A couple of answers to some questions would help lead towards a solution: - what fills the space? just spaces? - if you re in the middle of something such
      Message 2 of 12 , Jul 1 12:57 PM
      • 0 Attachment
        > Is there a simple way to move text on the currently line to a
        > specific column on the same line? For example if the text on
        > the current line started in column 10 and I wanted to move it
        > to column 20, it there a way to do that?


        A couple of answers to some questions would help lead towards a
        solution:

        - what fills the space? just spaces?

        - if you're in the middle of something such as

        int xi;

        and the cursor is on the "x", do you want the whole thing
        indented to the given position, or do you only want the stuff
        from the cursor to move to the given position?

        - how do you determine the destination position? is it always
        column 20? something you'd set for a time period but change
        while editing the same document? is it aligned with something else?

        You may also be interested in Dr. Chip's align.vim script

        http://www.vim.org/scripts/script.php?script_id=294

        It may do what you want, but if not, the answers to the questions
        above may help folks make a mapping to do what you describe.

        -tim



        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Charles E Campbell Jr
        ... 1. a) goto column 10: 10| b) insert ten spaces: 10i 2. Use DrawIt: (http://mysite.verizon.net/astronaut/vim/index.html#DRAWIT) a) Enable
        Message 3 of 12 , Jul 1 1:07 PM
        • 0 Attachment
          Jeff Lanzarotta wrote:
          > Hello,
          >
          > Is there a simple way to move text on the currently line to a specific
          > column on the same line? For example if the text on the current line
          > started in column 10 and I wanted to move it to column 20, it there a
          > way to do that?
          1. a) goto column 10: 10|
          b) insert ten spaces: 10i <esc>

          2. Use DrawIt: (http://mysite.verizon.net/astronaut/vim/index.html#DRAWIT)
          a) Enable DrawIt: \di
          b) use leftmouse to select text
          c) release leftmouse button
          d) use ctrl-leftmouse and move text wherever

          This approach will work with visual blocks, so its not restricted to
          just text on a line.

          3. As Tim C said, if your purpose is aligning text in columns, Align.vim
          may be what you want

          Regards,
          Chip Campbell


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Gene Kwiecinski
          ... Absolutely, but there also be so many variables and so many ways to do such a thing, that it s best if you just demonstrate a before n after as to what you
          Message 4 of 12 , Jul 1 1:14 PM
          • 0 Attachment
            >Is there a simple way to move text on the currently line to
            >a specific column on the same line? For example if the text
            >on the current line started in column 10 and I wanted to
            >move it to column 20, it there a way to do that?

            Absolutely, but there also be so many variables and so many ways to do
            such a thing, that it's best if you just demonstrate a before'n'after as
            to what you want.

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Jeff Lanzarotta
            Sorry about not explaining myself better. I am looking at moving comment lines over to column 41. This number is not set in stone, so I would to be able to
            Message 5 of 12 , Jul 1 2:32 PM
            • 0 Attachment
              Sorry about not explaining myself better.

              I am looking at moving comment lines over to column 41. This number is
              not set in stone, so I would to be able to change it. The space would
              be filled with with spaces. As for being able to move the line while
              the cursor in somewhere inside the line. That would be a great
              benefit, but not necessary.

              I hope that is a little better.

              On Jul 1, 3:45 pm, Jeff Lanzarotta <delux256-...@...> wrote:
              > Hello,
              >
              > Is there a simple way to move text on the currently line to a specific column on the same line? For example if the text on the current line started in column 10 and I wanted to move it to column 20, it there a way to do that?
              >
              > Thanks,
              >
              > Jeff
              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Gene Kwiecinski
              ... Still not quite clear... Is there anything else on the line beside the comment itself? Is it just a matter of reindenting them farther to the right? Etc.
              Message 6 of 12 , Jul 1 3:41 PM
              • 0 Attachment
                >I am looking at moving comment lines over to column 41. This number is
                >not set in stone, so I would to be able to change it. The space would
                >be filled with with spaces. As for being able to move the line while
                >the cursor in somewhere inside the line. That would be a great
                >benefit, but not necessary.

                Still not quite clear...

                Is there anything else on the line beside the comment itself? Is it
                just a matter of reindenting them farther to the right? Etc. Again,
                before and after lines of what you want.

                Easiest for me would be to just highlight the begin-comment chars, and
                insert the appropriate number of tabs, eg,

                # comment 1
                # comment 2
                # comment 3

                go to the top '#', <^V> for visual, <down><down> to highlight all 3
                '#'s, <I><tab><tab> to push them over 2 tabstops (typically 16 columns),
                and you're done.

                Eh, whatever...

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Tony Mechelynck
                ... For one line, like Dr.Chip said: 1. In Normal mode, place the cursor on the first character to be moved (let s say the first slash in the // of the
                Message 7 of 12 , Jul 1 3:56 PM
                • 0 Attachment
                  On 01/07/08 23:32, Jeff Lanzarotta wrote:
                  > Sorry about not explaining myself better.
                  >
                  > I am looking at moving comment lines over to column 41. This number is
                  > not set in stone, so I would to be able to change it. The space would
                  > be filled with with spaces. As for being able to move the line while
                  > the cursor in somewhere inside the line. That would be a great
                  > benefit, but not necessary.
                  >
                  > I hope that is a little better.
                  >
                  > On Jul 1, 3:45 pm, Jeff Lanzarotta<delux256-...@...> wrote:
                  >> Hello,
                  >>
                  >> Is there a simple way to move text on the currently line to a specific column on the same line? For example if the text on the current line started in column 10 and I wanted to move it to column 20, it there a way to do that?
                  >>
                  >> Thanks,
                  >>
                  >> Jeff

                  For one line, like Dr.Chip said:
                  1. In Normal mode, place the cursor on the first character to be moved
                  (let's say the first slash in the // of the C++-like comment). The
                  statusline tells you in which column you are.
                  2. Do some mental arithmetic: subtract the column where you are from the
                  column (41) where you want to go. Let's say you are in column 27, the
                  difference (41 - 27) is 14.
                  3.
                  14i <Esc>
                  where 14 is the result of the substraction and <Esc> means "Hit Escape".
                  Between hitting i and Esc, hit the space bar exactly once.

                  For several lines, all starting in the same column:
                  1. In Normal mode, place the cursor on the first character-to-be-moived
                  of the first (or last) line of the block.
                  2. Look on the statusline, see in which column you are.
                  3. Mental arithmetic as in 2 above. Remember the result.
                  4. Hit Ctrl-V to start Blockwise Visual mode.
                  5. Move the cursor to the last (or first) line, then hit $ -- all the
                  text to be moved is now highlighted
                  6. This time, use a capital I to move the block: if you are in column 11
                  (30 spaces required):
                  30I <Esc>
                  with space and <Esc> as in 3 of "For one line" above.

                  If you want to move the first // (in any line where there is one) to
                  column 41, then you'll need to write a function to do it for one line,
                  then ":call" that function from a ":g" command on every matching line:
                  :%g/\/\//call MoveComment('//',41)

                  where the function might be (untested)

                  " move the 'text' (and everything after it) to column 'col'
                  " in the current line, by adding spaces
                  function MoveComment(text,col)
                  " find the column with the text
                  let index = stridx(getline('.'), a:text) + 1
                  " if not found or too far, don't move
                  if index = 0 || index >= a:col
                  return 0
                  endif
                  " by how many must we shift ?
                  let shift = a:col - index
                  " OK, let's do it
                  exe "norm" shift . "i \e"
                  return shift
                  endfunction

                  The above does not handle the case where // might be other than a
                  comment leader (e.g., part of a quoted string).


                  Best regards,
                  Tony.
                  --
                  As a professional humorist, I often get letters from readers who are
                  interested in the basic nature of humor. "What kind of a sick
                  perverted disgusting person are you," these letters typically ask,
                  "that you make jokes about setting fire to a goat?" ...
                  -- Dave Barry, "Why Humor is Funny"

                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Ben Schmidt
                  ... Perhaps you just want these commands which nobody seems to have mentioned yet. ... possibly with ... to use spaces only. ... Ben. ...
                  Message 8 of 12 , Jul 1 6:48 PM
                  • 0 Attachment
                    Jeff Lanzarotta wrote:
                    > Sorry about not explaining myself better.
                    >
                    > I am looking at moving comment lines over to column 41. This number is
                    > not set in stone, so I would to be able to change it. The space would
                    > be filled with with spaces. As for being able to move the line while
                    > the cursor in somewhere inside the line. That would be a great
                    > benefit, but not necessary.
                    >
                    > I hope that is a little better.

                    Perhaps you just want these commands which nobody seems to have
                    mentioned yet.

                    :left 41

                    possibly with

                    :set expandtab

                    to use spaces only.

                    :help :left
                    :help 'expandtab'

                    Ben.



                    > On Jul 1, 3:45 pm, Jeff Lanzarotta <delux256-...@...> wrote:
                    >> Hello,
                    >>
                    >> Is there a simple way to move text on the currently line to a specific column on the same line? For example if the text on the current line started in column 10 and I wanted to move it to column 20, it there a way to do that?
                    >>
                    >> Thanks,
                    >>
                    >> Jeff
                    > >
                    >

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • Bill McCarthy
                    ... That makes it fairly easy - just moving all comment lines. Suppose a comment starts with # : function! DoCR(n) let sw=&shiftwidth exe set sw= . a:n sil
                    Message 9 of 12 , Jul 1 6:53 PM
                    • 0 Attachment
                      On Tue 1-Jul-08 4:32pm -0600, Jeff Lanzarotta wrote:
                      >
                      > Sorry about not explaining myself better.
                      >
                      > I am looking at moving comment lines over to column 41. This number is
                      > not set in stone, so I would to be able to change it. The space would
                      > be filled with with spaces. As for being able to move the line while
                      > the cursor in somewhere inside the line. That would be a great
                      > benefit, but not necessary.
                      >
                      > I hope that is a little better.

                      That makes it fairly easy - just moving all comment lines.

                      Suppose a comment starts with '#':

                      function! DoCR(n)
                      let sw=&shiftwidth
                      exe "set sw=" . a:n
                      sil %s/\s\+\ze#//e
                      sil g/^#/>
                      exe "set shiftwidth=" . sw
                      endfunction
                      command! -count=40 CR call DoCR(<count>)

                      To move them over 40 characters: :CR
                      To move them over 10 characters: :CR 10
                      --
                      Best regards,
                      Bill


                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • Bill McCarthy
                      ... That s a new command to me - thanks Ben. To have comments, ... -- Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ You received
                      Message 10 of 12 , Jul 1 7:00 PM
                      • 0 Attachment
                        On Tue 1-Jul-08 8:48pm -0600, Ben Schmidt wrote:

                        > Perhaps you just want these commands which nobody seems to have
                        > mentioned yet.
                        >
                        > :left 41

                        That's a new command to me - thanks Ben. To have comments,
                        beginning with '#', start at column 40:

                        :g/\s*#/le 40

                        --
                        Best regards,
                        Bill


                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_use" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      • Charles E Campbell Jr
                        ... If there s code on the left and comments on the right -- well, I d use Align and AlignMap s acom map: V ..move acom and the comments would all be aligned
                        Message 11 of 12 , Jul 2 7:10 AM
                        • 0 Attachment
                          Gene Kwiecinski wrote:
                          >> I am looking at moving comment lines over to column 41. This number is
                          >> not set in stone, so I would to be able to change it. The space would
                          >> be filled with with spaces. As for being able to move the line while
                          >> the cursor in somewhere inside the line. That would be a great
                          >> benefit, but not necessary.
                          >>
                          If there's code on the left and comments on the right -- well, I'd use
                          Align and AlignMap's \acom map:

                          V
                          ..move
                          \acom

                          and the comments would all be aligned to the right of the code. If I
                          wanted more space, then I'd use ctrl-v to select a one-space wide column
                          and use p repeatedly to get it where I wanted it (just hold the p key
                          down and hit u a few times to back up as necessary).

                          If you don't have code to the comment's left, well, I rather like Ben
                          Schmidt's solution to use the :left command.

                          Regards,
                          Chip Campbell


                          --~--~---------~--~----~------------~-------~--~----~
                          You received this message from the "vim_use" maillist.
                          For more information, visit http://www.vim.org/maillist.php
                          -~----------~----~----~----~------~----~------~--~---
                        • sc
                          ... are you looking for ... that works for me anyway sc --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use
                          Message 12 of 12 , Jul 4 1:37 PM
                          • 0 Attachment
                            On Tuesday 01 July 2008 14:45, Jeff Lanzarotta wrote:
                            > Hello,
                            >
                            > Is there a simple way to move text on the currently line to a specific column on the same line? For example if the text on the current line started in column 10 and I wanted to move it to column 20, it there a way to do that?
                            >
                            > Thanks,
                            >
                            > Jeff

                            are you looking for

                            :left 19

                            that works for me anyway

                            sc



                            --~--~---------~--~----~------------~-------~--~----~
                            You received this message from the "vim_use" maillist.
                            For more information, visit http://www.vim.org/maillist.php
                            -~----------~----~----~----~------~----~------~--~---
                          Your message has been successfully submitted and would be delivered to recipients shortly.