浅谈Vim中的Tab与空格缩进

所属分类: 脚本专栏 / linux shell 阅读数: 706
收藏 0 赞 0 分享

vim缩进参数解析

缩进用 tab 制表符还是空格,个人爱好问题。但是在大多项目中,习惯使用空格。关于缩进,vim中可以通过如下四个参数进行配置

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

解析:

tabstop

表示按一个tab之后,显示出来的相当于几个空格,默认的是8个。

softtabstop

表示在编辑模式的时候按退格键的时候退回缩进的长度。

shiftwidth

表示每一级缩进的长度,一般设置成跟 softtabstop 一样

expandtab与noexpandtab

当设置成 expandtab 时,缩进用空格来表示,noexpandtab 则是用制表符表示一个缩进。个人习惯使用 `set expandtab`

#标志tab与空格

在vim中,默认情况下,没法区分空格和缩进,所以我们需要配置,使其能够区分。

我的配置如下

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

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

附上自己的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..

以上这篇浅谈Vim中的Tab与空格缩进就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

php编译安装常见错误大全和解决方法

这篇文章主要介绍了php编译安装常见错误大全和解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Linux base shell重定向详解

这篇文章主要介绍了Linux base shell重定向的相关资料,并用一个简明例子总结了常见用法(在第三节),需要的朋友可以参考下
收藏 0 赞 0 分享

Linux Shell 常见的命令行格式简明总结

这篇文章主要介绍了Linux Shell 常见的命令行格式简明总结,非常实用,需要的朋友可以参考下
收藏 0 赞 0 分享

Shell 命令替换的两种方式

这篇文章主要介绍了Shell 命令替换的两种方式,需要的朋友可以参考下
收藏 0 赞 0 分享

Python创建、删除桌面、启动组快捷方式的例子分享

这篇文章主要介绍了Python创建、删除桌面、启动组快捷方式的例子分享,需要的朋友可以参考下
收藏 0 赞 0 分享

shell基础学习中的字符串操作、for循环语句示例

这篇文章主要介绍了shell基础学习中的字符串操作、for循环语句示例
收藏 0 赞 0 分享

shell脚本中28个特殊字符的作用简明总结

这篇文章主要介绍了shell脚本中28个特殊字符的作用简明总结,需要的朋友可以参考下
收藏 0 赞 0 分享

linux shell流程控制语句实例讲解(if、for、while、case语句实例)

linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case)。下面我将通过例子介绍下,各个语句使用方法
收藏 0 赞 0 分享

分享一个实用的iptables脚本(各种过滤写法参考)

这篇文章主要介绍了分享一个实用的iptables脚本(各种过滤写法参考),需要的朋友可以参考下
收藏 0 赞 0 分享

shell脚本实现ssh自动登录功能分享

mac下没有找到好用的类似secureCRT,就自己写了个自动登录的脚本,分享一下,如果是新浪的,就基本不用修改代码就直接能用
收藏 0 赞 0 分享
查看更多