What's the functional difference between the key notations “” and ''?What is the difference between single and double quoted strings?What's the difference between let and set?Difference between smart_close_popup() and cancel_popup() in neocomplete?What's the difference between call and execute?Differentiating between left and right shift keyWhat is the difference between set and :set?cnoremap and the <esc> keyWhat is the difference between single and double quoted strings?What is the difference between “mapped key sequences” and “key codes”? (timeoutlen v ttimeoutlen)what's the purpose of leading colon in key map?The difference between a plugin script and a sourced script

Does Anosov geodesic flow imply asphericity?

How exactly is a normal force exerted, at the molecular level?

Generate and graph the Recamán Sequence

Can a Federation colony become a member world?

Why are 120 V general receptacle circuits limited to 20 A?

Attempt to de-reference a null object: list initialization

Why won't the ground take my seed?

Miss Toad and her frogs

Automatically convert a number to use the correct SI unit prefix

Being paid less than a "junior" colleague

Should I report a leak of confidential HR information?

Why don't all electrons contribute to total orbital angular momentum of an atom?

One folder two different locations on ubuntu 18.04

Why isn’t the tax system continuous rather than bracketed?

Understanding Lasso Regression's sparsity geometrically

How did installing this RPM create a file?

What could a reptilian race tell by candling their eggs?

Skipping over failed imports until they are needed (if ever)

Why are there so many religions and gods?

What is the name of this OOB notification method/popup, and is it customizable?

Who are these Discworld wizards from this picture?

3D nonogram, beginner's edition

Can I ask to speak to my future colleagues before accepting an offer?

How is this practical and ancient scene shot?



What's the functional difference between the key notations “” and ''?


What is the difference between single and double quoted strings?What's the difference between let and set?Difference between smart_close_popup() and cancel_popup() in neocomplete?What's the difference between call and execute?Differentiating between left and right shift keyWhat is the difference between set and :set?cnoremap and the <esc> keyWhat is the difference between single and double quoted strings?What is the difference between “mapped key sequences” and “key codes”? (timeoutlen v ttimeoutlen)what's the purpose of leading colon in key map?The difference between a plugin script and a sourced script






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I stumbled recently upon a mapping in the Vim Tips Wiki that uses an expr-quote:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':"<Space>")<CR>


and realized it still worked after using a literal-string instead:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':'<Space>')<CR>


I find examples that use expr-quote over literal-string more often than not. Even the documentation for feedkeys() mentions




To include special keys into string, use double-quotes and "..."
notation |expr-quote|.




Is there any particular reason to prefer the "<xxx>" notation over '<xxx>'?



What is the difference between single and double quoted strings? answers this partially for special characters like n, but my question is specifically about the usage of special named keys like <CR>, <C-U>, etc.










share|improve this question









New contributor



Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 2





    I had a similar question a couple of years ago. Basically, map commands parse/guess the keynames specifically, therefore, they translate literal <keys> to the right form and you do not need the special form "<key>"

    – Christian Brabandt
    Jun 18 at 10:01


















4















I stumbled recently upon a mapping in the Vim Tips Wiki that uses an expr-quote:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':"<Space>")<CR>


and realized it still worked after using a literal-string instead:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':'<Space>')<CR>


I find examples that use expr-quote over literal-string more often than not. Even the documentation for feedkeys() mentions




To include special keys into string, use double-quotes and "..."
notation |expr-quote|.




Is there any particular reason to prefer the "<xxx>" notation over '<xxx>'?



What is the difference between single and double quoted strings? answers this partially for special characters like n, but my question is specifically about the usage of special named keys like <CR>, <C-U>, etc.










share|improve this question









New contributor



Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 2





    I had a similar question a couple of years ago. Basically, map commands parse/guess the keynames specifically, therefore, they translate literal <keys> to the right form and you do not need the special form "<key>"

    – Christian Brabandt
    Jun 18 at 10:01














4












4








4








I stumbled recently upon a mapping in the Vim Tips Wiki that uses an expr-quote:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':"<Space>")<CR>


and realized it still worked after using a literal-string instead:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':'<Space>')<CR>


I find examples that use expr-quote over literal-string more often than not. Even the documentation for feedkeys() mentions




To include special keys into string, use double-quotes and "..."
notation |expr-quote|.




Is there any particular reason to prefer the "<xxx>" notation over '<xxx>'?



What is the difference between single and double quoted strings? answers this partially for special characters like n, but my question is specifically about the usage of special named keys like <CR>, <C-U>, etc.










share|improve this question









