linux 使用 vim 玩python

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 文件不存在新建即可。 

猜你喜欢

转载自www.cnblogs.com/haoge92/p/9132346.html
今日推荐