gpt4 book ai didi

vim - 自动缩进在 vim 中不起作用?

转载 作者:行者123 更新时间:2023-12-04 12:08:23 25 4
gpt4 key购买 nike

我目前正在使用 vim 并希望每次需要时自动缩进(例如在 javascript 中的大括号之后或 Python 中的冒号之后)。出于某种原因,我尝试了 autoindent 和 smartindent,但每一行都给了我 2 个标签而不是一个。为什么要这样做?我以为它只会插入一个标签。

我当前的 ~/.vimrc 文件有:

    set ts=4
set autoindent
set smartindent
filetype plugin indent on

最佳答案

您还需要设置:

:set shiftwidth=4 softtabstop=4

tabstop 仅适用于真正的“\t”选项卡所采用的列数:
:he shiftwidth

Number of spaces to use for each step of (auto)indent. Used for
|'cindent'|, |>>|, |<<|, etc.
When zero the 'ts' value will be used.

:he softtabstop

Number of spaces that a <Tab> counts for while performing editing
operations, like inserting a <Tab> or using <BS>. It "feels" like
<Tab>s are being inserted, while in fact a mix of spaces and <Tab>s is
used.

而制表符:
 :he tabstop

Number of spaces that a <Tab> in the file counts for. Also see
|:retab| command, and 'softtabstop' option.

作为奖励,以下是我为此设置的一些映射,当我需要处理不使用我最喜欢的默认扩展选项卡和 4 个空格缩进的项目时:
nmap <Leader>t2 :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
nmap <Leader>t4 :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
nmap <Leader>t8 :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
nmap <Leader>T2 :set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2<CR>
nmap <Leader>T4 :set noexpandtab tabstop=4 softtabstop=4 shiftwidth=4<CR>
nmap <Leader>T8 :set noexpandtab tabstop=8 softtabstop=8 shiftwidth=8<CR>

关于vim - 自动缩进在 vim 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22305087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com