【发布时间】:2017-01-08 20:46:00
【问题描述】:
具体问题
说明
在注册者o记录了想要的动作后,我将整个宏粘贴到我的~/.vimrc并分配如下(直接粘贴映射不正确显示)
预期行为
我想使用此宏为自己创建一个新的“注释行”,该“注释行”引导一个新的脚本部分,其格式使该部分的名称居中。填充“节标题”后,我想在新行中进入插入模式。
在下面的屏幕记录中,我测试了 @o 和 @p$ on the word "time". The second attempt with@p` 是否正常工作。
问题(特别是在 Windows 机器上)
如您所见,@o 映射让我使用了垃圾短语,这些短语曾是我对宏的定义的一部分。这是否与^M 运算符有关?而且,如何修复使用* 填充行的@o 映射?
这两个映射在 Linux 系统上运行良好。 (不知道为什么,因为我已经在 Windows 机器上记录并粘贴了宏定义。)这在使用 MacVim 的 Mac 上似乎也不是问题。
一般性问题
- 有没有办法正确替换
^M运算符(用于<CR>,或“Enter”键)? - 有没有办法正确替换
^[运算符(用于<ESC>,或“Escape”键)? - 这些奇怪的击键表示是否有系统的映射列表,由“记录”功能通过
q记录。
解决方案
用\r 替换宏定义中的^M 标记。并且,将^[ 替换为\x1b,用于ESC 键。映射固定如下:
let @o = ":center\ri\r\x1bkV:s/ /\*/g\rJx50A\*\x1b80d|o"
let @p = ":center\ri\r\x1bkV:s/ /\"/g\rJx50A\"\x1b80d|o"
键码/映射的完整列表?方法一:通过十六进制代码。
感谢 Zbynek Vyskovsky,图片清晰。对于人们可能想到的任何键,Vim 都将其 ASCII 值作为“面值”。 (诀窍是使用以\x 开头的转义子句,其中x 用作连接到十六进制值的引导键/字符串/字符。)因此,对应列表(不完整)如下:
-
输入 ---
\x0d---\r -
ESC ---
\x1b---\e
Vim 原生解决方案
:help expr-quote 偶然提供了以下特殊字符列表。这将作为一般形式的原始问题的明确答案。
string *string* *String* *expr-string* *E114*
------
"string" string constant *expr-quote*
Note that double quotes are used.
A string constant accepts these special characters:
\... three-digit octal number (e.g., "\316")
\.. two-digit octal number (must be followed by non-digit)
\. one-digit octal number (must be followed by non-digit)
\x.. byte specified with two hex numbers (e.g., "\x1f")
\x. byte specified with one hex number (must be followed by non-hex char)
\X.. same as \x..
\X. same as \x.
\u.... character specified with up to 4 hex numbers, stored according to the
current value of 'encoding' (e.g., "\u02a4")
\U.... same as \u but allows up to 8 hex numbers.
\b backspace <BS>
\e escape <Esc>
\f formfeed <FF>
\n newline <NL>
\r return <CR>
\t tab <Tab>
\\ backslash
\" double quote
\<xxx> Special key named "xxx". e.g. "\<C-W>" for CTRL-W. This is for use
in mappings, the 0x80 byte is escaped.
To use the double quote character it must be escaped: "<M-\">".
Don't use <Char-xxxx> to get a utf-8 character, use \uxxxx as
mentioned above.
Note that "\xff" is stored as the byte 255, which may be invalid in some
encodings. Use "\u00ff" to store character 255 according to the current value
of 'encoding'.
Note that "\000" and "\x00" force the end of the string.
【问题讨论】: