Skip to content

END和HOME键的问题 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tmoonlight opened this issue Jun 5, 2022 · 5 comments
Open

END和HOME键的问题 #37

tmoonlight opened this issue Jun 5, 2022 · 5 comments

Comments

@tmoonlight
Copy link

tmoonlight commented Jun 5, 2022

新手请教大佬。个人比较习惯单按home和end键跳转行尾行末的操作,pluginstall之后,进入插入模式按了end或者home会出现乱码(控制字符?),有办法让这两个键起作用吗?我试了unmap<end> , inoremap<end> xxx 这些都没有起作用。

@expoli
Copy link

expoli commented Apr 12, 2025

41212b7

我以前配置过,你可以按照我原来的配置来进行修改。不过你这样设置之后,对应的 ALT 操作会失效和对应的 install 模式的操作。你可以对着修改一下

@expoli
Copy link

expoli commented Apr 12, 2025

测试了一下,实际上需要把对应的 init-config.vim 中对 alt 键的修复注释掉就行了

@expoli
Copy link

expoli commented Apr 12, 2025

测试了一下,实际上需要把对应的 init-config.vim 中对 alt 键的修复注释掉就行了

不知道能否通过修改修复 alt 键位部分的代码处理,来让 Home 与 End 键生效 @skywind3000

@expoli
Copy link

expoli commented Apr 12, 2025

让 DeepSeek 帮忙写了一下,现在既可以支持 ALT 键,又可以支持 Home 与 End 键,可以测试一下

if has('nvim') == 0 && has('gui_running') == 0
    " 先强制绑定正确的 Home/End 键码(基于你的终端测试结果)
    " 对应 ^[[H
	execute "set <Home>=\e[H"
	" 对应 ^[[F
    execute "set <End>=\e[F"

    " 定义安全的 Alt 键绑定函数
    function! s:metacode(key)
        " 严格排除所有功能键相关的字符(包括转义序列组成部分)
        if a:key =~# '^[\[\]A-Z]$'  " 排除 [ ] 和所有大写字母(功能键常见字符)
            return
        endif
        " 特殊排除会导致冲突的字符
        if a:key =~# '^H$\|^F$'     " 单独排除 H/F(Home/End 的组成部分)
            return
        endif
        exec "set <M-".a:key.">=\e".a:key
    endfunction

    " 仅绑定安全的字符集
    for i in range(10)
        call s:metacode(nr2char(char2nr('0') + i))
    endfor
    for i in range(26)
        " 只绑定小写字母(避免大写字母与功能键冲突)
        call s:metacode(nr2char(char2nr('a') + i))
    endfor
    for c in [',', '.', '/', ';', '{', '}']
        call s:metacode(c)
    endfor
    for c in ['?', ':', '-', '_', '+', '=', "'"]
        call s:metacode(c)
    endfor
endif

@expoli
Copy link

expoli commented Apr 12, 2025

上面的配置配置之后会导致 init-keymaps 部分的这部分失效。酌情使用

"----------------------------------------------------------------------
" 窗口切换:ALT+SHIFT+hjkl
" 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在
" bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的
"----------------------------------------------------------------------
noremap <m-H> <c-w>h
noremap <m-L> <c-w>l
noremap <m-J> <c-w>j
noremap <m-K> <c-w>k
inoremap <m-H> <esc><c-w>h
inoremap <m-L> <esc><c-w>l
inoremap <m-J> <esc><c-w>j
inoremap <m-K> <esc><c-w>k

if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1')
	" vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式
	" 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+?
	" 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改
	set termwinkey=<c-_>
	tnoremap <m-H> <c-_>h
	tnoremap <m-L> <c-_>l
	tnoremap <m-J> <c-_>j
	tnoremap <m-K> <c-_>k
	tnoremap <m-q> <c-\><c-n>
elseif has('nvim')
	" neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式
	tnoremap <m-H> <c-\><c-n><c-w>h
	tnoremap <m-L> <c-\><c-n><c-w>l
	tnoremap <m-J> <c-\><c-n><c-w>j
	tnoremap <m-K> <c-\><c-n><c-w>k
	tnoremap <m-q> <c-\><c-n>
endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants