使用非拉丁语言(例如希腊语)书写时,如何避免不断地在英语键盘布局和 Vim 命令之间切换?
我正在认真尝试用 Vim 来编写我的 Python 应用程序。 然而,事实证明,Vim 非常灵活,我想用它作为我工作中撰写律师/法律文件的主要编辑器。问题是我的母语不是英语而是希腊语。因此,我映射了 Alt+Shift 来在英语和希腊语键盘布局之间进行更改。
我遇到的问题是每次我想输入 Vim 命令(返回英语)时都必须按 Alt+Shift。所以当我输入文档时是 Alt+Shift,然后再次 Alt+Shift 输入 Vim 命令。这违背了使用 Vim 的目的,至少在使用速度方面是这样。
所以我的问题很简单:有什么方法可以避免在使用非拉丁语言编写时频繁的 Alt+Shift 键盘布局更改,只是为了输入 Vim 命令(例如,希腊语)?
I am giving Vim a serious try for coding my Python apps.
However, Vim is proving to be so flexible, I was thinking to use it as my main editor at work for writing lawyer/legal documents. The problem is that my mother tongue is not English but Greek. So, I have mapped Alt+Shift to change between English and Greek keyboard layouts.
The issue I am experiencing is that I have to press Alt+Shift each time I want to enter a Vim command (to return back to English). So it is Alt+Shift when I type my document, then Alt+Shift again to enter Vim commands. This defeats the purpose of using Vim, at least in terms of speed of use.
So my question is simple: Is there any way to avoid those frequent Alt+Shift keyboard layout changes just for entering Vim commands when writing in a non-Latin language (e.g., Greek)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题可以借助
keymap
选项来解决。它允许定义在模式下使用的备用键盘映射
需要文本输入。
要在插入时在默认键盘映射和备用键盘映射之间切换,
替换,或者命令行模式(但不是普通模式),使用
Ctrl+^ (Ctrl+6)。
更改键盘映射仅影响文本输入;中的键盘行为
无论当前的键盘映射设置如何,正常模式都保持不变。
人们可以离开插入模式用希腊语书写并立即使用
正常模式按键绑定,无需切换到不同的键盘
布局。如果随后返回到插入模式,或者例如启动
输入
/
进行搜索,Vim 将键盘映射回希腊语自动地。
记住这些文本输入模式中使用的当前键盘映射
切换到其他模式之间。唯一的例外是
行为是针对命令行模式进行的,该模式始终以
默认键盘映射,因为大多数时候需要输入 Ex
命令(ASCII 格式)。设置
keymap
选项后,用户应该在 Vim 中工作时保持系统键盘布局设置为英语
使用 Ctrl+^ 切换 Vim 键盘映射(而不是
系统范围的布局开关)。
要永久启用 UTF-8 希腊语键盘映射,请添加以下内容
行到您的
.vimrc
文件。有许多针对大量语言的预定义键盘映射,您可以
可以使用
:e $VIMRUNTIME/keymap
在 Vim 中浏览它们。笔记通常为一种语言提供多个键盘映射
仅字符编码不同,因此任何人都可以选择一种
适合他们的配置。
我还建议设置以下选项来指定是否
默认情况下,在插入模式下和输入时应启用键盘映射
搜索模式:
请参阅
:help iminsert
和:help imsearch
了解详细说明。还有一种特殊的语言模式,如果我没记错的话,
Vim 中的引入早于
keymap
。它允许实现与手动通过
keymap
提供的行为类似指定与键盘上的按键相对应的字母对
要保存在
langmap
选项中的长字符串。就个人而言——我的母语也不是英语——我更喜欢(并推荐)使用
而是使用
keymap
方式。总之,我应该强调以上所有内容都是平等的
适用于 Vim 拥有的任何其他语言(或可以配置为
有)一个键盘映射。
另请参阅我对类似问题的回答Vim“烦恼”
与键盘布局'自从我最初以来就一直被问到
给出了这个答案。
This problem can be solved with the help of the
keymap
option.It allows to define an alternate keyboard mapping to use in modes
requiring text input.
To switch between the default and alternate keymaps while in Insert,
Replace, or Command-line mode (but not Normal mode), use
Ctrl+^ (Ctrl+6).
Changing the keymap affects text input only; keyboard behavior in
Normal mode stays the same regardless of the current keymap setting.
One can leave Insert mode writing in Greek and immediately use
Normal-mode keybindings without switching to a different keyboard
layout. If one then returns to Insert mode or, for example, starts
a search by typing
/
, Vim switches the keymap back to Greekautomatically.
The current keymap used in those text-entering modes is remembered
between switchings to other modes. The only exception from this
behaviour is made for Command-line mode which always starts with the
default keymap, since most of the time it is required to type an Ex
command (in ASCII). With the
keymap
option set, user is supposedto work in Vim keeping system keyboard layout set to English while
switching Vim keymap with Ctrl+^ (instead of
the system-wide layout switch).
To enable, say, the UTF-8 Greek keymap permanently, add the following
line to your
.vimrc
file.There are many predefined keymaps for a large set of languages, you
can browse them all in Vim itself using
:e $VIMRUNTIME/keymap
. Notethat usually there are several keymaps provided for one language which
differ only by character encoding, so that anybody could choose one
that suits their configuration.
I also recommend setting the options below to specify whether the
keymap should be enabled by default in Insert mode and when entering
a search pattern:
See
:help iminsert
and:help imsearch
for the detailed explanation.There is also a special language mode that, if I am not mistaken,
was introduced in Vim earlier than
keymap
. It allows to achievethe behaviour similar to the one provided by
keymap
through manuallyspecifying letter pairs that correspond to the keys on keyboard in
a long string to be saved in the
langmap
option. Personally—mynative language is not English, too—I prefer (and recommend) using
the
keymap
way instead.In conclusion, I should emphasize that all of the above is equally
applicable to any other language Vim has (or can be configured to
have) a keymap for.
See also my answer to a similar question ‘Vim “annoyance”
with keyboard layouts’ that has been asked since I originally
gave this answer.