2021年3月27日 星期六

在vs code裡加入clang-format(google sytle)的功能

目的:

         在vs code的ide底下設定google coding sytle的clang-format功能。

步驟:

         1. 安裝clang-format
                若是windows則安裝llvm;若是linux系統(ubuntu)則用apt-get install clang-format

         2.. 安裝vs code的clang-format套件
         3. 到檔案->偏好設定->設定
         4.  在search settings鍵入clang-format
         5. 將Clang-format: Fallback Style以及Clang-format:Style設定為Google

         6. 最後在編輯的c程式裡面可以就由滑鼠右鍵選擇Format Document,這樣就會編排成Google的coding sytle。


   

參考資料:


2021年3月20日 星期六

在vim加入clang-format的功能

 目的:

使用clang-format官網提供的方法加入排版功能

平台:

ubuntu 18.04

作法:

1. 在clang-format的官網裡面的Vim Integration有提到需要有clang-format.py這個檔案並可從這裡獲得。並且需要特過指令:

        sudo apt-get install clang-format

下載clang-format這個工具。

2. 從.vimrc加入以下內容

        imap <c-f> <c-o>:py3file ~/clang-format.py<cr>

3. 之後便可在vim的insert mode透過ctrl-f使目前的程式編排成google的coding style。


參考資料:

1. Clang 12 documentation CLANGFORMAT

make bootable usb

 在ubuntu環境下製作linux的開機usb


 1.用fdisk -l 確認要用的usb是否被掛載,如果有請用umount指令卸下
 2. 啟動  Startup Disk Creator ,指定你系統的iso檔以及要製作的usb
 3. 按下Make Startup Disk啟動製作程序
 4.最後成功後會有視窗跳出提醒

 在ubuntu環境下製作windows的開機usb


1.用fdisk -l 確認要用的usb是否被掛載,如果有請用umount指令卸下
2.下載woeusb->apt-get install woeusb
3. 開啟woeusbgui
4. 選定iso檔和要燒錄的隨身碟
5. 成功後即可使用

參考資料: 

在vim中建立clang-format功能

 目的: 

在vim中加入clang-format的附件功能,並以google當作coding sytle。

步驟:

1. 在vim加入套件管理程式Vundle

    1-1. 下載vundle模組

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

    1-2. 下載clang-format程式和vundle的模組

        sudo apt-get install clang-format
        git clone https://github.com/rhysd/vim-clang-format.git  ~/.vim/Vundle.vim/vim-clang-format

    1-3. 加入vimrc並改為特定的內容

        vim ~/.vimrc

       內容如下:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/Vundle.vim/
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
call vundle#end()            " required
filetype plugin indent on    " required


    1-4. 一般模式下輸入:PlugInstall安裝Vundle模組的部份,若是成功會在右下角暗道Done!的字樣。

2. 增加clang-format的功能和vim相關的外掛模組

    2-1. 安裝clang-format

        sudo apt-get install clang-format

    2-2.在vimrc加入clang-format模組部份:

        Plugin 'rhysd/vim-clang-format'

    2-3.一般模式下輸入:PlugInstall安裝Vundle模組的部份,若是成功會在右下角暗道Done!的字樣。


    2-4.在.vim同的同層的資料夾下使用指令

        clang-format -style=google -dump-config > ./.clang-format 

        建立google的coding style規則。

3. 為了更方便使用,將vim的clang-format加入快捷鍵(ctrl+f)的功能。為此要在vimrc裡面加入以下內容:

        let g:clang_format#command = 'clang-format'
        nmap <c-f> :ClangFormat<cr>
        autocmd FileType c ClangFormatAutoEnable
        let g:clang_format#detect_style_file = 1

4. 最終的vimrc如下:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/Vundle.vim/
call vundle#begin()

Plugin 'gmarik/Vundle.vim'
Plugin 'rhysd/vim-clang-format'
call vundle#end()            " required
filetype plugin indent on    " required

let g:clang_format#command = 'clang-format'
nmap <c-f> :ClangFormat<cr>
autocmd FileType c ClangFormatAutoEnable
let g:clang_format#detect_style_file = 1

5. 最後即可在自己的c語言裡面藉由ctrl+f將程式排版成符合google的coding style。


參考資料:

1. Linux下vim配置clang-format的方法

2. Vim 套件管理程式 Vundle

3. [Vim] Vim 的插件管理工具 Vundle