2011-05-31 43 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> 
相關問題