开发者

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

开发者 https://www.devze.com 2023-03-09 20:58 出处:网络
I\'m having some trouble with vim, gg=G doesn\'t remove extra newlines, I\'m trying with :%s/\\(\\n\\)\\n\\+/\\1/g

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

精彩评论

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

关注公众号