New contributor



Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I stumbled recently upon a mapping in the Vim Tips Wiki that uses an expr-quote:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':"<Space>")<CR>


and realized it still worked after using a literal-string instead:



nnoremap <silent> <Space> @=(foldlevel('.')?'za':'<Space>')<CR>


I find examples that use expr-quote over literal-string more often than not. Even the documentation for feedkeys() mentions




To include special keys into string, use double-quotes and "..."
notation |expr-quote|.




Is there any particular reason to prefer the "<xxx>" notation over '<xxx>'?



What is the difference between single and double quoted strings? answers this partially for special characters like n, but my question is specifically about the usage of special named keys like <CR>, <C-U>, etc.







vimscript key-bindings






share|improve this question









New contributor



Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited Jun 19 at 11:18







Antoine Cotten













New contributor



Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked Jun 18 at 7:51









Antoine CottenAntoine Cotten

1235 bronze badges




1235 bronze badges




New contributor



Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Antoine Cotten is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









  • 2





    I had a similar question a couple of years ago. Basically, map commands parse/guess the keynames specifically, therefore, they translate literal <keys> to the right form and you do not need the special form "<key>"

    – Christian Brabandt
    Jun 18 at 10:01













  • 2





    I had a similar question a couple of years ago. Basically, map commands parse/guess the keynames specifically, therefore, they translate literal <keys> to the right form and you do not need the special form "<key>"

    – Christian Brabandt
    Jun 18 at 10:01








2




2





I had a similar question a couple of years ago. Basically, map commands parse/guess the keynames specifically, therefore, they translate literal <keys> to the right form and you do not need the special form "<key>"

– Christian Brabandt
Jun 18 at 10:01






I had a similar question a couple of years ago. Basically, map commands parse/guess the keynames specifically, therefore, they translate literal <keys> to the right form and you do not need the special form "<key>"

– Christian Brabandt
Jun 18 at 10:01











2 Answers
2






active

oldest

votes


















6














Good question. The keycode format with wider general usability is "<xxx>". In any expression this will be replaced with the underlying numerical representation of the associated key (i.e. the "key code").



Per :h keycodes the other form, <xxx>, is used in the documentation to represent non-printing keys and, more relevant here, can be used to substitute the associated key in mappings.



To my knowledge the mapping-only restriction is the critical difference between the two.



To demonstrate look at these two expression commands:



exe "echom 'hi<space>there'"
exe "echom 'hi<space>there'"


The first will print hi there to the command line. The second will print hi<space>there.



On the other hand if we put the same expressions in expression mappings...



nnoremap <expr> x ":echom 'hi<space>there'"<CR>
nnoremap <expr> x ":echom 'hi<space>there'"<CR>


...when invoked both will print hi there.



The "<xxx>" form also is used quite a bit in certain Vim function parameters so it may be illuminating to go to :h eval and search for the string < to see a number of examples of this.






share|improve this answer




















  • 1





    aha, in mappings is key here (no pun intended). Appreciate the reference to :h keycodes.

    – Antoine Cotten
    Jun 18 at 11:42











  • @AntoineCotten Sure. Glad it was useful to you.

    – B Layer
    Jun 18 at 13:04


















2














3 kinds of <xxxx>



"<xxxx>"
'<xxxx>'
<xxxx>


Let's see "<xxxx>" first, :h string says:



`<xxx> Special key named "xxx". e.g. "<C-W>" for CTRL-W.`
...


It's an expression, it's a string, a literal string for keycode, let's see it's relation ship with literal terminal keycode on my xterm-256color:



echo "a" output a, it's the same as terminal literal keycode
echo "b" output b, it's the same as terminal literal keycode

...
echo "<space>" output , it's the same as terminal literal keycode
echo "<c-a>" output ^a, it's the same as terminal literal keycode
echo "<c-b>" output ^b, it's the same as terminal literal keycode

...
echo "<c-right>" output <80><fd>V, it's not the same as terminal literal keycode
echo "<c-left>" output <80><fd>U, it's not the same as terminal literal keycode
echo "<f5>" output <80>k5, it's not the same as terminal literal keycode
echo "<f6>" output <80>k6, it's not the same as terminal literal keycode

...



So i believe "<xxxx>" is vim's internal keycode for keys, it's the same as terminal literal keycode if it doesn't starts with 0x80.



Now let's see '<xxxx>', it's the same as "<xxxx>", it's an expression, it's a string, and that's it, there is nothing special about this string.



Now let's see <xxxx>, it's not an expression, it's also not a string, it's nothing by itself, it has to be used with command like map.



Map and all kinds of <xxxx>



