地图'f'在 vi 中转到 PageUp

发布于 2024-12-12 05:22:53 字数 490 浏览 0 评论 0原文

我可以将 'jj' 映射到

imap jj

我什至可以将字母映射到选项卡导航

map tj :tabprevious<CR>
map tk :tabnext<CR>

但我无法将 g 映射到向上翻页(即使空格键充当向下翻页

map <Space> <PageDown>
map g <PageUp> 

这个“当您尝试映射多个按键序列时,您将不会'无法以较低的价格启动它们或大写字母(“映射它太危险了”),但标点符号和控制字符是公平的游戏。谁能证实这一点吗?

如果是这样,如何将功能分配给像“g”这样的未映射键

I can map 'jj' to

imap jj <Esc>

and I can even map letters to tab navigation

map tj :tabprevious<CR>
map tk :tabnext<CR>

But I can't map g to page up (even though spacebar acts as page down)

map <Space> <PageDown>
map g <PageUp> 

According to this "When you try to map multiple key sequences, you won't be able to start them with lower or upper case letters ("Too dangerous to map that"), but the punctuation and control characters are fair game." Can anyone confirm this?

If so, how does one assign a function to an unmapped key like 'g'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞琼窗梦回ˉ 2024-12-19 05:22:53

这并没有回答您的问题,但我认为这可能对您遇到的 RSI 问题有所帮助。它映射空格键以在快速和慢速移动模式之间切换。通常按 j 或 k 会向下滚动一行。按空格键将打开快速移动模式,按 j 或 k 将向下/向上滚动 10 行。再次按空格即可恢复正常。这只适用于 vim,而不仅仅是普通的 vi(尽管大多数“vi”程序只是 vim 的符号链接)。

它可以在正常和可视编辑模式下工作。

要使用它,请将此代码放在 ~/.vimrc 文件中的某个位置:

map <Space> :call ToggleFastMoveMode()<CR>

vmap <Space> :call ToggleFastMoveMode()<CR>gv

let g:fastMoveMode = 0

function! ToggleFastMoveMode()
    let g:fastMoveMode = 1 - g:fastMoveMode
    if (g:fastMoveMode == 0)
        noremap j j
        vnoremap j j
        noremap k k
        vnoremap k k
    else
        noremap j 10j
        vnoremap j 10j
        noremap k 10k
        vnoremap k 10k
    endif
endfunction

This isn't answering your question, but I thought it may be helpful to the problem you are having with your RSI. It maps the spacebar to toggle between fast and slow move modes. Normally pressing j or k will scroll down one line. Pressing space will turn on fast move mode, where pressing j or k will scroll down/up 10 lines. Press space again to go back to normal. This will only work in vim, not just plain vi (most "vi" programs are just symlinks to vim anyway though).

It works in both normal and visual edit modes.

To use it, put this code somewhere in your ~/.vimrc file:

map <Space> :call ToggleFastMoveMode()<CR>

vmap <Space> :call ToggleFastMoveMode()<CR>gv

let g:fastMoveMode = 0

function! ToggleFastMoveMode()
    let g:fastMoveMode = 1 - g:fastMoveMode
    if (g:fastMoveMode == 0)
        noremap j j
        vnoremap j j
        noremap k k
        vnoremap k k
    else
        noremap j 10j
        vnoremap j 10j
        noremap k 10k
        vnoremap k 10k
    endif
endfunction
乜一 2024-12-19 05:22:53

(编辑 - 原始答案建议使用本机 Ctrl-f 和 Ctrl-b,但答案已更新,因为这里的目标是避免使用 Ctrl 和 Shift)

需要添加的几点

将选择正确字符的问题留给您,假设我们选择现在是X

我可以想到 map X 不适合您的两个原因。

  1. 您的 vi 版本可能不支持 PageUp/PageDown。如果这是问题所在,那么尝试映射到 vi 的页面跳转(B 表示后退,伴随着前进),例如。 地图 X

  2. 另一个选择是它不能“按预期”工作。在 vi 中 PageUp/PageDown 作用于“视口”而不是光标。因此,如果您正在查看文件的顶部,但光标不在顶部或不会执行任何操作。如果光标距底部两行,PageDown 也不会“工作”。

    要解决这个问题,您可以将“向上移动视口” 和“将光标移动到视口顶部”H 结合起来,例如。 map XH(相反的是map XL)。或者指定自己跳转的行数map X 30k(Op.map X 30j)。

然后是选择正确的字符进行覆盖的问题。 Vi 有很多本机命令,实际上数量太多,以至于只有少数字符本身不执行某些操作。
因此,如果您的目标是避免 RSI,那么当然要覆盖一些内容。但请确保覆盖一些对您个人来说不太有用的内容。

本地:
f 在您当前所在的线路上搜索给定符号(可能非常有用,但我认为并不重要)
g 本身不执行任何操作,但 gg 将光标移动到文件顶部。选择 g 可能会导致问题,因为 vim(不是原来的 vi)会将两次快速按键解释为转到文件顶部,而不是执行两次 PageUp。

(Edit - original answer suggested native Ctrl-f and Ctrl-b, but answer was updated as the goal here is to avoid using Ctrl and Shift)

A few points to add

Leaving the issue of choosing the right character to you, assuming we chose X for now.

I can think of two reasons why map X <PageUp> isn't working for you.

  1. Your version of vi may not support PageUp/PageDown. If this is the issue then try instead to map to vi's page jumping (B for back, accompanied by for forward) eg. map X <C-b>.

  2. Another other option is that it doesn't work 'as expected'. In vi PageUp/PageDown act on the 'viewport' not the cursor. So if you'r looking at the top of the file, but the cursor is not at the top or won't do anything. PageDown won't 'work' if your cursor is two lines from the bottom either.

    To address this you could combine the 'move viewport up' <C-b> and the 'move cursor to the top of viewport' H eg. map X <C-b>H (The opposite being map X <C-f>L). Or specifying the number of lines to jump yourself map X 30k (Op. map X 30j).

Then the issue of choosing the right character to overwrite. Vi has a lot of native commands, so many in fact that only a handful of characters don't do something natively.
So if your goal is to avoid RSI, then of course overwrite something. But make sure to overwrite something that isn't too useful for you personally.

Natively:
f searches for a given symbol on the line you are currnetly on (can be very useful, but not critical I guess)
g on it's own does nothing, but gg moves cursor to top of file. Choosing g may cause issus as vim (not the original vi) will interpret two quick keypresses as go to top of file instead of do two PageUp's.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文