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

pulling text to the right?

Expand Messages
  • Lev Lvovsky
    I m sure there s a fancy word for this, but is there any way to pull text to the right? suppose I have the following: COL1 INT, COL2 INT, COL3 INT, I d
    Message 1 of 13 , Feb 26 4:30 PM
    • 0 Attachment
      I'm sure there's a fancy word for this, but is there any way to pull
      text to the right?

      suppose I have the following:

      COL1 INT,
      COL2 INT,
      COL3 INT,

      I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that,
      I need to put the cursor behind "COL3", hit space several times, and
      then align "INT" with the other "INTs". Can I put my cursor to the
      right of "COL3", and pull it over to "INT" on the right?

      thanks!
      -lev
    • A.J.Mechelynck
      ... With autoindent on, place the cursor at the end of the second line in Insert mode, hit to join the lines, then to break them again. The
      Message 2 of 13 , Feb 26 6:40 PM
      • 0 Attachment
        Lev Lvovsky wrote:
        > I'm sure there's a fancy word for this, but is there any way to pull
        > text to the right?
        >
        > suppose I have the following:
        >
        > COL1 INT,
        > COL2 INT,
        > COL3 INT,
        >
        > I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that, I
        > need to put the cursor behind "COL3", hit space several times, and then
        > align "INT" with the other "INTs". Can I put my cursor to the right of
        > "COL3", and pull it over to "INT" on the right?
        >
        > thanks!
        > -lev
        >

        With 'autoindent' on, place the cursor at the end of the second line in Insert
        mode, hit <Del> to join the lines, then <Enter> to break them again. The third
        line will align itself with the second one regardless of how many spaces are
        between the cursor and the first word (try it, you'll see). This won't align
        INT though, but there are several possible ways to do that after COL3 has been
        aligned. One of the fastest of these methods is to drag the mouse across all
        the spaces to be deleted to the left of INT in the third line, then hit <Del>.

        An alternative possibility would be to write an ad-hoc 'indentextpr' function,
        then reformat the whole file with gggqG -- but I wouldn't do that unless there
        were really many such "misindents" to correct.


        Best regards,
        Tony.
      • durgaprasad jammula
        Hi, If all the lines in a file only contains 2 words [column & int], you can even write a one line awk command to indent it. cat data.txt | awk {print
        Message 3 of 13 , Feb 26 11:15 PM
        • 0 Attachment
          Hi,

          If all the lines in a file only contains 2 words [column & int], you can even write a one line awk command to indent it.

          cat data.txt | awk '{print " "$1" "$2}' > indented_data.txt


          ----- Original Message ----
          From: A.J.Mechelynck <antoine.mechelynck@...>
          To: Lev Lvovsky <lists2@...>
          Cc: vim users list <vim@...>
          Sent: Tuesday, February 27, 2007 8:10:44 AM
          Subject: Re: pulling text to the right?

          Lev Lvovsky wrote:
          > I'm sure there's a fancy word for this, but is there any way to pull
          > text to the right?
          >
          > suppose I have the following:
          >
          > COL1 INT,
          > COL2 INT,
          > COL3 INT,
          >
          > I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that, I
          > need to put the cursor behind "COL3", hit space several times, and then
          > align "INT" with the other "INTs". Can I put my cursor to the right of
          > "COL3", and pull it over to "INT" on the right?
          >
          > thanks!
          > -lev
          >

          With 'autoindent' on, place the cursor at the end of the second line in Insert
          mode, hit <Del> to join the lines, then <Enter> to break them again. The third
          line will align itself with the second one regardless of how many spaces are
          between the cursor and the first word (try it, you'll see). This won't align
          INT though, but there are several possible ways to do that after COL3 has been
          aligned. One of the fastest of these methods is to drag the mouse across all
          the spaces to be deleted to the left of INT in the third line, then hit <Del>.

          An alternative possibility would be to write an ad-hoc 'indentextpr' function,
          then reformat the whole file with gggqG -- but I wouldn't do that unless there
          were really many such "misindents" to correct.


          Best regards,
          Tony.







          ____________________________________________________________________________________
          Need Mail bonding?
          Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
          http://answers.yahoo.com/dir/?link=list&sid=396546091
        • Matthew Winn
          On Mon, 26 Feb 2007 16:30:09 -0800, Lev Lvovsky ... I wouldn t bother with anything more than basic editing commands for a single change
          Message 4 of 13 , Feb 27 12:41 AM
          • 0 Attachment
            On Mon, 26 Feb 2007 16:30:09 -0800, Lev Lvovsky <lists2@...>
            wrote:

            > I'm sure there's a fancy word for this, but is there any way to pull
            > text to the right?
            >
            > suppose I have the following:
            >
            > COL1 INT,
            > COL2 INT,
            > COL3 INT,
            >
            > I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that,
            > I need to put the cursor behind "COL3", hit space several times, and
            > then align "INT" with the other "INTs". Can I put my cursor to the
            > right of "COL3", and pull it over to "INT" on the right?

            I wouldn't bother with anything more than basic editing commands for
            a single change like this. Just press I (to start inserting to the
            left of the COL3), type spaces until the column is aligned, then Esc
            kwwj (to put you in the right place for the INT) and dw (to remove the
            unwanted spaces).

            If you have tabs in the middle of the lines you may also need to press
            i and some more spaces because the dw may remove too much.

            Alternatively, this crude mapping will pull things over towards the
            cursor. It works by transferring one whitespace character from one
            side of the COL3 to the other:

            :map [whatever] :s/^\\(\\s*\\)\\(\\S.\\{-}\\)\\(\\s\\)\\(\\s*\\)\\%#/\\1\\3\\2\\4/<CR>``

            Debackslashed, that expression is:

            s/^\(\s*\)\(\S.\{-}\)\(\s\)\(\s*\)\%#/\1\3\2\4/

            That is, match the leading spaces (if any), one or more words,
            a single space, and then any additional spaces up to the cursor
            position, and replace them but moving the single space to just
            before the words.

            --
            Matthew Winn
          • Yakov Lerner
            ... Try in normal mode. :help , :help
            Message 5 of 13 , Feb 27 12:48 AM
            • 0 Attachment
              On 2/26/07, Lev Lvovsky <lists2@...> wrote:
              > I'm sure there's a fancy word for this, but is there any way to pull
              > text to the right?
              >
              > suppose I have the following:
              >
              > COL1 INT,
              > COL2 INT,
              > COL3 INT,
              >
              > I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that,
              > I need to put the cursor behind "COL3", hit space several times, and
              > then align "INT" with the other "INTs". Can I put my cursor to the
              > right of "COL3", and pull it over to "INT" on the right?

              Try >> in normal mode. :help >, :help <, :help 'shiftwidth'

              Yakov
            • cga2000
              ... I have this mapping in my ~/.vimrc that lets me enter spaces while ... So in the above example I would enter: G /* move cursor to last line - COL3 ..
              Message 6 of 13 , Feb 27 5:22 AM
              • 0 Attachment
                On Mon, Feb 26, 2007 at 07:30:09PM EST, Lev Lvovsky wrote:
                > I'm sure there's a fancy word for this, but is there any way to pull
                > text to the right?
                >
                > suppose I have the following:
                >
                > COL1 INT,
                > COL2 INT,
                > COL3 INT,
                >
                > I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that,
                > I need to put the cursor behind "COL3", hit space several times, and
                > then align "INT" with the other "INTs". Can I put my cursor to the
                > right of "COL3", and pull it over to "INT" on the right?

                I have this mapping in my ~/.vimrc that lets me enter spaces while
                remaining in "normal" mode:

                :nmap <space> i <esc>

                So in the above example I would enter:

                G /* move cursor to last line - COL3 .. */
                3<spacebar> /* move COL3 three columns to the right */
                e /* move the cursor to the '3' of COL3 */
                l /* move the cursor to the space after COL3 */
                3x /* delete three spaces to the right of COL3 */

                Sounds like a lot of work but all it really adds up to is seven
                easy keystrokes and the hands remain positioned on the home row.

                Compare with, for instance:

                <down-arrow><down-arrow><down-arrow>
                i
                <space><space><space>
                <escape>
                <right-arrow><right-arrow><right-arrow><right-arrow>
                <delete><delete><delete>

                .. fifteen keystrokes (and several moves to difficult-to reach keys)

                It's obviously not what you were looking for .. but once you get used to
                cursor movement commands that go beyond h,j,k,l (or worse .. arrow keys)
                it can be done quickly & effortlessly.

                I admit that fluency does require a few months of practice so it's
                really for you to decide whether it's worth the trouble.

                Thanks,
                cga
              • Charles E Campbell Jr
                ... It sounds like you re interested in aligning text. For that may I suggest looking into Align.vim (and AlignMaps.vim, which come together). To do the
                Message 7 of 13 , Feb 27 6:57 AM
                • 0 Attachment
                  Lev Lvovsky wrote:

                  > I'm sure there's a fancy word for this, but is there any way to pull
                  > text to the right?
                  >
                  > suppose I have the following:
                  >
                  > COL1 INT,
                  > COL2 INT,
                  > COL3 INT,
                  >
                  > I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that,
                  > I need to put the cursor behind "COL3", hit space several times, and
                  > then align "INT" with the other "INTs". Can I put my cursor to the
                  > right of "COL3", and pull it over to "INT" on the right?


                  It sounds like you're interested in aligning text. For that may I
                  suggest looking into Align.vim (and AlignMaps.vim, which come together).
                  To do the alignment, assuming that you're using spaces as delimiters:

                  at the upper right hand corner, type V
                  move cursor to bottom right hand corner.
                  type \tsp

                  If you're using tabs as delimiters, then use \tab instead of \tsp.

                  =====================================================


                  1. Get an up-to-date version of vimball and Align:

                  [vimball]
                  http://vim.sourceforge.net/scripts/script.php?script_id=1502
                  -or- http://mysite.verizon.net/astronaut/vim/index.html#VimBall
                  (the mysite.verizon.net one will be the more recent version)

                  [align]
                  http://mysite.verizon.net/astronaut/vim/index.html#ALIGN

                  2) Remove the old vimball plugin and install the new one:

                  Linux:
                  cd /usr/local/share/vim/vim70
                  /bin/rm plugin/vimball*.vim autoload/vimball*.vim doc/pi_vimball.txt
                  mv (wherever it was downloaded)/vimball.tar.gz .
                  gunzip vimball.tar.gz
                  tar -xvf vimball.tar

                  Windows:
                  Under Windows, check your runtimepath to determine where your
                  vim 7.0's runtime directories are:

                  vim
                  :echo &rtp
                  :q

                  The first directory is likely your personal plugins directory,
                  the second one is your vim system directory.

                  cd (to your vim system directory)
                  del plugin\vimballPlugin.vim
                  del autoload\vimball.vim
                  del doc\pi_vimball.txt
                  ren (wherever)\vimball.tar.gz vimball.tar.gz
                  gunzip vimball.tar.gz
                  tar -xvf vimball.tar

                  3) Install a new version of Align:
                  vim Align.vba.gz
                  :so %
                  :q
                • Kim Schulz
                  On Tue, 27 Feb 2007 09:57:55 -0500 ... I just tested it to see if I could get it to work, but I have some problems. I inserted the following int foo; uint8_t
                  Message 8 of 13 , Feb 27 1:17 PM
                  • 0 Attachment
                    On Tue, 27 Feb 2007 09:57:55 -0500
                    Charles E Campbell Jr <drchip@...> wrote:

                    > Lev Lvovsky wrote:
                    >
                    > > I'm sure there's a fancy word for this, but is there any way to
                    > > pull text to the right?
                    > >
                    > > suppose I have the following:
                    > >
                    > > COL1 INT,
                    > > COL2 INT,
                    > > COL3 INT,
                    > >
                    > > I'd like to get "COL3" aligned to "COL1" and "COL2", but to do
                    > > that, I need to put the cursor behind "COL3", hit space several
                    > > times, and then align "INT" with the other "INTs". Can I put my
                    > > cursor to the right of "COL3", and pull it over to "INT" on the
                    > > right?
                    >
                    >
                    > It sounds like you're interested in aligning text. For that may I
                    > suggest looking into Align.vim (and AlignMaps.vim, which come
                    > together). To do the alignment, assuming that you're using spaces as
                    > delimiters:
                    >
                    > at the upper right hand corner, type V
                    > move cursor to bottom right hand corner.
                    > type \tsp
                    >
                    > If you're using tabs as delimiters, then use \tab instead of \tsp.

                    I just tested it to see if I could get it to work, but I have some
                    problems.
                    I inserted the following
                    int foo;
                    uint8_t bar;
                    TIME baz;
                    int hello="world;

                    and then followed you instructions (used \tsp), but the result
                    afterwards is:
                    int foo;
                    uint8_t bar;
                    TIME baz;
                    int hello="world;




                    --
                    Kim Schulz | Private : http://www.schulz.dk
                    Kim@... | Business: http://www.devteam.dk
                    +45 5190 4262 | Sparetime: http://www.fundanemt.com
                  • Charles E Campbell Jr
                    ... What I got with your example: int foo; uint8_t bar; TIME baz; int hello= world; So everything lined up. Of course, when I used my mouse to pick
                    Message 9 of 13 , Feb 27 2:10 PM
                    • 0 Attachment
                      Kim Schulz wrote:

                      >I just tested it to see if I could get it to work, but I have some
                      >problems.
                      >I inserted the following
                      > int foo;
                      > uint8_t bar;
                      > TIME baz;
                      > int hello="world;
                      >
                      >and then followed you instructions (used \tsp), but the result
                      >afterwards is:
                      > int foo;
                      > uint8_t bar;
                      > TIME baz;
                      > int hello="world;
                      >
                      >
                      >
                      What I got with your example:

                      int foo;
                      uint8_t bar;
                      TIME baz;
                      int hello="world;

                      So everything lined up. Of course, when I used my mouse to pick up your
                      text, it was composed of all spaces. Does your original happen to have
                      a mixture of tabs and spaces?

                      Besides, this text is looking rather like a declaration set. There's a
                      map specifically supporting that:
                      \adec

                      Regards,
                      Chip Campbell
                    • Kim Schulz
                      On Tue, 27 Feb 2007 17:10:40 -0500 ... seems like the script wasn t loaded propertly. After restarting gvim, both tsp and adec worked (the latter one having
                      Message 10 of 13 , Feb 27 2:23 PM
                      • 0 Attachment
                        On Tue, 27 Feb 2007 17:10:40 -0500
                        Charles E Campbell Jr <drchip@...> wrote:

                        > So everything lined up. Of course, when I used my mouse to pick up
                        > your text, it was composed of all spaces. Does your original happen
                        > to have a mixture of tabs and spaces?
                        >
                        > Besides, this text is looking rather like a declaration set. There's
                        > a map specifically supporting that:
                        > \adec

                        seems like the script wasn't loaded propertly. After restarting gvim,
                        both \tsp and \adec worked (the latter one having the best result).
                        great script which I am sure I will get to use alot.

                        --
                        Kim Schulz | Private : http://www.schulz.dk
                        Kim@... | Business: http://www.devteam.dk
                        +45 5190 4262 | Sparetime: http://www.fundanemt.com
                      • Lev Lvovsky
                        Thank you for everyone s help so far (reply below) ... That sort of does what I want, but it ends up moving the INT right along with it. I guess what I m
                        Message 11 of 13 , Feb 28 12:55 PM
                        • 0 Attachment
                          Thank you for everyone's help so far (reply below)

                          On Feb 27, 2007, at 12:48 AM, Yakov Lerner wrote:

                          > On 2/26/07, Lev Lvovsky <lists2@...> wrote:
                          >> I'm sure there's a fancy word for this, but is there any way to pull
                          >> text to the right?
                          >>
                          >> suppose I have the following:
                          >>
                          >> COL1 INT,
                          >> COL2 INT,
                          >> COL3 INT,
                          >>
                          >> I'd like to get "COL3" aligned to "COL1" and "COL2", but to do that,
                          >> I need to put the cursor behind "COL3", hit space several times, and
                          >> then align "INT" with the other "INTs". Can I put my cursor to the
                          >> right of "COL3", and pull it over to "INT" on the right?
                          >
                          > Try >> in normal mode. :help >, :help <, :help 'shiftwidth'

                          That sort of does what I want, but it ends up moving the "INT" right
                          along with it. I guess what I'm looking for is a combination of key
                          strokes:

                          COL1 INT,
                          COL2 INT,
                          COL3 INT,
                          ^

                          I put my cursor at the column of the '^', on line 3 and press that
                          keystroke, which would simultaneously go to the beginning of the
                          line, <space>, go back to the '^', and '<x>' from that position, to
                          bring the "INT" back a space.

                          The real goal of this formatting is to create text that looks like this:

                          SOME_COL VARCHAR(32),
                          SOME_COL12 INT,
                          BLAH_BLAH1 BOOL,

                          I would suppose that this can be made with a vim function right? Any
                          good tutorials on them?

                          thank you!
                          -lev
                        • Matthew Winn
                          On Wed, 28 Feb 2007 12:55:23 -0800, Lev Lvovsky ... I d think it was likely, given that two days ago I posted a mapping that does exactly
                          Message 12 of 13 , Mar 1, 2007
                          • 0 Attachment
                            On Wed, 28 Feb 2007 12:55:23 -0800, Lev Lvovsky <lists2@...>
                            wrote:

                            > That sort of does what I want, but it ends up moving the "INT" right
                            > along with it. I guess what I'm looking for is a combination of key
                            > strokes:
                            >
                            > COL1 INT,
                            > COL2 INT,
                            > COL3 INT,
                            > ^
                            >
                            > I put my cursor at the column of the '^', on line 3 and press that
                            > keystroke, which would simultaneously go to the beginning of the
                            > line, <space>, go back to the '^', and '<x>' from that position, to
                            > bring the "INT" back a space.
                            >
                            > The real goal of this formatting is to create text that looks like this:
                            >
                            > SOME_COL VARCHAR(32),
                            > SOME_COL12 INT,
                            > BLAH_BLAH1 BOOL,
                            >
                            > I would suppose that this can be made with a vim function right?

                            I'd think it was likely, given that two days ago I posted a mapping
                            that does exactly that. In fact you can do it exactly as you describe
                            above by mapping something to "maI <Esc>`ax". (Unlike my first try,
                            this one won't stop when it runs out of spaces under the cursor.)

                            --
                            Matthew Winn
                          • Lev Lvovsky
                            ... All s I have to say in RE to Align.vim is: Wow . thanks Charles! -lev
                            Message 13 of 13 , Mar 1, 2007
                            • 0 Attachment
                              On Feb 27, 2007, at 6:57 AM, Charles E Campbell Jr wrote:

                              > Lev Lvovsky wrote:
                              >
                              >> I'm sure there's a fancy word for this, but is there any way to
                              >> pull text to the right?
                              >>
                              >> suppose I have the following:
                              >>
                              >> COL1 INT,
                              >> COL2 INT,
                              >> COL3 INT,
                              >>
                              >> I'd like to get "COL3" aligned to "COL1" and "COL2", but to do
                              >> that, I need to put the cursor behind "COL3", hit space several
                              >> times, and then align "INT" with the other "INTs". Can I put my
                              >> cursor to the right of "COL3", and pull it over to "INT" on the
                              >> right?
                              >
                              >
                              > It sounds like you're interested in aligning text. For that may I
                              > suggest looking into Align.vim (and AlignMaps.vim, which come
                              > together).
                              > To do the alignment, assuming that you're using spaces as delimiters:

                              All's I have to say in RE to Align.vim is:

                              "Wow".

                              thanks Charles!

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