用于Python的.vimrc配置
我当前的.vimrc配置如下:
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。我要添加些什么以便它为我自动生成标签?
-
简短的答案是您的autocmd缺少BufEnter触发器,因此在创建新文件时不会将其触发。尝试以下方法:
au BufEnter,BufRead *.py setlocal smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
请注意,我还将更改
set
为setlocal
。这样可以防止这些选项踩到您其他缓冲区的选项。执行您要执行的操作的“正确”方法是添加
filetype indent on
到.vimrc中。这将打开基于内置文件类型的缩进。Vim带有Python缩进支持。请参阅:help filetype-indent- on
以获取更多信息。