首頁 > 軟體

Vim中Tab與空格縮排

2020-06-16 16:47:28

vim縮排引數解析

縮排用 tab 製表符還是空格,個人愛好問題。但是在大多專案中,習慣使用空格。關於縮排,vim中可以通過如下四個引數進行設定

set tabstop=4
set softtabstop=4
set shiftwidth=4
set noexpandtab / expandtab

解析:
tabstop
表示按一個tab之後,顯示出來的相當於幾個空格,預設的是8個。
softtabstop
表示在編輯模式的時候按退格鍵的時候退回縮排的長度。
shiftwidth
表示每一級縮排的長度,一般設定成跟 softtabstop 一樣
expandtab與noexpandtab
當設定成 expandtab 時,縮排用空格來表示,noexpandtab 則是用製表符表示一個縮排。個人習慣使用 `set expandtab`
 #標誌tab與空格
 在vim中,預設情況下,沒法區分空格和縮排,所以我們需要設定,使其能夠區分。我的設定如下
 ```
set list?
set listchars=tab:?-,eol:??,trail:-?

vim設定

filetype on " required! /** 從這行開始,vimrc設定 **/
filetype plugin indent on
"autocmd FileType php set omnifunc=phpcomplete#CompletePHP
" 讓設定變更立即生效
set backspace=indent,eol,start
set ts=4 sw=4 sts=4 tw=100
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936

set termencoding=utf-8
set encoding=utf-8
autocmd BufWritePost $MYVIMRC source $MYVIMRC
let mapleader=";"
set guifont=YaHei Consolas Hybrid 10
set cursorline  " 十字高亮
set cursorcolumn
set autoindent      " 開啟自動縮排
set smartindent    " 開啟智慧縮排
set smarttab
set showmatch      " 設定括號匹配
 " 開啟實時搜尋功能
 set incsearch
 " " 搜尋時大小寫不敏感
 set ignorecase " " 關閉相容模式
 set nocompatible
 " " vim 自身命令列模式智慧補全
 set wildmenu
 " 顯示游標當前位置
 set ruler
 " 高亮顯示搜尋結果
 set hlsearch
 " 基於縮排或語法進行程式碼折疊
 "set foldmethod=indent
 set foldmethod=syntax
 " 啟動 vim 時關閉折疊程式碼
 set nofoldenable
 syntax enable
 " 允許用指定語法高亮配色方案替換預設方案
 syntax on
 set background=dark
 "colorscheme solarized
 " 配色方案
 colorscheme molokai
 let g:molokai_original = 1
" let g:rehash256 = 1
 "let g:Powerline_colorscheme='molokai256'
set expandtab
set list
set listchars=tab:?-,eol:??,trail:-
"set listchars=tab:?-,eol:?,trail:-

" 基於縮排或語法進行程式碼折疊
" "set foldmethod=indent
 set foldmethod=syntax
" " 啟動 vim 時關閉折疊程式碼
 set nofoldenable
 set term=screen-256color

 set rtp+=~/.vim/bundle/Vundle.vim
 autocmd vimenter * NERDTree
 set nu
 call vundle#rc()

 


  " let Vundle manage Vundle

  " required!

  Bundle 'gmarik/vundle'
"

"
"  " My Bundles here: /* 外掛設定格式 */
"
"  "
"
"  " original repos on github
"  (Github網站上非vim-scripts倉庫的外掛,按下面格式填寫)
"
  Bundle 'kshenoy/vim-signature'
"  Bundle 'Valloric/YouCompleteMe'
  Bundle 'tpope/vim-fugitive'

  Bundle 'Lokaltog/vim-easymotion'
  let g:EasyMotion_smartcase = 1
  let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
  map <Leader><leader>h <Plug>(easymotion-linebackward)
  map <Leader><Leader>j <Plug>(easymotion-j)
  map <Leader><Leader>k <Plug>(easymotion-k)
  map <Leader><leader>l <Plug>(easymotion-lineforward)
  " 重複上一次操作, 類似repeat外掛, 很強大
  map <Leader><leader>. <Plug>(easymotion-repeat)
  Bundle 'rstacruz/sparkup'

  Bundle 'tpope/vim-rails.git'

  Bundle 'fholgado/minibufexpl.vim'
  let g:miniBufExplMapWindowNavVim = 1 
  let g:miniBufExplMapWindowNavArrows = 1 
  let g:miniBufExplMapCTabSwitchBufs = 1 
  let g:miniBufExplModSelTarget = 1 
  let g:miniBufExplMoreThanOne=0

 map <F11> :MBEbp<CR>
 map <F12> :MBEbn<CR>
  Bundle 'Lokaltog/vim-powerline'

  Plugin 'scrooloose/nerdcommenter'

  Plugin 'scrooloose/nerdtree'
  Plugin 'derekwyatt/vim-fswitch'

  " vim-scripts repos (vim-scripts倉庫裡的,按下面格式填寫)

  Bundle 'L9'

  Bundle 'FuzzyFinder'

  " non github repos (非上面兩種情況的,按下面格式填寫)

  Bundle 'git://git.wincent.com/command-t.git'

  " ...

  Bundle 'captbaritone/better-indent-support-for-php-with-html'   

    filetype plugin indent on " required! /** vimrc檔案設定結束 **/
    set completeopt=longest,menu
    "
" NERDTree config
map nd :NERDTree
map nc :NERDTreeClose
let g:NERDTreeDirArrows = 1
let g:NERDTreeDirArrowExpandable = '?'
let g:NERDTreeDirArrowCollapsible = '?'
map <F2> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&  b:NERDTreeType == "primary") | q | endif

"    " /** vundle命令 **/
"
"    " Brief help
"
"    " :BundleList - list configured bundles
"
"    " :BundleInstall(!) - install(update) bundles
"
"    " :BundleSearch(!) foo - search(or refresh cache first) for foo
"
"    " :BundleClean(!) - confirm(or auto-approve) removal of unused bundles
"
"    "
"
"    " see :h vundle for more details or wiki for FAQ
"
"    " NOTE: comments after Bundle command are not allowed..

Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx

本文永久更新連結地址https://www.linuxidc.com/Linux/2018-08/153817.htm


IT145.com E-mail:sddin#qq.com