2011-04-11 58 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。 使用>>命令時,以#開頭的行不會右移。

相關問題