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?

BGP convergence issue

Soft question: Examples where lack of mathematical rigour cause security breaches?

Preventing Employees from either switching to Competitors or Opening Their Own Business

When conversion from Integer to Single may lose precision

Why doesn’t a normal window produce an apparent rainbow?

Passing multiple files through stdin (over ssh)

At what point in time did Dumbledore ask Snape for this favor?

Is it possible to 'live off the sea'

Find the Factorial From the Given Prime Relationship

Was there a priest on the Titanic who stayed on the ship giving confession to as many as he could?

Why only the fundamental frequency component is said to give useful power?

Inconsistent behavior of compiler optimization of unused string

What is the `some` keyword in SwiftUI

Were Alexander the Great and Hephaestion lovers?

How to build suspense or so to establish and justify xenophobia of characters in the eyes of the reader?

How to generate all commutative pairings of list elements?

Should an arbiter claim draw at a K+R vs K+R endgame?

How Can I Tell The Difference Between Unmarked Sugar and Stevia?

Smooth switching between 12 V batteries, with a toggle switch

Can an Aarakocra use a shield while flying?

Can the poison from Kingsmen be concocted?

Should I compare a std::string to "string" or "string"s?

Compiling c files on ubuntu and using the executable on Windows

Can a black dragonborn's acid breath weapon destroy objects?



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?













1















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


























    1















    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
























      1












      1








      1








      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 8 hours ago









      simo-zzsimo-zz

      20418




      20418




















          2 Answers
          2






          active

          oldest

          votes


















          2














          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









              2














              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





























                2














                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



























                  2












                  2








                  2







                  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 6 hours ago

























                  answered 6 hours ago









                  B LayerB Layer

                  6,2421620




                  6,2421620





















                      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 2 hours ago

























                          answered 6 hours ago









                          dedowsdidedowsdi

                          1,434411




                          1,434411



























                              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

                              Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                              Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                              199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單