欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vim python 编辑器 .vimrc配置

程序员文章站 2022-05-19 21:10:16
...
set tabstop=4                                                                                                                          
set softtabstop=4
set autoindent
set expandtab
set shiftwidth=4
" set mouse=a
" set mouse=v
set modeline
set modelines=5

autocmd FileType make set noexpandtab

if has("pathogen")
    execute pathogen#infect()
endif

if has("autocmd")
  filetype  plugin indent on
endif

if has("autochdir")
    set autochdir
endif

set number
set ruler
set backspace=2
set laststatus=2

set nolinebreak
set background=light
set showmatch
set autochdir
set shortmess=atI
"配置paste模式为f3
set pastetoggle=<F3>
"Enable folding
set foldmethod=indent
set foldlevel=99
"通过空格键快速打开和关闭折叠
nnoremap <space> za
"F4快捷键快速切换打开和关闭目录树窗口
map <F4> :NERDTreeToggle<CR>
    
set fenc=
"设置状态栏显示的内容
" set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}\ %{ALEGetStatusLine()}

if !has('gui_running')
  set t_Co=256
endif

set t_Co=256
colorscheme desert
hi LineNr ctermfg=245 ctermbg=235
set cursorline
hi CursorLine ctermbg=235 cterm=NONE guibg=Grey40
syntax on
" set nohls
" set nohlsearch

"记住上次打开的位置
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

auto BufNewFile *.py call PythonHeader()
    
func PythonHeader()
    call setline(1, "#!/usr/bin/env python")
    call append(1, "# -*- coding: utf-8 -*-")
    call append(2, "")
    call append(3, "from __future__ import unicode_literals")
    call append(4, "from __future__ import absolute_import")
endf

call plug#begin('~/.vim/plugged')
" 状态栏
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" 树形目录插件配置
Plug 'scrooloose/nerdtree'
Plug 'jistr/vim-nerdtree-tabs'
" 语法高亮和检查插件
" Plug 'sheerun/vim-polyglot'
Plug 'dense-analysis/ale'
" 注释插件
Plug 'preservim/nerdcommenter'
" 搜索插件
Plug 'kien/ctrlp.vim'
" 代码补全
Plug 'ycm-core/YouCompleteMe', { 'do': './install.py' }
call plug#end()
    
" ctrl+n切换树形目录,和树形目录配置
map <C-n> :NERDTreeToggle<CR>
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
let NERDTreeMinimalUI = 1
let NERDTreeShowHidden = 0   " 不显示隐藏文件
" let g:nerdtree_tabs_open_on_console_startup = 1
let g:nerdtree_tabs_focus_on_files = 1
" 设置宽度
let NERDTreeWinSize=25
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | q | endif

" 代码检查配置
" ale-setting {{{
let g:ale_set_highlights = 0
"自定义error和warning图标
" let g:ale_sign_error = ''
" let g:ale_sign_warning = ''
"在vim自带的状态栏中整合ale
" let g:ale_statusline_format = ['%d', '%d', '✔ OK']
"显示Linter名称,出错或警告等相关信息
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
"打开文件时不进行检查
let g:ale_lint_on_enter = 0

"普通模式下,sp前往上一个错误或警告,sn前往下一个错误或警告
nmap sp <Plug>(ale_previous_wrap)
nmap sn <Plug>(ale_next_wrap)
"<Leader>s触发/关闭语法检查
nmap <Leader>s :ALEToggle<CR>
"<Leader>d查看错误或警告的详细信息
nmap <Leader>d :ALEDetail<CR>
"对python使用pylint进行语法检查
let g:ale_linters = {
\   'python': ['pylint'],
\   'javascript': ['eslint'],
\}
" }}}

" 注释符号后面空一格
let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
" 整合airline+ale
let g:airline#extensions#ale#enabled = 1
" 配置airline
" let g:airline_section_b = '%{strftime("%c")}'   " 显示时间
" let g:airline_section_y = 'BN: %{bufnr("%")}'   " 显示星期
let g:airline#extensions#tabline#enabled = 1 " 显示窗口tab和buffer
" vim自动补全框颜色设置
hi PMenu ctermfg=80 ctermbg=8 guifg=MediumTurquoise guibg=Grey
hi PMenuSel ctermfg=250 ctermbg=30 guifg=Grey74 guibg=Turquoise4
" 代码补全插件配置
" 输入第一个字符就开始补全
let g:ycm_min_num_of_chars_for_completion=1
" 开起vim时不检测ycm_extra_conf文件
let g:ycm_confirm_extra_conf = 0
" 关闭显示函数的文档窗口
set completeopt=longest,menu
let g:ycm_add_preview_to_completeopt=0
" 设置跳转快捷键
nnoremap <c-k> :YcmCompleter GoToDeclaration<CR>
nnoremap <c-h> :YcmCompleter GoToDefinition<CR>
nnoremap <c-j> :YcmCompleter GoToDefinitionElseDeclaration<CR>