Eli the Bearded wrote:
> http://www.faqs.org/faqs/editor-faq/vi/part2/ > ------ start quote 8< ------ > 6.1 - Silly vi tricks > Note: Also check out the Silly macros down below. Many macros and > tricks are interchangeable. > > xp This will delete the character under the cursor, and put it > afterwards. In other words, it swaps the location of two characters. > > ddp Similar to xp, but swapping lines. > > yyp duplicate a line > > uu Undo and redo last change. (This will take you to the last > modification to the file without changing anything.) You can also use > this to compare the changes to a line. Make the changes to the line, > press U to undo the changes to the current line, and then press u to > toggle between the two versions. > > :g/.*/m0 > This will reverse the order of the lines in the current file. > m0 is the ex command to move the line to line 0. > > :v/./d or :g/^$/d > Removes all blank lines. > > :g/^[ <ctrl-v><tab>]*$/d > Removes all lines that only have whitespace. > > :v/./$s/$/<ctrl-v><enter>./|'';/./-1j|$d > Replaces multiple blank lines with just one blank line. > ------ >8 end quote ------ > > All of that works in vim (save "uu" with modern undo settings), except > for the last one. I happen to have true vi handy ("Version 4.0 (gritter) > 3/25/05"), as well as nvi ("Version (1.81.6-2013-11-20nb3)"), elvis > ("2.2.0"), vim 7.4, and vim 8.1. > > The replace multiple blank lines works in true vi and nvi, but not in > elvis or either vim. The trick works by the :v/./ selecting a group of > lines, $s editing the last line in that group to be a blank line and a > line with a dot, then |'' returning to the first line in the group, /./-1j > joining all but the last line of the group (so as not to join the new > dot line), and finally |$d deleting that last dot line. It's a > seriously complicated "trick", with lots of subtle compatibility tests > built right in. > > Is this a known incompatiblity in vim? I don't recall seeing it > documented. And I sought out that FAQ precisely for that trick since I > recalled it existed, but not what it was. AFAIK this builds upon a bug in Vi. In Nvi Keith Bostic decided to keep it like that (perhaps because of this example). I decided that it's really an unintentional bug and did not replicate it. Using "$" after :v does not refer to "the last in a a group", since :v works on a per-line base, it marks every line not matching the pattern. So in Vim the "$" refers to the last line, and changes that. There are much simpler ways to collapse multiple blank lines. -- hundred-and-one symptoms of being an internet addict: 122. You ask if the Netaholics Anonymous t-shirt you ordered can be sent to you via e-mail. /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- 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 because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