Definition of map without <expr> is:



Map the key sequence lhs to rhs for the modes where the map command applies.


It's key sequence, it works like you are typing it, remember that, it's very important.



:h keycodes says <xxxx> can be used with :h :map command, e.g.



inoremap <down> <esc>


Above command map <down> to <esc> in insert mode, map family command is smart, they interpret <xxxx> style keycode as vim's internal keycode for special keys. Now turn on :h 'showcmd' , let's see another example:



inoremap '<down> '<esc>'


Type 'down arrow' quickly in insert mode, you should see a single ', and you are back to normal mode, there should be a ' in right bottom of of your screen. Let's break it down: after you hit 'down arrow' in insert mode, the map triggered, it's result is '<esc>', remember that map without <expr> works like you are typing it, so you type ' esc, vim return to normal mode, the last ' won't be discarded, it waits for you to enter a mark lonely in the right bottom.



Another purpose of this example is to show you that map without <expr> knows nothing about expression, when it saw <xxxx>, it knows it should be interpreted as special key code, it doesn't care if it's surrounded by ' or ".



The <c-r>=



Let's see some wrong examples first, assume you want to map <c-f> to <esc> in insert mode:



inoremap <c-x> <c-r>='<esc>'<cr>


It won't work, because map without <expr> works like you are typing it, nothing good will happen if you type <esc> in the middle of a string. Continue:



inoremap <c-x> <c-r>="<esc>"<cr>


This won't work too, "" doesn't have chance to do their job, for the same reason as above. In this case you must prevent vim from interpreting <esc> as key code:



inoremap <c-x> <c-r>="<lt>esc>"<cr>


<lt> is special keycode for <, so after map special keycode interpretation, "<lt>esc>" becomes "<esc>", which is literal keycode for esc.



The <expr>



"<lt>esc>" is super ugly, :h :map-expression is much easier to work with, you provide an expression to map <expr>, it's evaluated result will be used as rhs for map, the result is key sequence, the expression is not:



inoremap <expr> <c-x> '<esc>'


It's simple and beautiful. Don't miss the quote, both '<xxxx>' and "<xxxx>" work here. Note that map still interpret <xxxx> as special keycode, this rule won't change, never change, but only for <xxxx> on the command, not for the result of the expression.
Let's use another example to explain that. Sometimes you want to use function as an expression:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction


Result of GetEsc() is "<esc>", you hope that map knows it's a special keycode. it won't work, map recognize <xxxx> as special keycode only if it's typed in the command directly, not for the expression result. The right form is:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction





share|improve this answer




















  • 3





    See also my question on vim-dev regarding this and the answer from ZyX

    – Christian Brabandt
    Jun 18 at 10:02











  • Vim is such a piece of work.

    – Antoine Cotten
    Jun 18 at 12:12











  • @ChristianBrabandt That part is still missing from help, i don't thing i have seen it.

    – dedowsdi
    Jun 18 at 12:23













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
);



);






Antoine Cotten is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f20344%2fwhats-the-functional-difference-between-the-key-notations-xxx-and-xxx%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









6














Good question. The keycode format with wider general usability is "<xxx>". In any expression this will be replaced with the underlying numerical representation of the associated key (i.e. the "key code").



Per :h keycodes the other form, <xxx>, is used in the documentation to represent non-printing keys and, more relevant here, can be used to substitute the associated key in mappings.



To my knowledge the mapping-only restriction is the critical difference between the two.



To demonstrate look at these two expression commands:



exe "echom 'hi<space>there'"
exe "echom 'hi<space>there'"


The first will print hi there to the command line. The second will print hi<space>there.



On the other hand if we put the same expressions in expression mappings...



nnoremap <expr> x ":echom 'hi<space>there'"<CR>
nnoremap <expr> x ":echom 'hi<space>there'"<CR>


...when invoked both will print hi there.



The "<xxx>" form also is used quite a bit in certain Vim function parameters so it may be illuminating to go to :h eval and search for the string < to see a number of examples of this.






share|improve this answer




















  • 1





    aha, in mappings is key here (no pun intended). Appreciate the reference to :h keycodes.

    – Antoine Cotten
    Jun 18 at 11:42











  • @AntoineCotten Sure. Glad it was useful to you.

    – B Layer
    Jun 18 at 13:04















6














Good question. The keycode format with wider general usability is "<xxx>". In any expression this will be replaced with the underlying numerical representation of the associated key (i.e. the "key code").



Per :h keycodes the other form, <xxx>, is used in the documentation to represent non-printing keys and, more relevant here, can be used to substitute the associated key in mappings.



