繁体   English   中英

.vimrc配置为Python

[英].vimrc configuration for Python

我目前的.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。 我添加了什么以便它会自动为我标记?

试试这个:

filetype indent on
filetype on
filetype plugin on

我主要做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

简短的回答是您的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

考虑查看官方.vimrc以了解遵循PEP 7和8约定。 出现在这里

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

您不必显式缩进python关键字。 $ VIM / indent / python.vim文件负责处理。 你只需要打开filetype indent和autoindent。

我(简单地)使用这个:

set shiftwidth=4
set tabstop=4
set expandtab
filetype plugin on
filetype indent on
syntax on

我会说这个配置提供了一些东西,而不会引起冲突( /etc/vim/vimrc ):

" Python Setup
autocmd Filetype python setlocal ts=2 sw=2 expandtab
autocmd Filetype python set number
autocmd Filetype python set autoindent
autocmd Filetype python set expandtab
autocmd Filetype python set shiftwidth=4
autocmd Filetype python set cursorline
autocmd Filetype python set showmatch
autocmd Filetype python let python_highlight_all = 1
autocmd Filetype python set colorcolumn=80

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM