在 vim 中使用制表符而不是空格,即使使用“set Expandtab”

发布于 2025-01-13 09:33:36 字数 819 浏览 2 评论 0原文

我通过 vi tabtest 创建文件“tabtest”,然后输入:

a
tab
b
newline  
c
tab
d  
CTRL-C
:
wq  

I have set Expandtab in my `.vimrc。但我仍然在文件中得到制表符而不是空格。

(base) balter@ab-rstudio:~$ cat -A tabtest
a^Ib$
^Ic^Id$
(base) balter@ab-rstudio:~$ cat .vimrc
let python_highlight_all = 1

set undodir=${HOME}/.vim/undo/
set backupdir=${HOME}/.vim/backup/
set directory=~/.vim/swp/
set writebackup
set noswapfile

set autoindent
set showmatch
set mouse=a
syntax on

set tabstop=4
set softtabstop=0
set shiftwidth=4
set textwidth=79
set expandtab
set smarttab
set autoindent
set fileformat=unix

set backspace=indent,eol,start
set whichwrap+=<,>,h,l,[,]

set laststatus=2
set statusline+=%F

colorscheme murphy

set paste

I create the file "tabtest" by vi tabtest and then typing:

a
tab
b
newline  
c
tab
d  
CTRL-C
:
wq  

I have set expandtab in my `.vimrc. But I'm still getting tabs in the file instead of spaces.

(base) balter@ab-rstudio:~$ cat -A tabtest
a^Ib$
^Ic^Id$
(base) balter@ab-rstudio:~$ cat .vimrc
let python_highlight_all = 1

set undodir=${HOME}/.vim/undo/
set backupdir=${HOME}/.vim/backup/
set directory=~/.vim/swp/
set writebackup
set noswapfile

set autoindent
set showmatch
set mouse=a
syntax on

set tabstop=4
set softtabstop=0
set shiftwidth=4
set textwidth=79
set expandtab
set smarttab
set autoindent
set fileformat=unix

set backspace=indent,eol,start
set whichwrap+=<,>,h,l,[,]

set laststatus=2
set statusline+=%F

colorscheme murphy

set paste

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

虐人心 2025-01-20 09:33:37

工具定制的黄金规则之一是只将您理解的内容放入配置中。实现这种理解的第一步是阅读(而不是略读)您计划添加的任何选项或命令的文档,然后利用新发现的知识思考优点以及这样做的缺点。

:help 'paste' 是一个非常强大的选项,具有许多明确记录的副作用,例如:

When the 'paste' option is switched on (also when it was already on):
        [...]
        - 'expandtab' is reset
        [...]

该选项永远不应在用户的 vimrc 中设置因为所有这些令人讨厌的副作用仅在使用终端/系统的粘贴功能时才需要,但在其余时间是非常不希望的。将其删除。

一般情况是这样的:

  1. 用户尝试使用终端的“粘贴”功能粘贴某些内容,但收到乱码文本,
  2. 用户在互联网上查找它,了解 paste 选项,但从不费心去阅读其文档中,
  3. 用户很快就厌倦了 :set Paste:set nopaste 舞蹈,并决定添加 set Paste到他们的 vimrc 以便它始终处于打开状态,
  4. 用户注意到缩进或插入模式映射的问题,但无法将它们与将 set Paste 添加到他们的 < code>vimrc…因为他们不知道该选项的实际作用,
  5. 用户再次转向互联网,这提醒他们及时阅读文档会让他们意识到的陷阱set Paste 引导他们使用:help 'pastetoggle',它很好地解决了重复问题,而无需添加set Paste对于他们的 vimrc
  6. 希望用户有所启发。

但是,当然,真正的解决方案是获得一个具有剪贴板支持的合适的 Vim,但那是另一个被殴打致死的故事了。

One of the golden rules of tool customization is to only put stuff you understand in your config. The first step toward that understanding is to read (not skim) the documentation for any option or command you plan to add and then, armed with that newfound knowledge, ponder the pros and cons of doing so.

:help 'paste' is a very powerful option with many explicitly documented side effects, such as:

When the 'paste' option is switched on (also when it was already on):
        [...]
        - 'expandtab' is reset
        [...]

That option should never be set in one's vimrc because of all those nasty side effects that are desirable only when using the terminal/system's pasting facilities but very undesirable the rest of the time. Remove it.

Here is how it generally goes:

  1. user tries to paste something with the terminal's "paste" thing and gets garbled text,
  2. user looks it up on the internet, learns about the paste option, and never bothers to read its documentation,
  3. user quickly gets tired of that :set paste<CR><whatever>:set nopaste<CR> dance and decides to add set paste to their vimrc so that it is always on,
  4. user notices issues with indenting or insert mode mappings but is unable to relate them to their nifty idea of adding set paste to their vimrc… because they have no idea of what the option actually does,
  5. user turns once again to the internet, which reminds them that reading the doc in due time would have made them aware of the pitfalls of set paste and led them to :help 'pastetoggle', which solves the repetitiveness issue nicely without adding set paste to their vimrc,
  6. user is, hopefully, enlightened.

But, of course, the real solution is to get a proper Vim with clipboard support, but that's another, beaten to death, story.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文