Stories
Slash Boxes
Comments

SoylentNews is people

posted by chromas on Wednesday August 22 2018, @09:22PM   Printer-friendly
from the :wq dept.

Over at The New Stack is a brief but entertaining history of the editor vi and Vim.

"The editor was optimized so that you could edit and feel productive when it was painting slower than you could think. Now that computers are so much faster than you can think, nobody understands this anymore," Joy said. "It was a world that is now extinct. People don't know that vi was written for a world that doesn't exist anymore."


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by JoeMerchant on Wednesday August 22 2018, @11:21PM (15 children)

    by JoeMerchant (3937) on Wednesday August 22 2018, @11:21PM (#724933)

    So, what I'm talking about with column copy is more like:

    You've got a section of indented code you want to move back a level, in Brief: arrow to a corner of the rectangle of characters you want to erase, Alt-A to start the rectangle selection, arrow to the other corner, Alt-B (or whatever it was) to complete the rectangle selection, now you can Ctrl-X to cut it, and if you want that rectangle of text somewhere else - once it's on the paste buffer you can arrow to wherever and Ctrl-V to insert the rectangle of text at the column-row where you are - your rectangle is inserted below and to the right of your cursor, pushing all text appearing after the column you pasted into to the right for the number of rows in your rectangle. And, the part that column-operating editors ALL get wrong, but Brief got right is: the cursor jumps from your insertion point to the bottom left of the inserted rectangle. One (of many) good application for this is rapid indenting of a block of code: copy a rectangle of the desired width of spaces, then Ctrl-V repeatedly until you've reached the end of your block to indent - no arrow (or mouse) navigation required.

    There are lots of very cool things that can be done with rectangle manipulation like that. If you have a table of information, you can duplicate or remove columns very simply and easily.

    Obviously, it's not an essential function, I've lived without it for 25+ years, but when a good application for it comes along I still miss it. I think there is something similar in vi, but instead of the two-key commands to activate it, it's more like 4 or 5 - pretty much ruins the ride for me. The fun part is repeatedly hitting Ctrl-V and getting what you want without a whole bunch of complex manipulations to make it happen multiple times (and, if I could eyeball that the paragraph needs 28 lines indented, then I could probably include 28 in a vi command to make that happen, but I'm not the kind of guy who can count all the toothpicks that came out of a fumbled toothpick box before they hit the ground.)

    --
    🌻🌻 [google.com]
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 2) by Knowledge Troll on Wednesday August 22 2018, @11:38PM (6 children)

    by Knowledge Troll (5948) on Wednesday August 22 2018, @11:38PM (#724940) Homepage Journal

    If you want to do an operation like reduce the brace level of code you use a regex to rewrite the line as a string, like this: 10,20s/^ //

    that says from line 10 to 20 apply the regex that rewrites the first four spaces into nothing

    to do that on an entire file is like this: %s/^ //

    I don't know how to do an operation in columns spanning many lines but you can do operations involving a number of characters on one line fairly easily. There may be a technique for defining a box as you describe in vim - gvim (the gui version) I think will let you do it with the mouse but I don't really use it.

    • (Score: 2) by coolgopher on Thursday August 23 2018, @12:49AM

      by coolgopher (1157) on Thursday August 23 2018, @12:49AM (#724974)

      You can also use to increase indent.

      Indentation amount is controlled by the shift-width setting (e.g. sw=2).

    • (Score: 2) by JoeMerchant on Thursday August 23 2018, @01:45AM (2 children)

      by JoeMerchant (3937) on Thursday August 23 2018, @01:45AM (#725007)

      So, regex is very cool and all, but I'm not sure I want to invest the effort in learning a language that complex just so I can edit text marginally faster...

      --
      🌻🌻 [google.com]
      • (Score: 2) by Knowledge Troll on Thursday August 23 2018, @01:57AM (1 child)

        by Knowledge Troll (5948) on Thursday August 23 2018, @01:57AM (#725012) Homepage Journal

        *shrug* You asked, though I'm fluent in regex and use them in vi the least. Being fluent in regex is assumed with all professionals anywhere around me.

        • (Score: 2) by JoeMerchant on Thursday August 23 2018, @12:06PM

          by JoeMerchant (3937) on Thursday August 23 2018, @12:06PM (#725167)

          There's lots of ways to specialize, I accidentally ended up versed in design controls and FDA/ISO compliance - not a topic I would have chosen, but valuable nonetheless. Regex is optional around here, and even frowned upon unless it comes with comments fully specifying what it is intended to do, and not do, because most of our programmers can't regex to save their lives.

          --
          🌻🌻 [google.com]
    • (Score: 2) by tangomargarine on Thursday August 23 2018, @08:21PM (1 child)

      by tangomargarine (667) on Thursday August 23 2018, @08:21PM (#725386)

      If you want to do an operation like reduce the brace level of code you use a regex to rewrite the line as a string, like this: 10,20s/^ //

      that says from line 10 to 20 apply the regex that rewrites the first four spaces into nothing

      You have to invoke this 4 times though, right? I'm not seeing anything that does 4 on its own.

      s/^ //

      s/<find>/<replace>/
      ^ beginning of line
      So replace the first space in a selected line with empty string.

      --
      "Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
      • (Score: 2) by Knowledge Troll on Thursday August 23 2018, @09:05PM

        by Knowledge Troll (5948) on Thursday August 23 2018, @09:05PM (#725405) Homepage Journal

        Good catch! It needs <pre>around it but I don't think I can do that with the markup available. It just take 4 spaces in a row which HTML converted into a single rendered space.

  • (Score: 2) by jmorris on Thursday August 23 2018, @08:03AM (2 children)

    by jmorris (4844) on Thursday August 23 2018, @08:03AM (#725106)

    You should read the Vim help text about auto indent mode. Just highlight a block of code and let it fix the indenting for you. Better, if you are writing code in it with auto indent it knows the rules for the language and does what needs to be done. Type the closing } and it jumps back to where it is supposed to be, etc.

    Or to add a level of indent to a block, position on the first line of the block, do >i{ and yer done. You really need to explore what vim brings to the table.

    • (Score: 3, Insightful) by JoeMerchant on Thursday August 23 2018, @12:21PM

      by JoeMerchant (3937) on Thursday August 23 2018, @12:21PM (#725174)

      I've been around long enough to have used several different IDE editors, which have several different auto-indent functionalities (all broken by default, most not fixable), plus different editors with different indentation helping command sequences, again mostly unique in their implementation. There's a big value in training the muscle memory to do things that work everywhere, not just in your special flower environment. I learned this the "hard way" with AutoCad 14 - I programmed it all up with custom command shortcuts to improve my workflow, worked in that environment for 3 months, then went to the production shop to help the real thing get built. I was so completely and utterly lost on anybody else's AutoCad (that obviously lacked my custom command shortcuts) I often had to run back to my laptop just to make a simple edit - maybe more efficient overall, but not great in the shop.

      --
      🌻🌻 [google.com]
    • (Score: 2) by tangomargarine on Thursday August 23 2018, @06:28PM

      by tangomargarine (667) on Thursday August 23 2018, @06:28PM (#725328)

      You should read the Vim help text about auto indent mode. Just highlight a block of code and let it fix the indenting for you.

      C-M-\

      Better, if you are writing code in it with auto indent it knows the rules for the language and does what needs to be done. Type the closing } and it jumps back to where it is supposed to be, etc.

      Yep. Emacs has a plugin for auto-closing parens when you open them too, but I found it got in the way more often than it helped so I turned it off again.

      Forcing emacs to automatically indent by the appropriate amount (plus other syntactical sugar plugin stuff) in different languages was a right bastard, though. It's supposed to be a lot easier than the horrible hacks I kludged up to do it but I couldn't figure out how.

      --
      "Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
  • (Score: 0) by Anonymous Coward on Thursday August 23 2018, @03:03PM

    by Anonymous Coward on Thursday August 23 2018, @03:03PM (#725226)

    Vim has a similar function to what you describe. It probably doesn't exist in traditional vi.

    ctrl+v to enter visual block mode
    highlight the text you want to manipulate
    then you can use x to cut it
    or maybe maybe y to copy it
    and p to paste it somewhere else if you want.

    you can use I to insert text on every line (appearing to the left of the selected block), or A to append text on every line (appearing to the right of the selected block).

    This is the mechanism I personally use most often for adding/removing indentation levels in blocks of code.

  • (Score: 2) by tangomargarine on Thursday August 23 2018, @06:20PM (3 children)

    by tangomargarine (667) on Thursday August 23 2018, @06:20PM (#725324)

    You've got a section of indented code you want to move back a level

    C-u -4 C-x TAB

    The "C-u -4" is just telling it to perform the "indent by 1 space" operation negative four times, though.

    And, the part that column-operating editors ALL get wrong, but Brief got right is: the cursor jumps from your insertion point to the bottom left of the inserted rectangle.

    Yeah, for some reason the emacs default for inserting registers leaves the cursor at the beginning of it, too. Had to figure out how to change that setting.

    --
    "Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
    • (Score: 2) by JoeMerchant on Thursday August 23 2018, @07:55PM (2 children)

      by JoeMerchant (3937) on Thursday August 23 2018, @07:55PM (#725377)

      So, even if I could remember and easily execute C-u -4 C-x TAB, why would I want to?

      Cursor to one corner
      Alt-A
      Cursor to other corner (visual editing, horrors, but at least it's a character interface)
      Alt-B
      Ctrl-X

      Not only is it faster and simpler to execute, it's also something approaching intuitive.

      --
      🌻🌻 [google.com]
      • (Score: 2) by tangomargarine on Thursday August 23 2018, @08:16PM (1 child)

        by tangomargarine (667) on Thursday August 23 2018, @08:16PM (#725384)

        So, even if I could remember and easily execute C-u -4 C-x TAB, why would I want to?

        My point is just that this is something you can do with various editors. Which is better is subjective.

        Or if we want to literally do it your way using emacs rectangle mode, Ctrl+SPACE at beginning, arrow to select,* C-x r k, which is an exactly equal number of keys.

        C-x is the standard keychord before any sort of default macro, (R)ectangle (K)ill.

        *you don't have to do anything to denote the end of the selection

        it's also something approaching intuitive.

        Ha. Yeah, because anything involving rectangular selections is ever intuitive, sure.

        YMMV

        --
        "Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
        • (Score: 2) by JoeMerchant on Friday August 24 2018, @02:13AM

          by JoeMerchant (3937) on Friday August 24 2018, @02:13AM (#725550)

          I think if more editors had good rectangle selection implementations, that coding style conventions would be different than they are, more matrix oriented. It doesn't happen all the time, but many times I do find situations where organizing code into a 2D array on the editing screen both makes it more readable, and much more easily edited with rectangle selection manipulations.

          --
          🌻🌻 [google.com]