To my knowledge the mapping-only restriction is the critical difference between the two.



To demonstrate look at these two expression commands:



exe "echom 'hi<space>there'"
exe "echom 'hi<space>there'"


The first will print hi there to the command line. The second will print hi<space>there.



On the other hand if we put the same expressions in expression mappings...



nnoremap <expr> x ":echom 'hi<space>there'"<CR>
nnoremap <expr> x ":echom 'hi<space>there'"<CR>


...when invoked both will print hi there.



The "<xxx>" form also is used quite a bit in certain Vim function parameters so it may be illuminating to go to :h eval and search for the string < to see a number of examples of this.






share|improve this answer




















  • 1





    aha, in mappings is key here (no pun intended). Appreciate the reference to :h keycodes.

    – Antoine Cotten
    Jun 18 at 11:42











  • @AntoineCotten Sure. Glad it was useful to you.

    – B Layer
    Jun 18 at 13:04













6












6








6







Good question. The keycode format with wider general usability is "<xxx>". In any expression this will be replaced with the underlying numerical representation of the associated key (i.e. the "key code").



Per :h keycodes the other form, <xxx>, is used in the documentation to represent non-printing keys and, more relevant here, can be used to substitute the associated key in mappings.



To my knowledge the mapping-only restriction is the critical difference between the two.



To demonstrate look at these two expression commands:



exe "echom 'hi<space>there'"
exe "echom 'hi<space>there'"


The first will print hi there to the command line. The second will print hi<space>there.



On the other hand if we put the same expressions in expression mappings...



nnoremap <expr> x ":echom 'hi<space>there'"<CR>
nnoremap <expr> x ":echom 'hi<space>there'"<CR>


...when invoked both will print hi there.



The "<xxx>" form also is used quite a bit in certain Vim function parameters so it may be illuminating to go to :h eval and search for the string < to see a number of examples of this.






share|improve this answer















Good question. The keycode format with wider general usability is "<xxx>". In any expression this will be replaced with the underlying numerical representation of the associated key (i.e. the "key code").



Per :h keycodes the other form, <xxx>, is used in the documentation to represent non-printing keys and, more relevant here, can be used to substitute the associated key in mappings.



To my knowledge the mapping-only restriction is the critical difference between the two.



To demonstrate look at these two expression commands:



exe "echom 'hi<space>there'"
exe "echom 'hi<space>there'"


The first will print hi there to the command line. The second will print hi<space>there.



On the other hand if we put the same expressions in expression mappings...



nnoremap <expr> x ":echom 'hi<space>there'"<CR>
nnoremap <expr> x ":echom 'hi<space>there'"<CR>


...when invoked both will print hi there.



The "<xxx>" form also is used quite a bit in certain Vim function parameters so it may be illuminating to go to :h eval and search for the string < to see a number of examples of this.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 18 at 13:03

























answered Jun 18 at 8:46









B LayerB Layer

6,5671 gold badge6 silver badges24 bronze badges




6,5671 gold badge6 silver badges24 bronze badges







  • 1





    aha, in mappings is key here (no pun intended). Appreciate the reference to :h keycodes.

    – Antoine Cotten
    Jun 18 at 11:42











  • @AntoineCotten Sure. Glad it was useful to you.

    – B Layer
    Jun 18 at 13:04












  • 1





    aha, in mappings is key here (no pun intended). Appreciate the reference to :h keycodes.

    – Antoine Cotten
    Jun 18 at 11:42











  • @AntoineCotten Sure. Glad it was useful to you.

    – B Layer
    Jun 18 at 13:04







1




1





aha, in mappings is key here (no pun intended). Appreciate the reference to :h keycodes.

– Antoine Cotten
Jun 18 at 11:42





aha, in mappings is key here (no pun intended). Appreciate the reference to :h keycodes.

– Antoine Cotten
Jun 18 at 11:42













@AntoineCotten Sure. Glad it was useful to you.

– B Layer
Jun 18 at 13:04





@AntoineCotten Sure. Glad it was useful to you.

– B Layer
Jun 18 at 13:04













2














3 kinds of <xxxx>



"<xxxx>"
'<xxxx>'
<xxxx>


Let's see "<xxxx>" first, :h string says:



`<xxx> Special key named "xxx". e.g. "<C-W>" for CTRL-W.`
...


It's an expression, it's a string, a literal string for keycode, let's see it's relation ship with literal terminal keycode on my xterm-256color:



echo "a" output a, it's the same as terminal literal keycode
echo "b" output b, it's the same as terminal literal keycode

...
echo "<space>" output , it's the same as terminal literal keycode
echo "<c-a>" output ^a, it's the same as terminal literal keycode
echo "<c-b>" output ^b, it's the same as terminal literal keycode

...
echo "<c-right>" output <80><fd>V, it's not the same as terminal literal keycode
echo "<c-left>" output <80><fd>U, it's not the same as terminal literal keycode
echo "<f5>" output <80>k5, it's not the same as terminal literal keycode
echo "<f6>" output <80>k6, it's not the same as terminal literal keycode

...



So i believe "<xxxx>" is vim's internal keycode for keys, it's the same as terminal literal keycode if it doesn't starts with 0x80.



Now let's see '<xxxx>', it's the same as "<xxxx>", it's an expression, it's a string, and that's it, there is nothing special about this string.



Now let's see <xxxx>, it's not an expression, it's also not a string, it's nothing by itself, it has to be used with command like map.



Map and all kinds of <xxxx>



Definition of map without <expr> is:



Map the key sequence lhs to rhs for the modes where the map command applies.


It's key sequence, it works like you are typing it, remember that, it's very important.



:h keycodes says <xxxx> can be used with :h :map command, e.g.



inoremap <down> <esc>


Above command map <down> to <esc> in insert mode, map family command is smart, they interpret <xxxx> style keycode as vim's internal keycode for special keys. Now turn on :h 'showcmd' , let's see another example:



inoremap '<down> '<esc>'


Type 'down arrow' quickly in insert mode, you should see a single ', and you are back to normal mode, there should be a ' in right bottom of of your screen. Let's break it down: after you hit 'down arrow' in insert mode, the map triggered, it's result is '<esc>', remember that map without <expr> works like you are typing it, so you type ' esc, vim return to normal mode, the last ' won't be discarded, it waits for you to enter a mark lonely in the right bottom.



Another purpose of this example is to show you that map without <expr> knows nothing about expression, when it saw <xxxx>, it knows it should be interpreted as special key code, it doesn't care if it's surrounded by ' or ".



The <c-r>=



Let's see some wrong examples first, assume you want to map <c-f> to <esc> in insert mode:



inoremap <c-x> <c-r>='<esc>'<cr>


It won't work, because map without <expr> works like you are typing it, nothing good will happen if you type <esc> in the middle of a string. Continue:



inoremap <c-x> <c-r>="<esc>"<cr>


This won't work too, "" doesn't have chance to do their job, for the same reason as above. In this case you must prevent vim from interpreting <esc> as key code:



inoremap <c-x> <c-r>="<lt>esc>"<cr>


<lt> is special keycode for <, so after map special keycode interpretation, "<lt>esc>" becomes "<esc>", which is literal keycode for esc.



The <expr>



"<lt>esc>" is super ugly, :h :map-expression is much easier to work with, you provide an expression to map <expr>, it's evaluated result will be used as rhs for map, the result is key sequence, the expression is not:



inoremap <expr> <c-x> '<esc>'


It's simple and beautiful. Don't miss the quote, both '<xxxx>' and "<xxxx>" work here. Note that map still interpret <xxxx> as special keycode, this rule won't change, never change, but only for <xxxx> on the command, not for the result of the expression.
Let's use another example to explain that. Sometimes you want to use function as an expression:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction


Result of GetEsc() is "<esc>", you hope that map knows it's a special keycode. it won't work, map recognize <xxxx> as special keycode only if it's typed in the command directly, not for the expression result. The right form is:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction





share|improve this answer




















  • 3





    See also my question on vim-dev regarding this and the answer from ZyX

    – Christian Brabandt
    Jun 18 at 10:02











  • Vim is such a piece of work.

    – Antoine Cotten
    Jun 18 at 12:12











  • @ChristianBrabandt That part is still missing from help, i don't thing i have seen it.

    – dedowsdi
    Jun 18 at 12:23















2














3 kinds of <xxxx>



"<xxxx>"
'<xxxx>'
<xxxx>


Let's see "<xxxx>" first, :h string says:



`<xxx> Special key named "xxx". e.g. "<C-W>" for CTRL-W.`
...


It's an expression, it's a string, a literal string for keycode, let's see it's relation ship with literal terminal keycode on my xterm-256color:



echo "a" output a, it's the same as terminal literal keycode
echo "b" output b, it's the same as terminal literal keycode

...
echo "<space>" output , it's the same as terminal literal keycode
echo "<c-a>" output ^a, it's the same as terminal literal keycode
echo "<c-b>" output ^b, it's the same as terminal literal keycode

