1. 程式人生 > >vim+Vundle+vim-autoformat+astyle格式化程式碼

vim+Vundle+vim-autoformat+astyle格式化程式碼

Plugin 'Chiel92/vim-autoformat'
" All of your Plugins must be added before the following linecall vundle#end() " requiredfiletype plugin indent on " required" To ignore plugin indent changes, instead use:"filetype plugin on"" Brief help" :PluginList - lists configured plugins" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate" :PluginSearch foo - searches for foo; append `!` to refresh local cache" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal"" see :h vundle for more details or wiki for FAQ" Put your non-Plugin stuff after this line
3.重啟vim,在vim中執行:PluginInstall,安裝vim-autoformat

4.安裝 astyle

sudo apt-get install astyle

也可以安裝其他語言對應的格式化外掛,安裝完成後,會執行預設格式化設定

5.自定義astyle格式化,在.vimrc中新增如下程式碼

let g:formatdef_my_cpp = '"astyle --style=google"'
let g:formatters_cpp = ['my_cpp']
au BufWrite * :Autoformat

程式碼儲存時,會自動進行格式化