一次删除一个空格的选项卡
如何配置 vim,以便一次删除一个选项卡而不是整个选项卡?当我尝试为 if 语句对齐多个测试时,我经常想这样做。在下面的示例中,条件 3 按我想要的方式对齐,而条件 2 由于制表符而偏移了一个空格。
if condition1 or \
condition2 or \
condition3:
do something
我在 OSX 10.6.7 上使用 vim 7.2.108,并且在我的代码文件中有以下模式行:
# ex: tabstop=4 softtabstop=1 shiftwidth=4 expandtab:
FWIW,此模式行确实允许我使用箭头键一次一个空格地浏览选项卡。
更新:以下是我对 Bram Mooleanar 的示例 vimrc 文件所做的更改:
map z :w<cr>
map q :q!<cr>
map m :make<cr>
set expandtab
set shiftwidth=4
set tabstop=4
set bs=2 " backspace over anything in insert mode
set showmatch " display the matching bracket of the pair
set nowrap " don't wrap line to fit window
set showmatch " show matching paren, bracket, or brace
set ruler " show current cursor position at bottom
set incsearch " show next match as you type in search pattern
set ignorecase
set smartcase
syntax on " enable syntax highlighting
How do I configure vim so that I can delete a tab one space at a time rather than the entire tab? I often want to do this when I'm trying to align multiple tests for an if statement. In the below example, condition3 is aligned as I want and condition2 is off by one space due to the tab.
if condition1 or \
condition2 or \
condition3:
do something
I'm using vim 7.2.108 on OSX 10.6.7 and have the following mode line in my code file:
# ex: tabstop=4 softtabstop=1 shiftwidth=4 expandtab:
FWIW, this mode line does allow me to use the arrow keys to navigate through a tab one space at a time.
Update: Here's the changes I've made to the example vimrc file from Bram Mooleanar:
map z :w<cr>
map q :q!<cr>
map m :make<cr>
set expandtab
set shiftwidth=4
set tabstop=4
set bs=2 " backspace over anything in insert mode
set showmatch " display the matching bracket of the pair
set nowrap " don't wrap line to fit window
set showmatch " show matching paren, bracket, or brace
set ruler " show current cursor position at bottom
set incsearch " show next match as you type in search pattern
set ignorecase
set smartcase
syntax on " enable syntax highlighting
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想说将其放入您的 .vimrc 文件中:
当您按 Tab 键时,它基本上会将制表符变成空格。
I would say put this in your .vimrc file:
Which basically turns tabs into spaces when you hit the tab key.
我只需在正常模式下点击
x
即可删除单个字符。我还将指出伟大的 indent/python.vim script埃里克·麦克斯温著。它并没有真正改变退格行为,但它允许您做一些更符合 PEP8 的事情——使用 Python 的隐式使用括号的行延续。使用脚本,上面的代码将如下所示I would just hit
x
in normal mode to delete a single character. I'll also point out the great indent/python.vim script by Eric McSween. It doesn't really change the backspace behavior, but it allows you to do something more in line with PEP8---using Python's implied line continuation using parentheses. With the script, the code above would look like看起来问题在于您使用制表符和空格的混合来管理对齐方式。
在大多数环境中,有很多人处理相同的文件,建议仅使用空格或仅使用制表符。
也就是说,您可以通过将以下内容添加到 vimrc 来映射一个键来删除制表符并在其位置插入 3 个空格。
如果你想在插入模式下执行:
*注意“>”后面有三个空格
It looks like the problem is that you are using a mix of tabs and spaces to manage alignment.
In most environments where there are many people working on the same files it is recommended that only spaces or only tabs are used.
That said you could map a key to delete the tab character and insert 3 spaces in its place by adding the following to your vimrc.
If you want to do it in insert mode:
*note that there are three spaces after the ">"