在使用非拉丁语言(例如希腊语)书写时,如何避免在英文键盘布局与输入 Vim 命令之间不断切换? [英] How to avoid constant switching to and from English keyboard layout to type Vim commands when writing in non-Latin language (e.g., Greek)?

查看:20
本文介绍了在使用非拉丁语言(例如希腊语)书写时,如何避免在英文键盘布局与输入 Vim 命令之间不断切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在认真尝试 Vim 编写我的 Python 应用程序.然而,事实证明 Vim 非常灵活,我想用它作为我的主要编辑器来编写律师/法律文件.问题是我的母语不是英语而是希腊语.因此,我已映射 Alt+Shift 以在英语和希腊语键盘布局之间切换.

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.

我遇到的问题是,每次我想输入 Vim 命令(返回英文)时,我都必须按 Alt+Shift.所以当我输入我的文档时它是 Alt+Shift,然后 Alt+Shift 再次输入 Vim 命令.这违背了使用 Vim 的初衷,至少在使用速度方面是如此.

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.

所以我的问题很简单:有什么方法可以避免那些频繁的 Alt+Shift 键盘布局更改,只是为了在使用非拉丁语言编写时输入 Vim 命令(例如,希腊语)?

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)?

推荐答案

这个问题可以在 keymap 选项的帮助下解决.它允许定义在模式中使用的备用键盘映射需要文本输入.

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.

要在插入时在默认和备用键盘映射之间切换,替换,或命令行模式(但不是普通模式),使用Ctrl+^(Ctrl+6).更改键盘映射仅影响文本输入;键盘行为无论当前的键盘映射设置如何,正常模式都保持不变.可以离开插入模式用希腊语书写并立即使用无需切换到不同键盘的正常模式键绑定布局.如果然后返回到插入模式,或者,例如,开始输入 / 进行搜索,Vim 将键盘映射切换回希腊语自动.

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 Greek automatically.

记住在这些文本输入模式中使用的当前键盘映射在切换到其他模式之间.唯一的例外行为是针对命令行模式进行的,该模式始终以默认键盘映射,因为大多数时候需要输入 Ex命令(ASCII).设置 keymap 选项后,用户应该在 Vim 中工作,同时将系统键盘布局设置为英语使用 Ctrl+^ 切换 Vim 键盘映射(而不是系统范围的布局开关).

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 supposed to work in Vim keeping system keyboard layout set to English while switching Vim keymap with Ctrl+^ (instead of the system-wide layout switch).

要永久启用 UTF-8 希腊语键盘映射,请添加以下内容行到您的 .vimrc 文件.

To enable, say, the UTF-8 Greek keymap permanently, add the following line to your .vimrc file.

:set keymap=greek_utf-8

对于大量语言有许多预定义的键盘映射,您可以使用 :e $VIMRUNTIME/keymap 在 Vim 中浏览它们.笔记通常为一种语言提供多个键盘映射仅在字符编码上有所不同,因此任何人都可以选择一种适合他们的配置.

There are many predefined keymaps for a large set of languages, you can browse them all in Vim itself using :e $VIMRUNTIME/keymap. Note that 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:

:set iminsert=0 imsearch=-1

详细解释见:help iminsert:help imsearch.

还有一种特殊的语言模式,如果我没记错的话,早于 keymap 在 Vim 中引入.它允许实现类似于 keymap 通过手动提供的行为指定对应于键盘上的键的字母对要保存在 langmap 选项中的长字符串.个人——我的母语也不是英语——我更喜欢(并推荐)使用keymap 方式代替.

There is also a special language mode that, if I am not mistaken, was introduced in Vim earlier than keymap. It allows to achieve the behaviour similar to the one provided by keymap through manually specifying letter pairs that correspond to the keys on keyboard in a long string to be saved in the langmap option. Personally—my native language is not English, too—I prefer (and recommend) using the keymap way instead.

总而言之,我要强调的是,以上所有内容都是平等的适用于 Vim 拥有的任何其他语言(或可以配置为有)一个键盘映射.

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.

另见我的回答对类似问题'Vim烦恼"使用键盘布局’从我最初开始就被问到给出了这个答案.

See also my answer to a similar question ‘Vim "annoyance" with keyboard layouts’ that has been asked since I originally gave this answer.

这篇关于在使用非拉丁语言(例如希腊语)书写时,如何避免在英文键盘布局与输入 Vim 命令之间不断切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