2011-04-11 23 views
11

自从第一天使用Vim 3年以来,这个避风港一直在困扰着我。每当我试着通过转移到缩进一行 + 当行的第一个字符用“#”,它不能在所有的工作,无论文件类型(.PHP,.TXT等开始> )。因为#用于在PHP评论,我还用它装饰的文本文件类似:当该行的第一个字符是一个尖锐的#字符时,Vim编辑器缩进问题

# This is a comment 

### 1. Instruction one 

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

我用Vim 7.2在Ubuntu具有以下.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 

谢谢!

回答

4

插入您的.vimrc如下:

set nosmartindent 

这是smartindent导致与#开头的行,只要你想不被缩进。你可以通过输入:help smartindent来了解更多关于它的信息。如果您为Python脚本(或任何其他语法)使用缩进文件,请包括以下内容。

filetype indent on 
+3

这并不能解决我的问题。我有'nosmartindent'和'filetype indent on',但仍然vim不让我缩进以'#'开头的行。当我在行中输入'#'作为第一个字符时,它也会将光标移动到第一列。任何线索? – 2013-04-15 11:16:31

+1

@MichaelHärtl默认情况下,我有你完全相同的问题。默认情况下,Rmd具有这种恼人的行为,切换此行为的正确咒语是:':set nocindent'将其关闭,':set cindent'将它关闭在此处定义如下:http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash – 2017-04-15 07:59:17

0

您可以使用:

inoremap # X^H# 

我认为这种行为是不完全错误的C/C++,因此我只是改变它在Python/PHP。

autocmd FileType python,php inoremap # X^H# 

:help smartindent说:

当输入#在新行的第一个字符,缩进的 该行被删除,#被放在第一列。下一行将恢复缩进 。

如果你不想这样,使用此映射::inoremap # X^H#,其中输入与CTRL-V CTRL-H^H。 使用>>命令时,以#开头的行不会右移。

相关问题