Using a special key in functionUsing an environment variable name as function argumentEscape return value key in mapping functionHow to escape strings containing keys (when mapping) or call function with noremapCarriage return as argument breaks the functionExecute normal is inserting “<tab>” instead of hitting tab keyE129 when calling the function by call()Converting from A to B using mapped keyHow to have vnoremap call function once?Why do functions in Vimscript require a “call” statement?Vim+Tmux: How to switch between Tmux Windows and Vim Tab Pages Seamlessly using the Alt Key?

Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?

How can powerful telekinesis avoid violating Newton's 3rd Law?

Is Lambda Calculus purely syntactic?

Confused with atmospheric pressure equals plastic balloon’s inner pressure

NUL delimited variable

What should I discuss with my DM prior to my first game?

Why Does Mama Coco Look Old After Going to the Other World?

What would be the way to say "just saying" in German? (Not the literal translation)

Do you have to have figures when playing D&D?

Why did the World Bank set the global poverty line at $1.90?

How to avoid typing 'git' at the begining of every Git command

What should I be wary of when insurer is taking a lot of time to decide whether car is repairable or a total loss?

How and why do references in academic papers work?

Extracting data from Plot

Does a (nice) centerless group always have a centerless profinite completion?

What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?

Should I refuse to be named as co-author of a low quality paper?

What is the reason for setting flaps 1 on the ground at high temperatures?

ASCII Meme Arrow Generator

Can you make an identity from this product?

Can a human be transformed into a Mind Flayer?

noalign caused by multirow and colors

Flat with smooth fibers implies formally smooth?

The significance of kelvin as a unit of absolute temperature



Using a special key in function


Using an environment variable name as function argumentEscape return value key in mapping functionHow to escape strings containing keys (when mapping) or call function with noremapCarriage return as argument breaks the functionExecute normal is inserting “<tab>” instead of hitting tab keyE129 when calling the function by call()Converting from A to B using mapped keyHow to have vnoremap call function once?Why do functions in Vimscript require a “call” statement?Vim+Tmux: How to switch between Tmux Windows and Vim Tab Pages Seamlessly using the Alt Key?













0















I am trying to remap <PageUp> key to call this function:



function! PageUp()
let l:line = line('.')
if(l:line != 1)
if(l:line != winline())
:set syntax=off
<PageUp>
:set syntax=on
else
normal! 1G
endif
endif
endfunction


but gvim complains that I cannot do it.



So what is the proper way to use the keys in a function ?










