主頁(yè) > 知識(shí)庫(kù) > 淺談Vim中的Tab與空格縮進(jìn)

淺談Vim中的Tab與空格縮進(jìn)

熱門(mén)標(biāo)簽:地方門(mén)戶(hù)網(wǎng)站 AI電銷(xiāo) 服務(wù)外包 鐵路電話系統(tǒng) 網(wǎng)站排名優(yōu)化 百度競(jìng)價(jià)排名 呼叫中心市場(chǎng)需求 Linux服務(wù)器

vim縮進(jìn)參數(shù)解析

縮進(jìn)用 tab 制表符還是空格,個(gè)人愛(ài)好問(wèn)題。但是在大多項(xiàng)目中,習(xí)慣使用空格。關(guān)于縮進(jìn),vim中可以通過(guò)如下四個(gè)參數(shù)進(jìn)行配置

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

解析:

tabstop

表示按一個(gè)tab之后,顯示出來(lái)的相當(dāng)于幾個(gè)空格,默認(rèn)的是8個(gè)。

softtabstop

表示在編輯模式的時(shí)候按退格鍵的時(shí)候退回縮進(jìn)的長(zhǎng)度。

shiftwidth

表示每一級(jí)縮進(jìn)的長(zhǎng)度,一般設(shè)置成跟 softtabstop 一樣

expandtab與noexpandtab

當(dāng)設(shè)置成 expandtab 時(shí),縮進(jìn)用空格來(lái)表示,noexpandtab 則是用制表符表示一個(gè)縮進(jìn)。個(gè)人習(xí)慣使用 `set expandtab`

#標(biāo)志tab與空格

在vim中,默認(rèn)情況下,沒(méi)法區(qū)分空格和縮進(jìn),所以我們需要配置,使其能夠區(qū)分。

我的配置如下

``` 
set list↩ 
set listchars=tab:▸-,eol:↩︎,trail:-↩ 

更多vim配置可參考:https://github.com/yangyangwithgnu/use_vim_as_ide

附上自己的vim配置

filetype on " required! /** 從這行開(kāi)始,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   " 打開(kāi)自動(dòng)縮進(jìn)
set smartindent   " 打開(kāi)智能縮進(jìn)
set smarttab 
set showmatch    " 設(shè)置括號(hào)匹配
 " 開(kāi)啟實(shí)時(shí)搜索功能
 set incsearch
 " " 搜索時(shí)大小寫(xiě)不敏感
 set ignorecase " " 關(guān)閉兼容模式
 set nocompatible
 " " vim 自身命令行模式智能補(bǔ)全
 set wildmenu
 " 顯示光標(biāo)當(dāng)前位置
 set ruler
 " 高亮顯示搜索結(jié)果
 set hlsearch
 " 基于縮進(jìn)或語(yǔ)法進(jìn)行代碼折疊
 "set foldmethod=indent
 set foldmethod=syntax
 " 啟動(dòng) vim 時(shí)關(guān)閉折疊代碼
 set nofoldenable
 syntax enable
 " 允許用指定語(yǔ)法高亮配色方案替換默認(rèn)方案
 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:-

" 基于縮進(jìn)或語(yǔ)法進(jìn)行代碼折疊
" "set foldmethod=indent
 set foldmethod=syntax
" " 啟動(dòng) vim 時(shí)關(guān)閉折疊代碼
 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網(wǎng)站上非vim-scripts倉(cāng)庫(kù)的插件,按下面格式填寫(xiě))
"
  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)
  " 重復(fù)上一次操作, 類(lèi)似repeat插件, 很強(qiáng)大
  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> :MBEbpCR>
 map F12> :MBEbnCR>
  Bundle 'Lokaltog/vim-powerline'

  Plugin 'scrooloose/nerdcommenter'

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

  " vim-scripts repos (vim-scripts倉(cāng)庫(kù)里的,按下面格式填寫(xiě))

  Bundle 'L9'

  Bundle 'FuzzyFinder'

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

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

  " ...

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

  filetype plugin indent on " required! /** vimrc文件配置結(jié)束 **/
  set completeopt=longest,menu
  "
" NERDTree config
map nd :NERDTree 
map nc :NERDTreeClose
let g:NERDTreeDirArrows = 1
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
map F2> :NERDTreeToggleCR>
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..

以上這篇淺談Vim中的Tab與空格縮進(jìn)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Linux下設(shè)置Vim編輯器里Tab的長(zhǎng)度行號(hào)
  • vi與vim如何修改tab為4個(gè)空格方法示例

標(biāo)簽:衡水 湖南 黃山 湘潭 崇左 銅川 蘭州 仙桃

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《淺談Vim中的Tab與空格縮進(jìn)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢(xún)

    • 400-1100-266