...
echo "<c-right>" output <80><fd>V, it's not the same as terminal literal keycode
echo "<c-left>" output <80><fd>U, it's not the same as terminal literal keycode
echo "<f5>" output <80>k5, it's not the same as terminal literal keycode
echo "<f6>" output <80>k6, it's not the same as terminal literal keycode

...



So i believe "<xxxx>" is vim's internal keycode for keys, it's the same as terminal literal keycode if it doesn't starts with 0x80.



Now let's see '<xxxx>', it's the same as "<xxxx>", it's an expression, it's a string, and that's it, there is nothing special about this string.



Now let's see <xxxx>, it's not an expression, it's also not a string, it's nothing by itself, it has to be used with command like map.



Map and all kinds of <xxxx>



Definition of map without <expr> is:



Map the key sequence lhs to rhs for the modes where the map command applies.


It's key sequence, it works like you are typing it, remember that, it's very important.



:h keycodes says <xxxx> can be used with :h :map command, e.g.



inoremap <down> <esc>


Above command map <down> to <esc> in insert mode, map family command is smart, they interpret <xxxx> style keycode as vim's internal keycode for special keys. Now turn on :h 'showcmd' , let's see another example:



inoremap '<down> '<esc>'


Type 'down arrow' quickly in insert mode, you should see a single ', and you are back to normal mode, there should be a ' in right bottom of of your screen. Let's break it down: after you hit 'down arrow' in insert mode, the map triggered, it's result is '<esc>', remember that map without <expr> works like you are typing it, so you type ' esc, vim return to normal mode, the last ' won't be discarded, it waits for you to enter a mark lonely in the right bottom.



Another purpose of this example is to show you that map without <expr> knows nothing about expression, when it saw <xxxx>, it knows it should be interpreted as special key code, it doesn't care if it's surrounded by ' or ".



The <c-r>=



Let's see some wrong examples first, assume you want to map <c-f> to <esc> in insert mode:



inoremap <c-x> <c-r>='<esc>'<cr>


It won't work, because map without <expr> works like you are typing it, nothing good will happen if you type <esc> in the middle of a string. Continue:



inoremap <c-x> <c-r>="<esc>"<cr>


This won't work too, "" doesn't have chance to do their job, for the same reason as above. In this case you must prevent vim from interpreting <esc> as key code:



inoremap <c-x> <c-r>="<lt>esc>"<cr>


<lt> is special keycode for <, so after map special keycode interpretation, "<lt>esc>" becomes "<esc>", which is literal keycode for esc.



The <expr>



"<lt>esc>" is super ugly, :h :map-expression is much easier to work with, you provide an expression to map <expr>, it's evaluated result will be used as rhs for map, the result is key sequence, the expression is not:



inoremap <expr> <c-x> '<esc>'


It's simple and beautiful. Don't miss the quote, both '<xxxx>' and "<xxxx>" work here. Note that map still interpret <xxxx> as special keycode, this rule won't change, never change, but only for <xxxx> on the command, not for the result of the expression.
Let's use another example to explain that. Sometimes you want to use function as an expression:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction


Result of GetEsc() is "<esc>", you hope that map knows it's a special keycode. it won't work, map recognize <xxxx> as special keycode only if it's typed in the command directly, not for the expression result. The right form is:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction





share|improve this answer




















  • 3





    See also my question on vim-dev regarding this and the answer from ZyX

    – Christian Brabandt
    Jun 18 at 10:02











  • Vim is such a piece of work.

    – Antoine Cotten
    Jun 18 at 12:12











  • @ChristianBrabandt That part is still missing from help, i don't thing i have seen it.

    – dedowsdi
    Jun 18 at 12:23













2












2








2







3 kinds of <xxxx>



"<xxxx>"
'<xxxx>'
<xxxx>


Let's see "<xxxx>" first, :h string says:



`<xxx> Special key named "xxx". e.g. "<C-W>" for CTRL-W.`
...


It's an expression, it's a string, a literal string for keycode, let's see it's relation ship with literal terminal keycode on my xterm-256color:



echo "a" output a, it's the same as terminal literal keycode
echo "b" output b, it's the same as terminal literal keycode

...
echo "<space>" output , it's the same as terminal literal keycode
echo "<c-a>" output ^a, it's the same as terminal literal keycode
echo "<c-b>" output ^b, it's the same as terminal literal keycode

...
echo "<c-right>" output <80><fd>V, it's not the same as terminal literal keycode
echo "<c-left>" output <80><fd>U, it's not the same as terminal literal keycode
echo "<f5>" output <80>k5, it's not the same as terminal literal keycode
echo "<f6>" output <80>k6, it's not the same as terminal literal keycode

...



So i believe "<xxxx>" is vim's internal keycode for keys, it's the same as terminal literal keycode if it doesn't starts with 0x80.



Now let's see '<xxxx>', it's the same as "<xxxx>", it's an expression, it's a string, and that's it, there is nothing special about this string.



Now let's see <xxxx>, it's not an expression, it's also not a string, it's nothing by itself, it has to be used with command like map.



Map and all kinds of <xxxx>



Definition of map without <expr> is:



Map the key sequence lhs to rhs for the modes where the map command applies.


It's key sequence, it works like you are typing it, remember that, it's very important.



:h keycodes says <xxxx> can be used with :h :map command, e.g.



inoremap <down> <esc>


Above command map <down> to <esc> in insert mode, map family command is smart, they interpret <xxxx> style keycode as vim's internal keycode for special keys. Now turn on :h 'showcmd' , let's see another example:



inoremap '<down> '<esc>'


Type 'down arrow' quickly in insert mode, you should see a single ', and you are back to normal mode, there should be a ' in right bottom of of your screen. Let's break it down: after you hit 'down arrow' in insert mode, the map triggered, it's result is '<esc>', remember that map without <expr> works like you are typing it, so you type ' esc, vim return to normal mode, the last ' won't be discarded, it waits for you to enter a mark lonely in the right bottom.



Another purpose of this example is to show you that map without <expr> knows nothing about expression, when it saw <xxxx>, it knows it should be interpreted as special key code, it doesn't care if it's surrounded by ' or ".



The <c-r>=



Let's see some wrong examples first, assume you want to map <c-f> to <esc> in insert mode:



inoremap <c-x> <c-r>='<esc>'<cr>


It won't work, because map without <expr> works like you are typing it, nothing good will happen if you type <esc> in the middle of a string. Continue:



inoremap <c-x> <c-r>="<esc>"<cr>


This won't work too, "" doesn't have chance to do their job, for the same reason as above. In this case you must prevent vim from interpreting <esc> as key code:



inoremap <c-x> <c-r>="<lt>esc>"<cr>


<lt> is special keycode for <, so after map special keycode interpretation, "<lt>esc>" becomes "<esc>", which is literal keycode for esc.



The <expr>



"<lt>esc>" is super ugly, :h :map-expression is much easier to work with, you provide an expression to map <expr>, it's evaluated result will be used as rhs for map, the result is key sequence, the expression is not:



inoremap <expr> <c-x> '<esc>'


It's simple and beautiful. Don't miss the quote, both '<xxxx>' and "<xxxx>" work here. Note that map still interpret <xxxx> as special keycode, this rule won't change, never change, but only for <xxxx> on the command, not for the result of the expression.
Let's use another example to explain that. Sometimes you want to use function as an expression:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction


Result of GetEsc() is "<esc>", you hope that map knows it's a special keycode. it won't work, map recognize <xxxx> as special keycode only if it's typed in the command directly, not for the expression result. The right form is:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction





share|improve this answer















3 kinds of <xxxx>



"<xxxx>"
'<xxxx>'
<xxxx>


Let's see "<xxxx>" first, :h string says:



`<xxx> Special key named "xxx". e.g. "<C-W>" for CTRL-W.`
...


It's an expression, it's a string, a literal string for keycode, let's see it's relation ship with literal terminal keycode on my xterm-256color:



echo "a" output a, it's the same as terminal literal keycode
echo "b" output b, it's the same as terminal literal keycode

...
echo "<space>" output , it's the same as terminal literal keycode
echo "<c-a>" output ^a, it's the same as terminal literal keycode
echo "<c-b>" output ^b, it's the same as terminal literal keycode

...
echo "<c-right>" output <80><fd>V, it's not the same as terminal literal keycode
echo "<c-left>" output <80><fd>U, it's not the same as terminal literal keycode
echo "<f5>" output <80>k5, it's not the same as terminal literal keycode
echo "<f6>" output <80>k6, it's not the same as terminal literal keycode

...



So i believe "<xxxx>" is vim's internal keycode for keys, it's the same as terminal literal keycode if it doesn't starts with 0x80.



Now let's see '<xxxx>', it's the same as "<xxxx>", it's an expression, it's a string, and that's it, there is nothing special about this string.



Now let's see <xxxx>, it's not an expression, it's also not a string, it's nothing by itself, it has to be used with command like map.



Map and all kinds of <xxxx>



Definition of map without <expr> is:



