开发者

vim sed match more than one newline and replace it with one newline

I'm having some trouble with vim, gg=G doesn't remove extra newlines, I'm trying with

:%s/\(\n\)\n\+/\1/g

but it's not working in the whole file. Any help appr开发者_Go百科eciated.


This should work in vim...

:g/^\s*$/d


" Put the function bellow in your vimrc
" remove extra newlines keeping the cursor position and search registers
fun! DelBlank()
   let _s=@/
   let l = line(".")
   let c = col(".")
   :g/^\n\{2,}/d
   let @/=_s
   call cursor(l, c)
endfun
" the function can be called with "leader" d see :h <leader>
map <special> <leader>d :keepjumps call DelBlank()<cr>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