地图'f'在 vi 中转到 PageUp
我可以将 '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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并没有回答您的问题,但我认为这可能对您遇到的 RSI 问题有所帮助。它映射空格键以在快速和慢速移动模式之间切换。通常按 j 或 k 会向下滚动一行。按空格键将打开快速移动模式,按 j 或 k 将向下/向上滚动 10 行。再次按空格即可恢复正常。这只适用于 vim,而不仅仅是普通的 vi(尽管大多数“vi”程序只是 vim 的符号链接)。
它可以在正常和可视编辑模式下工作。
要使用它,请将此代码放在
~/.vimrc
文件中的某个位置: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:(编辑 - 原始答案建议使用本机 Ctrl-f 和 Ctrl-b,但答案已更新,因为这里的目标是避免使用 Ctrl 和 Shift)
需要添加的几点
将选择正确字符的问题留给您,假设我们选择现在是
X
。我可以想到
map X
不适合您的两个原因。您的 vi 版本可能不支持 PageUp/PageDown。如果这是问题所在,那么尝试映射到 vi 的页面跳转(B 表示后退,伴随着前进),例如。
地图 X
。另一个选择是它不能“按预期”工作。在 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.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>
.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 beingmap X <C-f>L
). Or specifying the number of lines to jump yourselfmap 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.