Hi Bill,

On 2/1/07, Bill McCarthy <[EMAIL PROTECTED]> wrote:
On Thu 1-Feb-07 11:51am -0600, Tim Chase wrote:

> vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
> vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>

Why do you use `<lt> instead of just `< ?  Just a matter of
preference?


The following text describing when to use <lt> in a map is taken
from the Vim keymap tutorial which is available at:

http://www.geocities.com/yegappan/vim_keymap.html

----------------------------------------------------------------------------------------------------
When Vim parses a string in a map command, the \<...> sequence of characters is
replaced by the corresponding control character. For example, let us
say in insert
mode you want the down arrow key to execute <C-N> when the insert complete
popup menu is displayed. Otherwise, you want the down arrow key to move the
cursor one line down. You can try the following command (which doesn't work):

   :inoremap <Down> <C-R>=pumvisible() ? "\<C-N>" : "\<Down>"<CR>

When parsing the above command, Vim replaces <C-N> and <Down> with the
corresponding control characters. When you press the down arrow in insert
mode, as there are control characters in the expression now, the
command will fail.

To fix this, you should escape the "<" character, so that Vim will not
replace "\<C-N>" with the control character when parsing the command. The
following command works:

   :inoremap <Down> <C-R>=pumvisible() ? "\<lt>C-N>" : "\<lt>Down>"<CR>

With the above command, Vim will use the control character only when the map
is invoked and not when the above command is parsed.
------------------------------------------------------------------------------------------------------------


------------------------------------------------------------------------------------------------------------
If the flag 'B' is present in 'cpoptions', then the backslash
character is not treated
as a special character in map commands. For example, let us say you want to
create an insert-mode map for the <F6> key to insert the text "Press <Home> to
go to first character". For this, you can try using the following command:

   imap <F6> Press <Home> to go to first character

When you press <F6> in the insert mode, the <Home> in the above map will
cause Vim to move the cursor to the first character in the line and insert the
reminder of the text there. To literally enter the text "<Home>", you need
to escape it:

   imap <F6> Press \<Home> to go to first character

If the flag 'B' is not present in 'cpoptions', then the above map command will
insert the correct text. If the flag 'B' is present, then the
backslash character is
not treated as a special character and the above map will not insert
the correct
text. To treat <Home> literally independent of the 'cpoptions' setting, you can
use the following command:

   imap <F6> Press <lt>Home> to go to first character

In the above command, the notation <lt> is used for "<" in "<Home>".
------------------------------------------------------------------------------------------------------------

- Yegappan

Reply via email to