我目前的设置是8个空格;我该如何重新定义它呢?
当前回答
要为当前用户永久地定义此属性,请创建(或编辑).vimrc文件:
$ vim ~/.vimrc
然后,将下面的配置粘贴到文件中。重新启动vim后,将应用选项卡设置。
set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
" Vim will interpret it to be having
" a width of 4.
set shiftwidth=4 " Indents will have a width of 4
set softtabstop=4 " Sets the number of columns for a TAB
set expandtab " Expand TABs to spaces
其他回答
还有一件事,使用 : retab 将现有制表符转换为空格 http://vim.wikia.com/wiki/Converting_tabs_to_spaces
添加一行 将ts = 4 在 ~ /。每个用户的Vimrc文件 或 /etc/vimrc文件用于整个系统
将您想要的设置放在~/。vimrc文件——请参阅下面的一些指导方针和最佳实践。
在Vim中使用标签有四种主要方式:
Always keep 'tabstop' at 8, set 'softtabstop' and 'shiftwidth' to 4 (or 3 or whatever you prefer) and use 'noexpandtab'. Then Vim will use a mix of tabs and spaces, but typing and will behave like a tab appears every 4 (or 3) characters. Note: Setting 'tabstop' to any other value than 8 can make your file appear wrong in many places (e.g., when printing it). Set 'tabstop' and 'shiftwidth' to whatever you prefer and use 'expandtab'. This way you will always insert spaces. The formatting will never be messed up when 'tabstop' is changed. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a |modeline| to set these values when editing the file again. Only works when using Vim to edit the file. Always set 'tabstop' and 'shiftwidth' to the same value, and 'noexpandtab'. This should then work (for initial indents only) for any tabstop setting that people use. It might be nice to have tabs after the first non-blank inserted as spaces if you do this though. Otherwise aligned comments will be wrong when 'tabstop' ischanged.
来源:
vimdoc.sourceforge.net/htmldoc/options.html #“制表符” :帮助制表符
我复制并粘贴到我的。vimrc文件:
" size of a hard tabstop
set tabstop=4
" always uses spaces instead of tab characters
set expandtab
" size of an "indent"
set shiftwidth=4
前两个设置意味着当我按Tab键时,我得到4个空格。 第三个设置意味着当我做V>(即视觉和缩进)时,我也得到了4个空格。
不像公认的答案那么全面,但它可能会帮助那些只想复制和粘贴一些东西的人。
或者vim modeline的简写:
vim :set ts=4 sw=4 sts=4 et :
推荐文章
- 如何在Vim注释掉一个Python代码块
- 如何在可视块模式插入?
- 强迫自己掌握vi的最好方法是什么?
- 如何回到行之前编辑的最后一个在Vim?
- 如何跳转到一个特定的人物在vim?
- 如何删除一个大的文本块而不计算行?
- 在Vim/Vi中,如何将光标移动到前一个单词的末尾?
- 如何在vim中自动删除尾随空格
- 为什么Vim使用~扩展名保存文件?
- 如何在Vim或Linux中将空格转换为制表符?
- 我如何使用vimdiff来解决git合并冲突?
- 在Vim中删除当前缓冲区的文件名/路径
- Git在终端提交时打开VIM,但无法返回终端
- 请参阅编辑器中的换行符和回车
- 如何在NERDTree中显示隐藏文件(以句点开始)?