Map the key sequence lhs to rhs for the modes where the map command applies.


It's key sequence, it works like you are typing it, remember that, it's very important.



:h keycodes says <xxxx> can be used with :h :map command, e.g.



inoremap <down> <esc>


Above command map <down> to <esc> in insert mode, map family command is smart, they interpret <xxxx> style keycode as vim's internal keycode for special keys. Now turn on :h 'showcmd' , let's see another example:



inoremap '<down> '<esc>'


Type 'down arrow' quickly in insert mode, you should see a single ', and you are back to normal mode, there should be a ' in right bottom of of your screen. Let's break it down: after you hit 'down arrow' in insert mode, the map triggered, it's result is '<esc>', remember that map without <expr> works like you are typing it, so you type ' esc, vim return to normal mode, the last ' won't be discarded, it waits for you to enter a mark lonely in the right bottom.



Another purpose of this example is to show you that map without <expr> knows nothing about expression, when it saw <xxxx>, it knows it should be interpreted as special key code, it doesn't care if it's surrounded by ' or ".



The <c-r>=



Let's see some wrong examples first, assume you want to map <c-f> to <esc> in insert mode:



inoremap <c-x> <c-r>='<esc>'<cr>


It won't work, because map without <expr> works like you are typing it, nothing good will happen if you type <esc> in the middle of a string. Continue:



inoremap <c-x> <c-r>="<esc>"<cr>


This won't work too, "" doesn't have chance to do their job, for the same reason as above. In this case you must prevent vim from interpreting <esc> as key code:



inoremap <c-x> <c-r>="<lt>esc>"<cr>


<lt> is special keycode for <, so after map special keycode interpretation, "<lt>esc>" becomes "<esc>", which is literal keycode for esc.



The <expr>



"<lt>esc>" is super ugly, :h :map-expression is much easier to work with, you provide an expression to map <expr>, it's evaluated result will be used as rhs for map, the result is key sequence, the expression is not:



inoremap <expr> <c-x> '<esc>'


It's simple and beautiful. Don't miss the quote, both '<xxxx>' and "<xxxx>" work here. Note that map still interpret <xxxx> as special keycode, this rule won't change, never change, but only for <xxxx> on the command, not for the result of the expression.
Let's use another example to explain that. Sometimes you want to use function as an expression:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction


Result of GetEsc() is "<esc>", you hope that map knows it's a special keycode. it won't work, map recognize <xxxx> as special keycode only if it's typed in the command directly, not for the expression result. The right form is:



inoremap <c-x> GetEsc()
function! GetEsc()
return "<esc>"
endfunction






share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 18 at 10:59

























answered Jun 18 at 9:43









dedowsdidedowsdi

1,9064 silver badges15 bronze badges




1,9064 silver badges15 bronze badges







  • 3





    See also my question on vim-dev regarding this and the answer from ZyX

    – Christian Brabandt
    Jun 18 at 10:02











  • Vim is such a piece of work.

    – Antoine Cotten
    Jun 18 at 12:12











  • @ChristianBrabandt That part is still missing from help, i don't thing i have seen it.

    – dedowsdi
    Jun 18 at 12:23












  • 3





    See also my question on vim-dev regarding this and the answer from ZyX

    – Christian Brabandt
    Jun 18 at 10:02











  • Vim is such a piece of work.

    – Antoine Cotten
    Jun 18 at 12:12











  • @ChristianBrabandt That part is still missing from help, i don't thing i have seen it.

    – dedowsdi
    Jun 18 at 12:23







3




3





See also my question on vim-dev regarding this and the answer from ZyX

– Christian Brabandt
Jun 18 at 10:02





See also my question on vim-dev regarding this and the answer from ZyX

– Christian Brabandt
Jun 18 at 10:02













Vim is such a piece of work.

– Antoine Cotten
Jun 18 at 12:12





Vim is such a piece of work.

– Antoine Cotten
Jun 18 at 12:12













@ChristianBrabandt That part is still missing from help, i don't thing i have seen it.

– dedowsdi
Jun 18 at 12:23





@ChristianBrabandt That part is still missing from help, i don't thing i have seen it.

– dedowsdi
Jun 18 at 12:23










Antoine Cotten is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Antoine Cotten is a new contributor. Be nice, and check out our Code of Conduct.












Antoine Cotten is a new contributor. Be nice, and check out our Code of Conduct.











Antoine Cotten is a new contributor. Be nice, and check out our Code of Conduct.














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%2f20344%2fwhats-the-functional-difference-between-the-key-notations-xxx-and-xxx%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

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

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?