2011-05-31 86 views
4

我有一些麻烦用vim替换它,GG = G不排除额外的新行,我与VIM SED匹配多于一个换行符和一个换行符

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

努力,但它不是在整个文件中工作。任何帮助赞赏。

+0

+1一个有趣的问题。我没有意识到'\ n'很难在'vim'中匹配 – 2011-05-31 02:09:12

回答

4

这应该在vim工作...

:g/^\s*$/d

0
" Put the function bellow in your vimrc 
" remove extra newlines keeping the cursor position and search registers 
fun! DelBlank() 
    let [email protected]/ 
    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> 
相关问题