請問大家
如何將各Arithmetic operators 算術運算子及邏輯運算子
的前後加上空格.
像是
a=b;
應為
a = b;
而對於邏輯運算子也應該用上.
不知大家都是如何去處理的?
目前都是寫完後再用搜尋取代方式(:%s/=/ = /gc)
但這樣做跟一行一行檢查一樣,而且不方便.
我想這部份可能需要用Regexp 常規表示式.
對於這個Regexp如何表示?
(+,-,*,/,+=,-=,/=,*= and ==,!=,<,>,...)
並避開一些command用的(//,/****,*/)
---------------------------------------------------------
因為,突然工作上被要求這樣..
雖然在原本的vim上,我也會有vim內建的"auto format", select all , press “=”
但是卻不能夠,滿足上述的要求,所以上網查詢了相關的"issue"。
很快地就得到了" Artistic" tool.
像是 opeator –pad
在使用原本的auto format
而使用" Artistic" tool.
如此,
1.各 opeator 和 operand 之間, 都會加上一個space pad
2.設定各indent 4 space
3.單行的判斷式,會自己加上一個brack
A.
download Artistic
http://sourceforge.net/projects/astyle/
B.steup (on windows to vim)
1.to compress the
2. select the bin document
3.copy the astyle.exe to vim director
同使用diff.exe .方式
4.
在vimrc中加入
map ,fc <Esc>:%!astyle --style=ansi --pad-oper --min-conditional-indent=0 --max-code-length=120 --add-brackets --break-blocks --delete-empty-lines --indent=spaces=4<CR>
5.當然,你也可以直接使用下command 去執行astyle (也可寫成batch file)
同astyle --style=ansi --pad-oper --min-conditional-indent=0 --max-code-length=120 --add-brackets --break-blocks --delete-empty-lines --indent=spaces=4 <input file name>
Reference :
Artistic :
http://astyle.sourceforge.net/astyle.html#_pad-oper
Automatically formatting (adding spaces:
http://vim.1045645.n5.nabble.com/Automatically-formatting-adding-spaces-td1190147.html
工具使用] 代码排版 astyle
http://godbms.blogspot.tw/2012/02/astyle.html
代码排版工具——astyle
http://www.shui6.com/viewthread.php?tid=353
http://stackoverflow.com/questions/2355834/auto-format-c-file-in-vim