我目前的设置是8个空格;我该如何重新定义它呢?
当前回答
或者vim modeline的简写:
vim :set ts=4 sw=4 sts=4 et :
其他回答
很少有设置定义是使用空格还是制表符。
这里有一些方便的函数,可以在~/中定义。vimrc文件:
function! UseTabs()
set tabstop=4 " Size of a hard tabstop (ts).
set shiftwidth=4 " Size of an indentation (sw).
set noexpandtab " Always uses tabs instead of space characters (noet).
set autoindent " Copy indent from current line when starting a new line (ai).
endfunction
function! UseSpaces()
set tabstop=2 " Size of a hard tabstop (ts).
set shiftwidth=2 " Size of an indentation (sw).
set expandtab " Always uses spaces instead of tab characters (et).
set softtabstop=0 " Number of spaces a <Tab> counts for. When 0, featuer is off (sts).
set autoindent " Copy indent from current line when starting a new line.
set smarttab " Inserts blanks on a <Tab> key (as per sw, ts and sts).
endfunction
用法:
:call UseTabs()
:call UseSpaces()
要在每个文件扩展名中使用它,可以使用以下语法(添加到.vimrc):
au! BufWrite,FileWritePre *.module,*.install call UseSpaces()
请参见:将制表符转换为空格。
下面是来自Wikia的另一个片段,可用于在制表符和空格之间切换:
" virtual tabstops using spaces
set shiftwidth=4
set softtabstop=4
set expandtab
" allow toggling between local and default mode
function TabToggle()
if &expandtab
set shiftwidth=8
set softtabstop=0
set noexpandtab
else
set shiftwidth=4
set softtabstop=4
set expandtab
endif
endfunction
nmap <F9> mz:execute TabToggle()<CR>'z
它可以为每个选项卡使用4个空格,并映射到F9来切换设置。
还有一件事,使用 : retab 将现有制表符转换为空格 http://vim.wikia.com/wiki/Converting_tabs_to_spaces
将您想要的设置放在~/。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 #“制表符” :帮助制表符
确保vartabstop未设置
set vartabstop=
设置tabstop为4
set tabstop=4
对于永久的更改,创建文件~/.vim/plugin/tab_expander。用内容进行Vim
set tabstop=4 softtabstop=4 expandtab shiftwidth=4 smarttab
防止碰~/。Vimrc,从而保持其他默认设置不变。
推荐文章
- 如何在Vim注释掉一个Python代码块
- 如何在可视块模式插入?
- 强迫自己掌握vi的最好方法是什么?
- 如何回到行之前编辑的最后一个在Vim?
- 如何跳转到一个特定的人物在vim?
- 如何删除一个大的文本块而不计算行?
- 在Vim/Vi中,如何将光标移动到前一个单词的末尾?
- 如何在vim中自动删除尾随空格
- 为什么Vim使用~扩展名保存文件?
- 如何在Vim或Linux中将空格转换为制表符?
- 我如何使用vimdiff来解决git合并冲突?
- 在Vim中删除当前缓冲区的文件名/路径
- Git在终端提交时打开VIM,但无法返回终端
- 请参阅编辑器中的换行符和回车
- 如何在NERDTree中显示隐藏文件(以句点开始)?