我现在正在尝试切换到 VIM,并希望让它像 Python 的 IDE 一样自动缩进。我有以下 .vimrc 文件
syntax on
set number
autocmd FileType tex,latex,python set showmatch
nnoremap j gj
nnoremap k gk
"Python Settings
autocmd FileType python set softtabstop=4
autocmd FileType python set tabstop=4
autocmd FileType python set autoindent
autocmd FileType python set expandtab
autocmd FileType python set textwidth=80
autocmd FileType python set smartindent
autocmd FileType python set shiftwidth=4
autocmd FileType python map <buffer> <F2> :w<CR>:exec '! python' shellescape(@%, 1)<CR>
autocmd FileType python imap <buffer> <F2> <esc>:w<CR>:exec '! python' shellescape(@%, 1)<CR>
Run Code Online (Sandbox Code Playgroud)
在某些情况下,代码会自动缩进。例如,我尝试过 if 语句和 while 语句,它们在按 Enter 键后缩进。所以下面的内容将正确缩进。
if True:
#this is where my next line automatically starts
Run Code Online (Sandbox Code Playgroud)
while True:
#this is where my next line automatically starts
Run Code Online (Sandbox Code Playgroud)
但对于类/函数定义,没有缩进。
class Request_Form(QDialog):
#no indentation -- cursor comes here
Run Code Online (Sandbox Code Playgroud)
谁能帮我纠正这种行为