share|improve this question


























    0















    I am trying to remap <PageUp> key to call this function:



    function! PageUp()
    let l:line = line('.')
    if(l:line != 1)
    if(l:line != winline())
    :set syntax=off
    <PageUp>
    :set syntax=on
    else
    normal! 1G
    endif
    endif
    endfunction


    but gvim complains that I cannot do it.



    So what is the proper way to use the keys in a function ?










    share|improve this question
























      0












      0








      0








      I am trying to remap <PageUp> key to call this function:



      function! PageUp()
      let l:line = line('.')
      if(l:line != 1)
      if(l:line != winline())
      :set syntax=off
      <PageUp>
      :set syntax=on
      else
      normal! 1G
      endif
      endif
      endfunction


      but gvim complains that I cannot do it.



      So what is the proper way to use the keys in a function ?










      share|improve this question














      I am trying to remap <PageUp> key to call this function:



      function! PageUp()
      let l:line = line('.')
      if(l:line != 1)
      if(l:line != winline())
      :set syntax=off
      <PageUp>
      :set syntax=on
      else
      normal! 1G
      endif
      endif
      endfunction


      but gvim complains that I cannot do it.



      So what is the proper way to use the keys in a function ?







      vimscript






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 3 at 22:22









      simo-zzsimo-zz

      20419




      20419




















          2 Answers
          2






          active

          oldest

          votes


















          3














          First of all, you use the PageUp key in Normal mode so the underlying functionality is a Normal mode command. You can't use such commands directly while in an Ex command-line or function/script. You need to use the Ex command :norm for this.



          Further, to use "key codes" (:h key-codes) of non-printing characters like <PageUp> you need to construct the :norm command as an expression and pass it to the :exe command (see last paragraph of :h :norm).



          That gives us:



          :exe "norm <PageUp>"


          The double quotes are required as is the to escape the keycode and indicate that you want the special meaning not the literal string "<PageUp>".



          (Note: Usually we want to use norm! instead of norm in order to avoid conflicts with mappings but that's not a critical element of this answer so omitted.)






          share|improve this answer
































            1














            To send special key to :normal, you need to get it's raw code by using "<key>" notation.



            exec "norm! <PageUp>"


            You can also use raw code directly if you want(not recommended, hard to read):



            norm! <80>kP
            ^----------<80> is 0x80


            <80>kP is raw code of <PageUp>, you can enter it like this in normal mode:



            "="<PageUp>"<cr>p
            ^----------press carriage return


            If raw code of the key doesn't start with 0x80, it's the same as terminal code (not sure), you can use the :h i_CTRL-V to insert terminal code:



            norm! <c-v><c-p>
            ^------------press ctrl-v ctrl-p


            • :h :exec

            • :h quote=

            • :h string





            share|improve this answer

























              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%2f20206%2fusing-a-special-key-in-function%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              First of all, you use the PageUp key in Normal mode so the underlying functionality is a Normal mode command. You can't use such commands directly while in an Ex command-line or function/script. You need to use the Ex command :norm for this.



              Further, to use "key codes" (:h key-codes) of non-printing characters like <PageUp> you need to construct the :norm command as an expression and pass it to the :exe command (see last paragraph of :h :norm).



              That gives us:



              :exe "norm <PageUp>"


              The double quotes are required as is the to escape the keycode and indicate that you want the special meaning not the literal string "<PageUp>".



              (Note: Usually we want to use norm! instead of norm in order to avoid conflicts with mappings but that's not a critical element of this answer so omitted.)






              share|improve this answer





























                3














                First of all, you use the PageUp key in Normal mode so the underlying functionality is a Normal mode command. You can't use such commands directly while in an Ex command-line or function/script. You need to use the Ex command :norm for this.



                Further, to use "key codes" (:h key-codes) of non-printing characters like <PageUp> you need to construct the :norm command as an expression and pass it to the :exe command (see last paragraph of :h :norm).



                That gives us:



                :exe "norm <PageUp>"


                The double quotes are required as is the to escape the keycode and indicate that you want the special meaning not the literal string "<PageUp>".



                (Note: Usually we want to use norm! instead of norm in order to avoid conflicts with mappings but that's not a critical element of this answer so omitted.)






                share|improve this answer



























                  3












                  3








                  3







                  First of all, you use the PageUp key in Normal mode so the underlying functionality is a Normal mode command. You can't use such commands directly while in an Ex command-line or function/script. You need to use the Ex command :norm for this.



                  Further, to use "key codes" (:h key-codes) of non-printing characters like <PageUp> you need to construct the :norm command as an expression and pass it to the :exe command (see last paragraph of :h :norm).



                  That gives us:



                  :exe "norm <PageUp>"


                  The double quotes are required as is the to escape the keycode and indicate that you want the special meaning not the literal string "<PageUp>".



                  (Note: Usually we want to use norm! instead of norm in order to avoid conflicts with mappings but that's not a critical element of this answer so omitted.)






                  share|improve this answer















                  First of all, you use the PageUp key in Normal mode so the underlying functionality is a Normal mode command. You can't use such commands directly while in an Ex command-line or function/script. You need to use the Ex command :norm for this.



                  Further, to use "key codes" (:h key-codes) of non-printing characters like <PageUp> you need to construct the :norm command as an expression and pass it to the :exe command (see last paragraph of :h :norm).



                  That gives us:



                  :exe "norm <PageUp>"


                  The double quotes are required as is the to escape the keycode and indicate that you want the special meaning not the literal string "<PageUp>".



                  (Note: Usually we want to use norm! instead of norm in order to avoid conflicts with mappings but that's not a critical element of this answer so omitted.)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 4 at 0:36

























                  answered Jun 4 at 0:04









                  B LayerB Layer

                  6,3621621




                  6,3621621





















                      1














                      To send special key to :normal, you need to get it's raw code by using "<key>" notation.



                      exec "norm! <PageUp>"


                      You can also use raw code directly if you want(not recommended, hard to read):



                      norm! <80>kP
                      ^----------<80> is 0x80


                      <80>kP is raw code of <PageUp>, you can enter it like this in normal mode:



                      "="<PageUp>"<cr>p
                      ^----------press carriage return


                      If raw code of the key doesn't start with 0x80, it's the same as terminal code (not sure), you can use the :h i_CTRL-V to insert terminal code:



                      norm! <c-v><c-p>
                      ^------------press ctrl-v ctrl-p


                      • :h :exec

                      • :h quote=

                      • :h string





                      share|improve this answer





























                        1














                        To send special key to :normal, you need to get it's raw code by using "<key>" notation.



                        exec "norm! <PageUp>"


                        You can also use raw code directly if you want(not recommended, hard to read):



                        norm! <80>kP
                        ^----------<80> is 0x80


                        <80>kP is raw code of <PageUp>, you can enter it like this in normal mode:



                        "="<PageUp>"<cr>p
                        ^----------press carriage return


                        If raw code of the key doesn't start with 0x80, it's the same as terminal code (not sure), you can use the :h i_CTRL-V to insert terminal code:



                        norm! <c-v><c-p>
                        ^------------press ctrl-v ctrl-p


                        • :h :exec

                        • :h quote=

                        • :h string





                        share|improve this answer



























                          1












                          1








                          1







                          To send special key to :normal, you need to get it's raw code by using "<key>" notation.



                          exec "norm! <PageUp>"


                          You can also use raw code directly if you want(not recommended, hard to read):



                          norm! <80>kP
                          ^----------<80> is 0x80


                          <80>kP is raw code of <PageUp>, you can enter it like this in normal mode:



                          "="<PageUp>"<cr>p
                          ^----------press carriage return


                          If raw code of the key doesn't start with 0x80, it's the same as terminal code (not sure), you can use the :h i_CTRL-V to insert terminal code:



                          norm! <c-v><c-p>
                          ^------------press ctrl-v ctrl-p


                          • :h :exec

                          • :h quote=

                          • :h string





                          share|improve this answer















                          To send special key to :normal, you need to get it's raw code by using "<key>" notation.



                          exec "norm! <PageUp>"


                          You can also use raw code directly if you want(not recommended, hard to read):



                          norm! <80>kP
                          ^----------<80> is 0x80


                          <80>kP is raw code of <PageUp>, you can enter it like this in normal mode:



                          "="<PageUp>"<cr>p
                          ^----------press carriage return


                          If raw code of the key doesn't start with 0x80, it's the same as terminal code (not sure), you can use the :h i_CTRL-V to insert terminal code:



                          norm! <c-v><c-p>
                          ^------------press ctrl-v ctrl-p


                          • :h :exec

                          • :h quote=

                          • :h string






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jun 4 at 3:49

























                          answered Jun 4 at 0:17









                          dedowsdidedowsdi

                          1,559414




                          1,559414



























                              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%2f20206%2fusing-a-special-key-in-function%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

                              Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                              Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                              Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form