自从第一天使用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
Run Code Online (Sandbox Code Playgroud)
谢谢!
在您的.vimrc:中插入以下内容:
set nosmartindent
Run Code Online (Sandbox Code Playgroud)
这smartindent导致开头的行#不按您的要求缩进.您可以通过键入来阅读更多相关信息:help smartindent.如果对python脚本(或任何其他语法)使用缩进文件,请同时包含以下内容.
filetype indent on
Run Code Online (Sandbox Code Playgroud)
您可以使用:
inoremap # X^H#
Run Code Online (Sandbox Code Playgroud)
我认为这种行为对于 C/C++ 来说并不是完全错误的,因此我只是在 python/php 中更改它。
autocmd FileType python,php inoremap # X^H#
Run Code Online (Sandbox Code Playgroud)
:help smartindent说:
当在新行中键入#第一个字符时,该行的缩进将被删除,并将其#放入第一列中。下一行的缩进将恢复。
如果您不想这样做,请使用此映射::inoremap # X^H#,其中^H输入为CTRL-V CTRL-H。使用该>>命令时,以 开头的行#不会右移。