.vimrc配置为Python

TIM*_*MEX 19 python vim

我目前的.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>
Run Code Online (Sandbox Code Playgroud)

但是,当我编写python脚本时,当我按下"ENTER"时,它将转到下一行的BEGINNING.我添加了什么以便它会自动为我标记?

Nop*_*ope 15

试试这个:

filetype indent on
filetype on
filetype plugin on
Run Code Online (Sandbox Code Playgroud)

我主要做Python编程,这是我的vimrc的首要任务

set nobackup
set nowritebackup
set noswapfile
set lines=40
set columns=80
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
set smarttab
filetype indent on
filetype on
filetype plugin on
Run Code Online (Sandbox Code Playgroud)


Lau*_*ves 12

简短的回答是您的autocmd缺少BufEnter触发器,因此在创建新文件时不会触发它.试试这个:

 au BufEnter,BufRead *.py setlocal smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
Run Code Online (Sandbox Code Playgroud)

请注意,我也改变了setsetlocal.这将阻止这些选项踩踏你的其他缓冲区选项.

做你想做的事情的"正确"方法是添加filetype indent on到你的.vimrc.这将打开基于内置文件类型的缩进.Vim附带了Python缩进支持.有关详情:help filetype-indent-on,请参阅.


sub*_*iet 6

考虑考虑遵循PEP 7和8约定的官方.vimrc。现在在这里

http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc