如何在vim indentexpr中使用execut
我试图在vim indentexpr中使用execut,但代码不足如何在vim indentexpr中使用execut,vim,Vim,我试图在vim indentexpr中使用execut,但代码不足 function! AddSpace(lnum,str) while len(getline(a:lnum)) < 80 execut a:lnum . "," . a:lnum . "s/".a:str."/ ".a:str endwhile endfunction function! GetIndent() if getline(v:lnum) =~ ';' c
function! AddSpace(lnum,str)
while len(getline(a:lnum)) < 80
execut a:lnum . "," . a:lnum . "s/".a:str."/ ".a:str
endwhile
endfunction
function! GetIndent()
if getline(v:lnum) =~ ';'
call AddSpace(v:lnum,";")
endif
...
return ...
endfunction
setlocal indentexpr=GetIndent()
它很好用
也许“execut”在indentexpr中不起作用
是否仍有方法使用“execut”向文件中插入空间?
或者有没有更好的方法在不移动光标的情况下完成插入
谢谢你的帮助
'indentexpr'
并不意味着直接修改文本。事实上,明确禁止在计算表达式时修改文本。默认情况下,错误消息被抑制,因此您不会得到错误指示,但表达式在遇到文本修改时会停止
AddSpace函数应该返回要添加的空间数,而不是实际添加空间。注意,您不需要while循环,只需使用减法计算所需的空格数即可
有关详细信息,请参见
:帮助'indentexpr'
。如果您非常想缩短执行
,为什么不将其缩短为exe
?exe听起来像是来自microsoft的东西……如果我想获得控制台.log(a)代码>当缩进console.log时(a)代码>?我只能生成另一个脚本?缩进只影响行首的空白。如果要影响整行,则需要自定义映射,或者可能需要formatexpr。
call AddSpace(3,";")