Sunday, September 30, 2018

from the old vi faq

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.

Elijah
------
tends to use :g/^/m0 for reversing lines (even works in ed)

--
--
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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: