gpt4 book ai didi

vim - 无法在vimrc中映射主页按钮

转载 作者:行者123 更新时间:2023-12-04 23:23:21 24 4
gpt4 key购买 nike

我想映射主页按钮,以便 vim 转到 vim 中的第一个非空白字符。但是映射主页按钮没有任何作用?如果我映射另一个键,则它可以正常工作。

请参阅下面我的 vimrc 文件:

map <Home> 0w
imap <Home> <ESC>0wi

以上是行不通的。虽然以下工作(例如Ctrl-F)
map <C-f> 0w
imap <C-f> <ESC>0wi

没有办法将 Home 键映射到这个吗?我真的很需要它,因为我在使用 Notepad++、Sublime text 2、Visual Studio 时已经习惯了……

我也尝试了以下方法,但没有结果。使用另一个键时,它再次起作用......
http://vim.wikia.com/wiki/Smart_home

最佳答案

来自 Vim FAQ (也可通过 this nice plugin 获得):

20.4. I am not able to create a mapping for the <xxx> key. What is wrong?

1) First make sure, the key is passed correctly to Vim. To determine if
this is the case, put Vim in Insert mode and then hit Ctrl-V (or
Ctrl-Q if your Ctrl-V is remapped to the paste operation (e.g. on
Windows if you are using the mswin.vim script file) followed by your
key.

If nothing appears in the buffer (and assuming that you have
'showcmd' on, ^V remains displayed near the bottom right of the Vim
screen), then Vim doesn't get your key correctly and there is nothing
to be done, other than selecting a different key for your mapping or
using GVim, which should recognise the key correctly.

这样你就可以检查 home您按下的键与 Vim 理解的 <Home> 相同.

另一种可能性是其他一些映射正在干扰这个映射。您可以尝试以下操作:
noremap <Home> 0w
inoremap <Home> <ESC>0wi

编辑:

问题似乎是您的终端正在发送 home Vim 无法识别的键码 <Home> .

我相信最好的解决方案是让 Vim 正确识别那个键,这样你就可以移动你的 .vimrc到其他终端/系统而无需更改。

来自 :h xterm-end-home-keys :
  On some systems (at least on FreeBSD with XFree86 3.1.2) the codes that the
<End> and <Home> keys send contain a <Nul> character. To make these keys send
the proper key code, add these lines to your ~/.Xdefaults file:

*VT100.Translations: #override \n\
<Key>Home: string("0x1b") string("[7~") \n\
<Key>End: string("0x1b") string("[8~")

如果这不起作用,您可以尝试 :set t_kh=^V^[[1~ .如果它有效,您可以将其附在终端类型的检查中。
更多信息请访问 :h terminal options
编辑 2:
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?

:
:

3) If the key is seen, but not as itself and not as some recognizable
key, then there is probably an error in the terminal library for the
current terminal (termcap or terminfo database). In that case >

:set term?

will tell you which termcap or terminfo Vim is using. You can try to
tell vim, what termcode to use in that terminal, by adding the
following to your vimrc: >

if &term == <termname>
set <C-Right>=<keycode>
endif

where <termname> above should be replaced by the value of 'term'
(with quotes around it) and <keycode> by what you get when hitting
Ctrl-V followed by Ctrl-Right in Insert mode (with nothing around
it). <C-Right> should be left as-is (9 characters). Don't forget that
in a :set command, white space is not allowed between the equal sign
and the value, and any space, double quote, vertical bar or backslash
present as part of the value must be backslash-escaped.

Now you should be able to see the keycode corresponding to the key
and you can create a mapping for the key using the following command: >

:map <C-Right> <your_command_to_be_mapped>

For more information, read

:h map-keys-fails
:h map-special-keys
:h key-codes

关于vim - 无法在vimrc中映射主页按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16958433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com