Python 的 .vimrc 配置 [英] .vimrc configuration for Python
问题描述
我当前的 .vimrc 配置如下:
My current .vimrc configuration is below:
set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent
syntax on
set listchars=tab:>-
set listchars+=trail:.
set ignorecase
set smartcase
map <C-t><up> :tabr<cr>
map <C-t><down> :tabl<cr>
map <C-t><left> :tabp<cr>
map <C-t><right> :tabn<cr>
但是,当我编写python脚本时,当我按下ENTER"时,它会转到下一行的BEGINNING.我要添加什么才能自动为我设置标签?
However, when I write python scripts, when I push "ENTER", it will go to the BEGINNING of the next line. What do I add so that it will auto-tab for me?
推荐答案
简短的回答是您的 autocmd 缺少 BufEnter 触发器,因此在您创建新文件时它不会被触发.试试这个:
The short answer is that your autocmd is missing the BufEnter trigger, so it isn't being fired when you create a new file. Try this instead:
au BufEnter,BufRead *.py setlocal smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
请注意,我还将 set
更改为 setlocal
.这将防止这些选项影响您其他缓冲区的选项.
Note that I also changed the set
to setlocal
. This'll prevent these options from stomping on your other buffers' options.
做您想做的事情的正确"方法是将 filetype indent on
添加到您的 .vimrc.这将打开基于内置文件类型的缩进.Vim 带有 Python 缩进支持.有关详细信息,请参阅 :help filetype-indent-on
.
The "right" way to do what you're trying to do is to add filetype indent on
to your .vimrc. This'll turn on the built-in filetype based indentation. Vim comes with Python indentation support. See :help filetype-indent-on
for more info.
这篇关于Python 的 .vimrc 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!