vim 的配置文件默認是當前用戶宿主目錄下的.vimrc 文件。下列配置是常用 vim 進行 python 開 發的配置。
" 高亮當前行
set cursorline
" 將 TAB 設為四個空格的寬度
set tabstop=4
" 自動縮進
set autoindent
" 使用空格代替 TAB
set expandtab
" 定義 PythonHeader() 函數用於自動插入 Python 文件頭
function PythonHeader()
call setline(1, "# -*- coding: utf-8 -*-")
normal o
normal o
endfunc
" 新建 py 結尾的文件時自動調用 PythonHeader() 函數
autocmd BufNewFile *.py call PythonHeader()
" 按下 F5 自動執行當前 Python 文件
map :!clear ;python %
NOTE: 如果.vimrc 文件不存在新建即可。