用于Python的.vimrc配置

发布于 2021-01-29 15:08:44

我当前的.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。我要添加些什么以便它为我自动生成标签?

关注者
0
被浏览
77
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    简短的答案是您的autocmd缺少BufEnter触发器,因此在创建新文件时不会将其触发。尝试以下方法:

     au BufEnter,BufRead *.py setlocal smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
    

    请注意,我还将更改setsetlocal。这样可以防止这些选项踩到您其他缓冲区的选项。

    执行您要执行的操作的“正确”方法是添加filetype indent on到.vimrc中。这将打开基于内置文件类型的缩进。Vim带有Python缩进支持。请参阅:help filetype-indent- on以获取更多信息。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看