插入模式開始行每當我要評論在vim增加縮進線,我打移 - Ø(打開高於目前的一個新行,切換到插入模式)並開始輸入Python註釋(使用#
)。然後,這個哈希奇蹟般地移動到行的開頭(無縮進),我必須點擊幾次tab。評論(#)走在Vim的
任何人都知道如何解決它?
插入模式開始行每當我要評論在vim增加縮進線,我打移 - Ø(打開高於目前的一個新行,切換到插入模式)並開始輸入Python註釋(使用#
)。然後,這個哈希奇蹟般地移動到行的開頭(無縮進),我必須點擊幾次tab。評論(#)走在Vim的
任何人都知道如何解決它?
我想你在.vimrc有set smartindent
見:h smartindent
When typing '#' as the first character in a new line, the indent for
that line is removed, the '#' is put in the first column. The indent
is restored for the next line. If you don't want this, use this
mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
When using the ">>" command, lines starting with '#' are not shifted
right.
我相信你並不需要,而編碼蟒蛇smartindenting。所以,只是從你的設置中刪除或添加以下到您的.vimrc:
au! FileType python setl nosmartindent
你可能想嘗試Nerd Commenter,這是一個插件,允許你自動添加評論到大多數語言的行。您只需將光標放在您感興趣的行上,並輸入,c空間並且該行將被註釋掉。相同的擊鍵將移除註釋以顯示該行。
所以,如果您有:
def func():
print("indented") <- cursor position in command mode
類型,Ç空間,你會得到:
def func():
#print("indented")
comments.vim是一個輕量級替代http://www.vim.org/scripts/script.php?script_id=1528 – Shaun 2014-06-12 12:36:50
這個答案顯然是對的錢,非常感謝。我完全錯過了這一點。 但是,我不同意這個事實,我不需要smartindenting,因爲python是關於它的。相反,我可以添加異常。 但是,我想知道哪個是最好的,手冊的inoremap還是Haes提供的?或者說,有什麼不同? – 2010-01-15 08:31:46
我認爲python'smartindent'沒用。 Python程序員不需要縮進就可以自動插入1.在以'{'結尾的行後面。 2.在以'}'開頭的行之前。來自'cinwords'的關鍵字可以通過python filetype indentation正確處理。 – 2010-01-15 09:13:24
基本上inoremaps是相同的。這個inoremap唯一的缺點是 - 你不能用'>>'把註釋轉移到正確的位置 – 2010-01-15 09:16:33