2016-11-26 70 views
0

目標文本文件。如何在位於`{`和`}`之間的行中添加四個空格?

<style type="text/css"> 
    #wrap{ 
    height: 550px; 
    width: 660px; 
    } 
    #wrap ul{ 
    list-style: none; 
    } 
    #wrap li{ 
    border-radius:3px; 
    cursor:pointer; 
    } 
    #wrap{ 
    height: 550px; 
    width: 660px; 
    } 
    #wrap ul{ 
    list-style: none; 
    } 
    #wrap li{ 
    border-radius:3px; 
    cursor:pointer; 
    } 
</style> 

現在我想在這{}之間找到行的開頭添加四個空格,使顯示爲低於上述。

<style type="text/css"> 
    #wrap{ 
     height: 550px; 
     width: 660px; 
    } 
    #wrap ul{ 
     list-style: none; 
    } 
    #wrap li{ 
     border-radius:3px; 
     cursor:pointer; 
    } 
    #wrap{ 
     height: 550px; 
     width: 660px; 
    } 
    #wrap ul{ 
     list-style: none; 
    } 
    #wrap li{ 
     border-radius:3px; 
     cursor:pointer; 
    } 
</style> 

也許這是愚蠢的執行所有commonds做任務。

3,4s/^/ /g 
7s/^/ /g 
10,11s/^/ /g 
14,15s/^/ /g 
18s/^/ /g 
21,22s/^/ /g 

有沒有更簡單更聰明的方法呢?

回答

0

假設您的文檔的文件類型被正確設置到html和您的製表設置正確,以下就足夠了:

:2,23norm == 

但是,直接回答你的問題,你應該針對包含:行:

:2,23g/:/s/^/ /

如果不想手動定義範圍,你可以這樣做:

vit:g/:/s/^/ /

它自動插入'<,'>範圍。

-1
:g/^[^<#}]/ normal >> 

說明:

: ........... command 
g ........... global command (executes on the following pattern 
/........... start search pattern 
^ ........... beginning of line 
[^ ] ........ denied list 
<#} ......... denied chars 
/........... search pattern's end 
normal ...... execute in normal mode 
>> .......... indentation 

如果這種模式是太經常,你可以把地圖上的~/.vimrc文件,像這樣:

map <F2> <esc>:g/^[^<#}]/ normal >><cr> 

<cr>意味着回車

+0

驗證reg模式中有一些錯誤。 –

相關問題