planet earth

OK, this is more nerdy, but there are some not so used commands that are super useful all named g for Global or g for Go.


The :g command and it's reverse :v

This Global command is quicker than the typical :s/old/new/g instead the syntax is [range]g/pattern/cmd which is way more general. For for instance, if you wanted deleted all the lines with with world "hello" in it, you type :g/hello/d

And there is reVerse version so, :v/hello/d means delete all the lines with hello. You can also do this maybe more intuitively with :g!/pattern/d

The cool g command

The there is the Go command so you can do things like gx which means go to the hyperlink underneath, this was broken before on the Mac but works great as of September 2021, but there are bunch to them, more than I think I can remember and you do a :help *g* you will see all the current commands:

  • gf - go to the file name under the cursor
  • gm - go the column in the middle of the screen
  • gq{motion} - go format to the motion, so gq) means wrap lines to the end of the paragraph. You can also do gqq which is short for wrap the current line and for example gqj means wrap down to the next line
  • gu{motion}. Means make lower case (I know, u is lower), so guu means make the current line all lower case.
  • gd. If you loaded and you are in a program file, it will go to the definition of the word under the cursor. It's not really smart, it basically does an [[ which moves to the beginning of a section and then searches for the word from there.
  • gD. Like gd but starts the search at the top and looks for the first occurrence of the world (it assumes that this is a language where the function is defined before it's use).

So what the heck are the * and # commands

OK, there commands are really useful for editing html or programs. So, * means go to the next word that is the same as the word the cursor is on. If you are on the say an HTML tag like script then * will get you to the next script tag. and # will send you backwards.

Related Posts