2012-06-20 16 views
2

使用VIM中的autoindent配置時,它將在創建新行後自動將光標縮進到有意義的位置。但是,當您輸入的第一個字符是散列字符(#)時,將刪除縮進並將#作爲該行的第一個字符插入。如何不通過插入`#`來刪除縮進?

這是爲什麼發生?如何配置VIM不這樣做?

例(_爲空光標位置):

def python_function(): 
    _ 

點擊#鍵盤上後,這種情況發生:

def python_function(): 
#_ 

但什麼應該發生是這樣的:

def python_function(): 
    #_ 
+2

檢出http://stackoverflow.com/questions/191201/indenting-comments-to-match-code-in-vim和http://stackoverflow.com/questions/385327/what-setting-in-vim -counteracts-smartindents-refusal-to-indent-comments-in-sh –

+0

你說得對,我只是不知道如何搜索這個詞。 – erikbwork

回答

4

可能必須smartindentcindent代替(或以及)autoindent;這些縮進樣式是爲C語法語言設計的。編輯Python以使用:filetype plugin indent on是個好主意,因爲這會爲Python加載適當的縮進設置。

+1

@erikb肯定,完成。 – ecatmur

3

:help smartindent

使用映射:inoremap # X^H#(^ h被經由輸入CTRL-V CTRL-H)

+0

你知道爲什麼會發生這種情況嗎? – erikbwork

+1

smartindent的幫助部分給出了一個簡短的解釋。作爲C源代碼的編輯器,vim具有很強的遺產,通常以'#'開頭的行不會縮進。 –

+1

@ erikb85,你的問題的答案是http://stackoverflow.com/questions/35156448/autoindent-smartindent-and-indentexpr – dlmeetei

相關問題