Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of g key in vim normal mode

Tags:

vim

In vim's normal mode, the g prefix is used for a number of commands. Some commands go somewhere in the document, but other commands deal with file encodings and swapping upper/lower case letters.

  • ga - show character encoding
  • 10gg - go to line 10
  • gg - go to line 1
  • gH - start Select line mode
  • gr{char} - virtual replace N chars with {char}

What is the missing connection between all these commands?

like image 855
Natan Yellin Avatar asked Oct 03 '11 08:10

Natan Yellin


People also ask

What does the G key do in Vim?

gg will move you to the first line in the file, and G will move you to the last line in the file. Alternatively, if you type nG where n is a number, you'll jump to that to that line.

What is G in Vim editor?

g is a prefix to several commands. e.g. goto to move the cursor, but also gqip to format a paragraph.

How do I enter normal mode in Vim?

By default, Vim starts in “normal” mode. Normal mode can be accessed from other modes by pressing Esc or <C-[> .

What are the 4 navigation keys in vi?

We can prefix the repeat factor with navigation keys (h, j, k and l). Explanation: The repeat factor can be used as a command prefix with all these four commands.


2 Answers

There's no greater connection to g-commands: it's a mixed bunch. It is an easy prefix and the unbound keys were getting extinct so the less-used maps found a good place behind g.

like image 127
mike3996 Avatar answered Oct 01 '22 21:10

mike3996


Simply you're talking about two different things. In some cases g is the short way of "global" (for range command for example), for line moving the g stands for goto.

In VIM commands are often shortened for quick of use.

:help global may help

Btw: for line navigation I've always used the :<lineno> syntax.

like image 34
BigMike Avatar answered Oct 01 '22 21:10

BigMike