问题
As a beginner programmer I've been practicing vim on vimgolf recently and saw that the command "g?" was used effectively to switch many lines of 'Ivm' to become 'Vim'. I understand that this shifts each alphabetical letter 13 times to the right but do not understand how this would prove useful except in unique circumstances like these.
回答1:
The g?
command (type :help g?
for brief documentation) implements the rot13 algorithm, which rotates each letter 13 places forward or backward in the alphabet.
I'm not sure how commonly it's used today, but on Usenet it used to be a common way to encode spoilers. For example, if I'm writing a post that gives away the ending of something that not everyone has seen, I might use rot13
to weakly encrypt part of the article. It's enough to make it impossible to read accidentally (unless you've had a lot of practice), but easy to read if you're using a newsreader that has a built-in rot13
function -- as most of them do.
For example:
Pretend this is a spoiler. Filter with rot13 to read it.
would become
Cergraq guvf vf n fcbvyre. Svygre jvgu ebg13 gb ernq vg.
If I don't want to read the spoiler, I can ignore it. If I do want to read it, I can decrypt it easily enough.
回答2:
I have been using Vim since 4 years and learned about that command very early on but, even if I knew perfectly well what ROT13 was, I never found a use for g?
.
Until a couple of weeks ago when I needed to add a bunch of <li>
with unique IDs to a <ul>
in an HTML prototype…
The starting point:
<ul>
<li id="lorem">foo</li>
<li id="ipsum">foo</li>
</ul>
After duplicating the two <li>
:
<ul>
<li id="lorem">foo</li>
<li id="ipsum">foo</li>
<li id="lorem">foo</li>
<li id="ipsum">foo</li>
</ul>
After g?i"
on the two new <li>
's id
s:
<ul>
<li id="lorem">foo</li>
<li id="ipsum">foo</li>
<li id="yberz">foo</li>
<li id="vcfhz">foo</li>
</ul>
There! I found a practical use for g?
in actual "programming"! Celebration!!!
来源:https://stackoverflow.com/questions/25224741/what-functionality-does-the-g-command-provide-in-vim