vim+Vundle+vim-autoformat+astyle格式化代碼__vim

來源:互聯網
上載者:User

Vundle是vim外掛程式管理工具,用來管理vim外掛程式,vim-autoformat是代碼格式化外掛程式


1.安裝Vundle(參考點擊開啟連結)

$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

2.在.vimrc檔案中添加如下內容

set nocompatible              " be iMproved, requiredfiletype off                  " required" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')" let Vundle manage Vundle, requiredPlugin 'VundleVim/Vundle.vim'
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

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


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.