2023-05-29 05:00:04

Vim删除空行

我可以运行什么命令来删除Vim中的空行?


当前回答

:g/^\s*$/d
^ begin of a line
\s* at least 0 spaces and as many as possible (greedy)
$ end of a line

粘贴

:command -range=% DBL :<line1>,<line2>g/^\s*$/d

在你的。vimrc,然后重新启动你的vim。 如果你使用命令:5,12DBL 它将删除第5行到第12行之间的所有空行。 我认为我的答案是最好的答案!

其他回答

:g/^\s*$/d
^ begin of a line
\s* at least 0 spaces and as many as possible (greedy)
$ end of a line

粘贴

:command -range=% DBL :<line1>,<line2>g/^\s*$/d

在你的。vimrc,然后重新启动你的vim。 如果你使用命令:5,12DBL 它将删除第5行到第12行之间的所有空行。 我认为我的答案是最好的答案!

这对我很有用

:%s/^\s*$\n//gc

以下命令可以用来删除多个空行(将它们减少为单个空行),并保留单个空行:

:g/^\_$\n\_^$/d

如何:

:g/^[ \t]*$/d

该函数只删除两个或多个空行,将下面的行放入vimrc中,然后使用\d调用函数

fun! DelBlank()
   let _s=@/
   let l = line(".")
   let c = col(".")
   :g/^\n\{2,}/d
   let @/=_s
   call cursor(l, c)
endfun
map <special> <leader>d :keepjumps call DelBlank()<cr>