编写一个vim运算符,用于删除行前的空白

编写一个vim运算符,用于删除行前的空白,vim,Vim,我想写一个vim命令来删除一行之前的空白。我尝试了两种不同的方法: "delete the whitespace before a line nnoremap gll <esc>^d0 "delete the whitespace for the lines in visual block vnoremap gl <esc>:'<,'>normal ^d0<cr> “删除行前的空白 nnoremap gll^d0 “删除可视块中行的空白

我想写一个vim命令来删除一行之前的空白。我尝试了两种不同的方法:

"delete the whitespace before a line
nnoremap gll  <esc>^d0

"delete the whitespace for the lines in visual block
vnoremap gl   <esc>:'<,'>normal ^d0<cr>
“删除行前的空白
nnoremap gll^d0
“删除可视块中行的空白
vnoremap gl:“只需编写:

nnoremap gll :normal ^d0<CR>
nnoremap gll:normal ^d0

将使
2gll
做你想做的事。

如果我理解正确,你正在寻找命令
:left

例如,将
gll
映射到
:left
,应该可以工作


对于可视化映射,
:left
也有效。

快速脏映射:

nno gll :<C-U>exe ',+' . (v:count-1) . 'left'<CR>
nno gll:exe',+'。(五:计数一)左撇子
说明:

<C-U>   remove the range automatically added to the command line
exe     execute a string as a normal command
',+' . (v:count-1) 
        build a string containing (1) a range of the current line
        to the v:count-1 line (v:count holds the count given to
        the mapping)
left    and (2) the command to left-align text
<CR>    execute the string
删除自动添加到命令行的范围
exe将字符串作为普通命令执行
',+' . (五:计数1)
生成包含(1)当前行范围的字符串
到v:count-1行(v:count保存给定给
(地图)
左对齐和(2)左对齐文本的命令
执行字符串
重读你的问题,也许你想定义 运算符映射:

fun! Left(type)
    '[,'] left
endfun
nno gl :set opfunc=Left<CR>g@
有趣!左(类型)
“[,”]左
结束
nno gl:set opfunc=Leftg@
请参阅
:帮助:地图操作员

g@
是一个正常模式命令,它在调用
'opfunc'
设置指定的函数之前等待运动。在函数中,
'[
']
标记指的是运动定义的起始线和结束线

现在可以在运动命令之前使用
gl
。 因此,
gll
将删除当前行的缩进,
glap
将删除当前行的缩进 当前段落的缩进,等等。你需要做一些额外的工作 支持可视模式,但在帮助文件中有明确的说明


最后,我实现这一点的方法很简单,例如,
是的,我认为OP希望映射像正常模式操作符一样工作。