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.
- Stack Overflow What are the vim commands that start with g? g is a prefix to several commands. e.g. goto to move the cursor, but also gqip to format a paragraph. Where is the reference for all commands that are prefixed with g? They are exactly that, "commands that start with g".
:%s/pattern/replace/g is common, the following is nearly equivalent: :g/./s/pattern/replace/g (less common, but basically the with "substitute" command). "$ means "last line in the file"." is interesting to me because vim normally uses $ to represent the end of the line and G to represent the end of the file.
The ":" mode (e.g. ex-mode) commands in vi or vim have this form: Address can be a single line address (ex-mode operates on "lines"), or a line range. For instance, a very simple command in "p" which will print the addressed line (s).
Whenever it is used in combination with a motion it acts as itself: "delete between these parentheses", "delete from here to EOL", etc. On the other hand, g is nothing: not an operator, not a command, not a motion. It was just an empty slot that Vim's creator has been using for decades as a dumpster for new commands.
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!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With