当行的第一个字符是尖锐的#字符时,Vim编辑器缩进问题

sf6xfgos  于 2023-05-17  发布在  其他
关注(0)|答案(3)|浏览(107)

自从第一天使用Vim以来,这已经困扰了我3年。每当我尝试通过Shift + >缩进一行时,该行的第一个字符以“#”开头,它根本不起作用,无论文件类型如何(.php,.txt等)。因为#在PHP中用于注解,我也用它来装饰文本文件,比如:

# This is a comment

### 1. Instruction one

# ------------ this is an sample --------------

我在Ubuntu中使用Vim 7.2,设置如下.vimrc

syntax on
set t_Co=256
set incsearch
set hlsearch
set number
set nowrap
set nowrapscan
set ignorecase
set et
set sw=4
set smarttab
set smartindent
set autoindent
set textwidth=0
set noequalalways
set formatoptions=1
set lbr
set vb      
set foldmethod=marker

谢谢!

gkn4icbw

gkn4icbw1#

.vimrc中插入以下内容:

set nosmartindent

正是smartindent导致以#开头的行不能按照您的要求缩进。您可以通过键入:help smartindent阅读更多有关它的信息。如果您使用python脚本的缩进文件(或任何其他语法),也包括以下内容。

filetype indent on
zf9nrax1

zf9nrax12#

您可以用途:

inoremap # X^H#

我认为这种行为对于C/C++来说并不是完全错误的,因此我只是在python/php中改变了它。

autocmd FileType python,php inoremap # X^H#

:help smartindent说:
当键入#作为新行的第一个字符时,该行的缩进将被删除,#将被放在第一列。下一行将恢复缩进。
如果你不想这样做,请使用这个Map::inoremap # X^H#,其中^HCTRL-V CTRL-H一起输入。使用>>命令时,以#开始的行不会右移。

flvlnr44

flvlnr443#

在问了ChatGPT之后,我终于找到了解决方案。
默认情况下,vim将foldignore设置为#,您可以通过在vim中运行以下命令进行验证:

set foldignore?

您将看到输出foldignore=#

解决方案:把这个添加到你的vim配置中:

set foldignore=

相关问题