Vim 维姆:“我不知道。”;f";如果可以';我找不到一个角色

Vim 维姆:“我不知道。”;f";如果可以';我找不到一个角色,vim,Vim,我有一个(相当粗糙的)映射,我想用于Jade文件 nmap <leader>jc ^f)Wc$ 进入 其中u是插入模式下的光标 但是,当f找不到)时,它将停止运行序列中的其余操作。有没有办法强迫它继续执行命令序列呢?您似乎需要重新思考一下您的问题 实际上,您的映射非常具体,它表示: jump to the first printable character on the line > jump to the first closing parenthese on the

我有一个(相当粗糙的)映射,我想用于Jade文件

nmap <leader>jc ^f)Wc$
进入

其中u是插入模式下的光标


但是,当
f
找不到
时,它将停止运行序列中的其余操作。有没有办法强迫它继续执行命令序列呢?

您似乎需要重新思考一下您的问题

实际上,您的映射非常具体,它表示:

  jump to the first printable character on the line
> jump to the first closing parenthese on the line
  jump to next WORD
  delete from the cursor to the end of the line
  enter insert mode
跳转到行的第一个右括号
部分就是问题所在。这意味着您的整个映射取决于当前行中是否存在右括号

要么将该映射保持在其当前状态,并在没有意义的地方停止使用它(当当前行上没有右括号时),要么重新定义问题,以便通过通用解决方案解决它

一个可能需要一些脚本的通用解决方案。或者不是

编辑

这是当前宏背后的逻辑:

1. jump to a specific "anchor" on the line
            |
            V
2. perform an action on whatever comes after that anchor 
   on that line
1.  try to jump to a specific "anchor" on the line
            |
            V
2a. if success: perform an action on whatever comes after that anchor 
    on that line
            |
            V
2b. if failure: perform an action on whatever comes after that anchor 
    on that line
结果是:

foo( bar, baz ) lorem ipsum
foo( bar, baz ) lorem ipsum
进入:

很明显,在下面这一行什么都不做:

foo = { "bar" : "baz" }
宏的行为既一致又可预测。它是针对特定情况的,在轻微或完全不同的情况下不会出现问题

这是您希望它的工作方式:

1. jump to a specific "anchor" on the line
            |
            V
2. perform an action on whatever comes after that anchor 
   on that line
1.  try to jump to a specific "anchor" on the line
            |
            V
2a. if success: perform an action on whatever comes after that anchor 
    on that line
            |
            V
2b. if failure: perform an action on whatever comes after that anchor 
    on that line

就像…放置一个在函数中间不做任何事情的条件。< /P> 它将变成:

进入:

以及:

进入:

这会使宏的行为不一致:它可以工作,并且对任何一行文本都有很大的影响。不知怎的,我觉得那不是你想要的

对于记录,
:^f)Wc$
不会“继续”。光标停留在行的第一个可打印字符上,并停在那里,这正是Wc$所做的


实际上,您要求的是类似于
/)\{-,1}
的内容,它将匹配零或1
。但是我对这样一个东西的有用性有严重的怀疑。

您最初的宏一开始就错了,因为它似乎根本不符合您试图解决的问题

您最后给出的两个示例可以使用相同的命令完成:

^WC

Romaill已经试图说服您,您的方法存在一些缺陷

无论如何,如果希望宏在命令失败后继续,则必须将正常模式命令序列拆分为Ex命令(使用
:normal
),因为这些命令不会中止:

nmap <leader>jc :execute 'normal ^f)'<CR>Wc$
nmap jc:execute'normal^f')Wc$

在此上下文中break是什么意思?如果没有
,您希望它做什么?更重要的是:为什么要在没有右括号的文本上使用假定存在右括号的命令?@Conner我希望它继续运行。@davenichols我不知道这是什么意思。你想让它删除第一个空格字符中的所有内容并进入插入模式吗?我知道映射是特定的。我只是想让它像我在正常模式下运行
^f)Wc$
时那样执行。@davenichols,当线路上没有
时,你为什么要执行
f)
呢?我不会。但是我想要一个在任何一种情况下都有效的映射。@davenichols,正如benjifisher所问,您需要认真定义“有效”和“中断”的含义。您的映射在行中的第一个
之后执行一些操作,如果没有
,您希望它执行什么操作?抱歉。我所说的“中断”是指停止继续执行列出的动作/动作。为了清楚起见,我编辑了我原来的问题。为了进一步澄清,我又编辑了一次。但我认为响亮的答案是,我不能强迫vim按照我想要的方式行事。这种方法显然有其缺陷,但是,使用一个命令在
p上产生相同结果的好处这是一个段落,
p.important这是一个重要段落,
p.important(attr='val')这是一个具有属性的重要段落,
p.important(attr='val',attr='val')这是一个具有两个属性的段落
超过了这些缺陷(在我看来),因为目前Jade没有
cit
(更改内部标记)。
foo = { "bar" : "baz" }
foo |
^WC
nmap <leader>jc :execute 'normal ^f)'<CR>Wc$