- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近一直在玩 vim 宏(目前在 MacVim 中),有时我喜欢使用例如显式地将宏分配到寄存器中:let @a='(macro keystrokes)'
.这通常工作正常,但我发现一个奇怪的行为,每当我分配一个以回车符/^M 结尾的字符串值时,vim 会在将它放入寄存器之前自动在末尾添加一个换行符/^J,这会影响执行宏!
示例:假设我录制了一个简单的宏,它进入插入模式,键入“嘿”,退出插入模式,然后按两次 Enter 进入 2 行。我通过输入 qaihey<Escape><Enter><Enter>q
将其记录到寄存器 @a 中,它将以下内容存储在@a中:
ihey^[^M^M
到目前为止一切顺利,通过键入 @a
执行宏做它应该做的。另一种非常好的方法可以让这个相同的宏进入寄存器@a 是通过将整个东西( ihey<Ctrl-V><Escape><Ctrl-V><Enter><Ctrl-V><Enter>
)键入缓冲区然后用 "ay
猛拉它——最终结果是一样的。但奇怪的是——假设我只是想使用 let
将该字符串直接分配给@a。声明:
:let @a='ihey^[^M^M'
现在如果我输入 :reg
看看它说的值(value)有一个额外的^J
最后出于某种原因:
"8 ...
"9 ...
"a ihey^[^M^M^J
"b ...
有额外的^J
导致它在我执行宏时多走一行,所以它实际上改变了行为。
有人知道为什么要添加这个额外的字符吗?任何人都知道我如何获得以 ^M
结尾的字符串值进入寄存器(或任何变量),而无需额外的 ^J
被添加?
最佳答案
一些快速检查 vim 帮助文件说:
:let @{reg-name} = {expr1} *:let-register* *:let-@*
...
If the result of {expr1} ends in a <CR> or <NL>, the
register will be linewise, otherwise it will be set to
characterwise.
换句话说,以回车符结尾的字符串将使 Vim 将其解释为行结尾
快速谷歌搜索 this来自 VimTips wiki:
Note however, that the above method using :let will not work as expected for any macros which you make ending in a < CR > or < NL > character (carriage return or newline). This is because, as documented in :help :let-@, Vim will treat the register as "linewise" under these conditions. The reason for this is to make registers set with :let act "the right way" when dealing with yanked/deleted text, but it can cause headaches when dealing with recorded macros. Possible workarounds include using the setreg() function or adding "no-op" commands to the end of the macro, such as a < ESC >. See the discussion on vim_dev about unexpected behavior of the :let command for details.
因此您有几个选择:使用 setreg()
或在使用 let
时向字符串添加某种无操作序列 (< ESC >)。
关于macros - 如何在不添加 <LF> 的情况下将以 <CR> 结尾的字符串分配给 vimscript 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20171382/
我正在使用 Ubuntu 15.04 和 vim-gnome 7.4。 当我运行时: vim --version | grep -i +ruby 它返回: +ruby 基于:Vim Ruby Supp
我正在编写一个测试脚本,它将简单地运行带有几个参数的 *.EXE 文件,然后将结果输出到一个文件。我有一个 *.sh 测试脚本可以正确运行测试(但需要手动更新更多测试)。此脚本中的行如下所示: bla
我想知道之间的区别(如果可能的话提供示例)CR LF (Windows)、LF (Unix) 和 CR (Macintosh) 换行符类型。 最佳答案 CR和LF是控制字符,分别编码为0x0D(十进制
我正在尝试使用 PHP 正则表达式来查找 CR 3492161 或 cr 3492161。我尝试使用以下正则表达式,但它不起作用。请求你的帮助。 :-) 'CR\s/^\d{7}$/' 'CR\h/^
交换换行符(例如通过某些文本编辑器)是否会破坏 javascript 代码? 最佳答案 两个控制字符都是valid line breaks .事实上你甚至不需要换行符。这只是为了更好的可读性。除了在字
这个问题已经有答案了: How to correct variable overwriting misbehavior when parsing output? (3 个回答) 已关闭 5 年前。 我
好的,我计划创建一个文件来存储我将导入到程序中的数据。该程序将为 Linux、Windows 和可能的 Mac 编译。 现在我真正想知道的是,由于这些文件中的换行符,我是否需要这些数据文件略有不同,或
建议以下计划: import java.io.StringReader; import javax.xml.transform.OutputKeys; import javax
我正在尝试将“,”和“\n”放入文件中。所有值都是 0 ,除了 4, 9, 14, 19, 23...我放置 ',' 和 '\n' 但是输出即将到来: 0000,0000,0000,0000,0000
我一直在尝试通过 Python 学习 Open ERP 模块开发。我想出了一个我认为我不理解的源代码。我在浏览时尝试了几个互联网链接,但找不到有用的链接。我非常需要理解这一点。 cr.execute(
我目前正在使用 JSP 生成一些 vCard。我发现一些平台无法识别这些生成的 vCard,除非它们的行由回车符 (CR) 分隔,而 JSP 似乎默认只使用换行符 (LF) 来分隔行。 你们知道有什么
验证用户时出现以下错误:purchase_user@purchase 失败。 MongoDB-CR 身份验证失败。当我通过浏览器访问网络服务时,用户文档中缺少凭据。 但我能够从 mongo 验证 pu
首先我想说我已经阅读了 this post但是我仍然对 CR line terminators 有问题. 有一个文件叫build_test.sh , 我编辑在 leafpad它可以直接显示在 Vim
我最近才开始使用 vim,并且在添加大量有用的插件时玩得很开心。问题是,在设置所有插件期间的某个时候,我没有注意到 enter 键的映射停止正常工作。在插入模式下,当我按下 Enter 键时,如果当前
我正在寻找一种在 vim 中突出显示 ^M(CR) 的方法。 最佳答案 确保文件格式设置为 unix 或 mac 我的是: set fileformats=unix,mac 如果是 DOS,您将看不到
假设我有一个程序(例如在Perl中),将这样的内容写入STDOUT: print "123\t- 456"; print "\r+\n"; 在我的屏幕上,我看到以下结果: 123 + 456
我正在编写一个在特定条件下自动插入一些文本的函数。当我尝试模拟 Enter press 时,我卡在了某个部分。我想出了这个(显而易见的)代码: execute "normal! a\" 问题是它破坏了
我有一个 HTML 页面中的元素。我正在用 JavaScript 向其中写入数据,并想稍后检查用户是否更改了文本。但是,如果数据包含任何回车符,它们似乎会被悄悄删除,因此将从文本区域读取的文本与应该存
各位正则表达式专家, 我有一个充满表达式的平面文件,例如: SELECT * FROM CONVENIENT_ONE_LINE_QUERY "SELECT * FROM THIS_QUERY WHER
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我是一名优秀的程序员,十分优秀!