What is the meaning of 'g'?












1















Note: this question has two sort of answers on StackOverflow but I thought perhaps a better answer would come from here, and, if not, at least it will be documented where it should be:




  • What are the vim commands that start with g?

  • Use of g key in vim normal mode




What is the semantic meaning of the letter g in normal mode commands? I have used the heck out of gg, G, and <n>G, but until today, I hadn't ever thought to find out what the semantics of g are in the larger Zen of Vi.



Today I had to lowercase a bunch of constants in my code, and I figured there had to be a better way than character by character (since <n>~ doesn't work, for whatever odd reason that I am unaware of). I found it in g~<n> and g~iw.



This lead me to find the linked answers, but they have less than satisfying explanations, and are on stackoverflow, and not vi.SE, to boot.



So,



What is the vi-semantic meaning of g?



By vi-semantic meaning, I expect people to understand, as in ciw means change in word, so c means change, i, means inner text item, and w means word delineated by space or punctuation excluding _.



P.S., how do I tag this?










share|improve this question





























    1















    Note: this question has two sort of answers on StackOverflow but I thought perhaps a better answer would come from here, and, if not, at least it will be documented where it should be:




    • What are the vim commands that start with g?

    • Use of g key in vim normal mode




    What is the semantic meaning of the letter g in normal mode commands? I have used the heck out of gg, G, and <n>G, but until today, I hadn't ever thought to find out what the semantics of g are in the larger Zen of Vi.



    Today I had to lowercase a bunch of constants in my code, and I figured there had to be a better way than character by character (since <n>~ doesn't work, for whatever odd reason that I am unaware of). I found it in g~<n> and g~iw.



    This lead me to find the linked answers, but they have less than satisfying explanations, and are on stackoverflow, and not vi.SE, to boot.



    So,



    What is the vi-semantic meaning of g?



    By vi-semantic meaning, I expect people to understand, as in ciw means change in word, so c means change, i, means inner text item, and w means word delineated by space or punctuation excluding _.



    P.S., how do I tag this?










    share|improve this question



























      1












      1








      1








      Note: this question has two sort of answers on StackOverflow but I thought perhaps a better answer would come from here, and, if not, at least it will be documented where it should be:




      • What are the vim commands that start with g?

      • Use of g key in vim normal mode




      What is the semantic meaning of the letter g in normal mode commands? I have used the heck out of gg, G, and <n>G, but until today, I hadn't ever thought to find out what the semantics of g are in the larger Zen of Vi.



      Today I had to lowercase a bunch of constants in my code, and I figured there had to be a better way than character by character (since <n>~ doesn't work, for whatever odd reason that I am unaware of). I found it in g~<n> and g~iw.



      This lead me to find the linked answers, but they have less than satisfying explanations, and are on stackoverflow, and not vi.SE, to boot.



      So,



      What is the vi-semantic meaning of g?



      By vi-semantic meaning, I expect people to understand, as in ciw means change in word, so c means change, i, means inner text item, and w means word delineated by space or punctuation excluding _.



      P.S., how do I tag this?










      share|improve this question
















      Note: this question has two sort of answers on StackOverflow but I thought perhaps a better answer would come from here, and, if not, at least it will be documented where it should be:




      • What are the vim commands that start with g?

      • Use of g key in vim normal mode




      What is the semantic meaning of the letter g in normal mode commands? I have used the heck out of gg, G, and <n>G, but until today, I hadn't ever thought to find out what the semantics of g are in the larger Zen of Vi.



      Today I had to lowercase a bunch of constants in my code, and I figured there had to be a better way than character by character (since <n>~ doesn't work, for whatever odd reason that I am unaware of). I found it in g~<n> and g~iw.



      This lead me to find the linked answers, but they have less than satisfying explanations, and are on stackoverflow, and not vi.SE, to boot.



      So,



      What is the vi-semantic meaning of g?



      By vi-semantic meaning, I expect people to understand, as in ciw means change in word, so c means change, i, means inner text item, and w means word delineated by space or punctuation excluding _.



      P.S., how do I tag this?







      normal-mode






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago







      malan

















      asked 2 hours ago









      malanmalan

      1855




      1855






















          1 Answer
          1






          active

          oldest

          votes


















          3














          g is a little bit of a weird key in vim. A lot of other keys have a specific word to describe their category:




          • h, j, k, l, }, {, w, e, etc. are all motions. They tell your cursor to move.


          • d, c, y, etc. are all operators. They change the text they operate on in a specific way, and you tell them what text to operate on by giving a motion.



          g does not have a name like this. If I had to come up with a name, I would call it a leader. Here's a random example. Let's say you wanted a shortcut that removes every space from the current line. That's not too hard to do:



          :s/ //g<cr>


          But what do you map it to? How about d for delete spaces? Well... no, d already has a meaning. How about s for space? Well... no, s already has a meaning too. In fact, basically every single key you could think of has a meaning. So what do you map it to? Vim has something called a leader key, which means you pick a key ( by default, although <space> and , are common alternatives), and then use it in all your mappings. For example, you could say:



          nnoremap <leader>s :s/ //g<cr>


          and map it to <leader>s, whatever you choose leader to be. This is extremely useful, because now you have another 95 two-key sequences you could map to that are guaranteed to not overwrite anything else. You can come up with the shortcuts you find useful and don't have to worry about removing vim's default functionality.



          g works in a very similar way. Bram Moolenaar and Bill Joy I'm sure had many useful operations (such as go the beginning/end of the file, or go to [line]) that make sense to create a shortcut for in default vim, but they're not going to be used often enough to justify giving them a one-key shortcut, since these are reserved for the more useful/frequently used things like hjkl, or d and p. There are tons of keyboard shortcuts that all start with g. What do they have in common? Absolutely nothing. They just happen to be useful things to have that aren't worth giving a one-key shortcut for.



          So really, gg is a motion just like all the other motions I listed, it just happens to use a two-key sequence. g~ is an operator just like all the other operators I listed, it just happens to use a two-key sequence.



          There are several other "leader" like keys in vim. For example, look up in help





          • :h z (Commands that start with 'z')


          • :h [ (Commands that start with '[')


          • :h ctrl-w (Commands that start with <C-w>)






          share|improve this answer
























          • So g is like a system leader, as opposed to a user leader. Just have to memorize the combos. Thank you.

            – malan
            1 hour ago








          • 2





            g and z and really like namespaces for the next character. That's because we have been slowly running out of keys on a keyboard, so commands that are useful, had been added to those keys

            – Christian Brabandt
            1 hour ago











          • @ChristianBrabandt Yes, namespace is a great word for that.

            – DJMcMayhem
            1 hour ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "599"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f18744%2fwhat-is-the-meaning-of-g%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          g is a little bit of a weird key in vim. A lot of other keys have a specific word to describe their category:




          • h, j, k, l, }, {, w, e, etc. are all motions. They tell your cursor to move.


          • d, c, y, etc. are all operators. They change the text they operate on in a specific way, and you tell them what text to operate on by giving a motion.



          g does not have a name like this. If I had to come up with a name, I would call it a leader. Here's a random example. Let's say you wanted a shortcut that removes every space from the current line. That's not too hard to do:



          :s/ //g<cr>


          But what do you map it to? How about d for delete spaces? Well... no, d already has a meaning. How about s for space? Well... no, s already has a meaning too. In fact, basically every single key you could think of has a meaning. So what do you map it to? Vim has something called a leader key, which means you pick a key ( by default, although <space> and , are common alternatives), and then use it in all your mappings. For example, you could say:



          nnoremap <leader>s :s/ //g<cr>


          and map it to <leader>s, whatever you choose leader to be. This is extremely useful, because now you have another 95 two-key sequences you could map to that are guaranteed to not overwrite anything else. You can come up with the shortcuts you find useful and don't have to worry about removing vim's default functionality.



          g works in a very similar way. Bram Moolenaar and Bill Joy I'm sure had many useful operations (such as go the beginning/end of the file, or go to [line]) that make sense to create a shortcut for in default vim, but they're not going to be used often enough to justify giving them a one-key shortcut, since these are reserved for the more useful/frequently used things like hjkl, or d and p. There are tons of keyboard shortcuts that all start with g. What do they have in common? Absolutely nothing. They just happen to be useful things to have that aren't worth giving a one-key shortcut for.



          So really, gg is a motion just like all the other motions I listed, it just happens to use a two-key sequence. g~ is an operator just like all the other operators I listed, it just happens to use a two-key sequence.



          There are several other "leader" like keys in vim. For example, look up in help





          • :h z (Commands that start with 'z')


          • :h [ (Commands that start with '[')


          • :h ctrl-w (Commands that start with <C-w>)






          share|improve this answer
























          • So g is like a system leader, as opposed to a user leader. Just have to memorize the combos. Thank you.

            – malan
            1 hour ago








          • 2





            g and z and really like namespaces for the next character. That's because we have been slowly running out of keys on a keyboard, so commands that are useful, had been added to those keys

            – Christian Brabandt
            1 hour ago











          • @ChristianBrabandt Yes, namespace is a great word for that.

            – DJMcMayhem
            1 hour ago
















          3














          g is a little bit of a weird key in vim. A lot of other keys have a specific word to describe their category:




          • h, j, k, l, }, {, w, e, etc. are all motions. They tell your cursor to move.


          • d, c, y, etc. are all operators. They change the text they operate on in a specific way, and you tell them what text to operate on by giving a motion.



          g does not have a name like this. If I had to come up with a name, I would call it a leader. Here's a random example. Let's say you wanted a shortcut that removes every space from the current line. That's not too hard to do:



          :s/ //g<cr>


          But what do you map it to? How about d for delete spaces? Well... no, d already has a meaning. How about s for space? Well... no, s already has a meaning too. In fact, basically every single key you could think of has a meaning. So what do you map it to? Vim has something called a leader key, which means you pick a key ( by default, although <space> and , are common alternatives), and then use it in all your mappings. For example, you could say:



          nnoremap <leader>s :s/ //g<cr>


          and map it to <leader>s, whatever you choose leader to be. This is extremely useful, because now you have another 95 two-key sequences you could map to that are guaranteed to not overwrite anything else. You can come up with the shortcuts you find useful and don't have to worry about removing vim's default functionality.



          g works in a very similar way. Bram Moolenaar and Bill Joy I'm sure had many useful operations (such as go the beginning/end of the file, or go to [line]) that make sense to create a shortcut for in default vim, but they're not going to be used often enough to justify giving them a one-key shortcut, since these are reserved for the more useful/frequently used things like hjkl, or d and p. There are tons of keyboard shortcuts that all start with g. What do they have in common? Absolutely nothing. They just happen to be useful things to have that aren't worth giving a one-key shortcut for.



          So really, gg is a motion just like all the other motions I listed, it just happens to use a two-key sequence. g~ is an operator just like all the other operators I listed, it just happens to use a two-key sequence.



          There are several other "leader" like keys in vim. For example, look up in help





          • :h z (Commands that start with 'z')


          • :h [ (Commands that start with '[')


          • :h ctrl-w (Commands that start with <C-w>)






          share|improve this answer
























          • So g is like a system leader, as opposed to a user leader. Just have to memorize the combos. Thank you.

            – malan
            1 hour ago








          • 2





            g and z and really like namespaces for the next character. That's because we have been slowly running out of keys on a keyboard, so commands that are useful, had been added to those keys

            – Christian Brabandt
            1 hour ago











          • @ChristianBrabandt Yes, namespace is a great word for that.

            – DJMcMayhem
            1 hour ago














          3












          3








          3







          g is a little bit of a weird key in vim. A lot of other keys have a specific word to describe their category:




          • h, j, k, l, }, {, w, e, etc. are all motions. They tell your cursor to move.


          • d, c, y, etc. are all operators. They change the text they operate on in a specific way, and you tell them what text to operate on by giving a motion.



          g does not have a name like this. If I had to come up with a name, I would call it a leader. Here's a random example. Let's say you wanted a shortcut that removes every space from the current line. That's not too hard to do:



          :s/ //g<cr>


          But what do you map it to? How about d for delete spaces? Well... no, d already has a meaning. How about s for space? Well... no, s already has a meaning too. In fact, basically every single key you could think of has a meaning. So what do you map it to? Vim has something called a leader key, which means you pick a key ( by default, although <space> and , are common alternatives), and then use it in all your mappings. For example, you could say:



          nnoremap <leader>s :s/ //g<cr>


          and map it to <leader>s, whatever you choose leader to be. This is extremely useful, because now you have another 95 two-key sequences you could map to that are guaranteed to not overwrite anything else. You can come up with the shortcuts you find useful and don't have to worry about removing vim's default functionality.



          g works in a very similar way. Bram Moolenaar and Bill Joy I'm sure had many useful operations (such as go the beginning/end of the file, or go to [line]) that make sense to create a shortcut for in default vim, but they're not going to be used often enough to justify giving them a one-key shortcut, since these are reserved for the more useful/frequently used things like hjkl, or d and p. There are tons of keyboard shortcuts that all start with g. What do they have in common? Absolutely nothing. They just happen to be useful things to have that aren't worth giving a one-key shortcut for.



          So really, gg is a motion just like all the other motions I listed, it just happens to use a two-key sequence. g~ is an operator just like all the other operators I listed, it just happens to use a two-key sequence.



          There are several other "leader" like keys in vim. For example, look up in help





          • :h z (Commands that start with 'z')


          • :h [ (Commands that start with '[')


          • :h ctrl-w (Commands that start with <C-w>)






          share|improve this answer













          g is a little bit of a weird key in vim. A lot of other keys have a specific word to describe their category:




          • h, j, k, l, }, {, w, e, etc. are all motions. They tell your cursor to move.


          • d, c, y, etc. are all operators. They change the text they operate on in a specific way, and you tell them what text to operate on by giving a motion.



          g does not have a name like this. If I had to come up with a name, I would call it a leader. Here's a random example. Let's say you wanted a shortcut that removes every space from the current line. That's not too hard to do:



          :s/ //g<cr>


          But what do you map it to? How about d for delete spaces? Well... no, d already has a meaning. How about s for space? Well... no, s already has a meaning too. In fact, basically every single key you could think of has a meaning. So what do you map it to? Vim has something called a leader key, which means you pick a key ( by default, although <space> and , are common alternatives), and then use it in all your mappings. For example, you could say:



          nnoremap <leader>s :s/ //g<cr>


          and map it to <leader>s, whatever you choose leader to be. This is extremely useful, because now you have another 95 two-key sequences you could map to that are guaranteed to not overwrite anything else. You can come up with the shortcuts you find useful and don't have to worry about removing vim's default functionality.



          g works in a very similar way. Bram Moolenaar and Bill Joy I'm sure had many useful operations (such as go the beginning/end of the file, or go to [line]) that make sense to create a shortcut for in default vim, but they're not going to be used often enough to justify giving them a one-key shortcut, since these are reserved for the more useful/frequently used things like hjkl, or d and p. There are tons of keyboard shortcuts that all start with g. What do they have in common? Absolutely nothing. They just happen to be useful things to have that aren't worth giving a one-key shortcut for.



          So really, gg is a motion just like all the other motions I listed, it just happens to use a two-key sequence. g~ is an operator just like all the other operators I listed, it just happens to use a two-key sequence.



          There are several other "leader" like keys in vim. For example, look up in help





          • :h z (Commands that start with 'z')


          • :h [ (Commands that start with '[')


          • :h ctrl-w (Commands that start with <C-w>)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          DJMcMayhemDJMcMayhem

          10.7k12861




          10.7k12861













          • So g is like a system leader, as opposed to a user leader. Just have to memorize the combos. Thank you.

            – malan
            1 hour ago








          • 2





            g and z and really like namespaces for the next character. That's because we have been slowly running out of keys on a keyboard, so commands that are useful, had been added to those keys

            – Christian Brabandt
            1 hour ago











          • @ChristianBrabandt Yes, namespace is a great word for that.

            – DJMcMayhem
            1 hour ago



















          • So g is like a system leader, as opposed to a user leader. Just have to memorize the combos. Thank you.

            – malan
            1 hour ago








          • 2





            g and z and really like namespaces for the next character. That's because we have been slowly running out of keys on a keyboard, so commands that are useful, had been added to those keys

            – Christian Brabandt
            1 hour ago











          • @ChristianBrabandt Yes, namespace is a great word for that.

            – DJMcMayhem
            1 hour ago

















          So g is like a system leader, as opposed to a user leader. Just have to memorize the combos. Thank you.

          – malan
          1 hour ago







          So g is like a system leader, as opposed to a user leader. Just have to memorize the combos. Thank you.

          – malan
          1 hour ago






          2




          2





          g and z and really like namespaces for the next character. That's because we have been slowly running out of keys on a keyboard, so commands that are useful, had been added to those keys

          – Christian Brabandt
          1 hour ago





          g and z and really like namespaces for the next character. That's because we have been slowly running out of keys on a keyboard, so commands that are useful, had been added to those keys

          – Christian Brabandt
          1 hour ago













          @ChristianBrabandt Yes, namespace is a great word for that.

          – DJMcMayhem
          1 hour ago





          @ChristianBrabandt Yes, namespace is a great word for that.

          – DJMcMayhem
          1 hour ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Vi and Vim Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f18744%2fwhat-is-the-meaning-of-g%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What are all the squawk codes?

          What are differences between VBoxVGA, VMSVGA and VBoxSVGA in VirtualBox?

          Olav Thon