一份vim配置简单的IDE文件

nano做一个的文本编辑器,偶尔简单修改一下文本还是挺好用的:https://zsxwz.com/2020/04/26/

vim做为一个文本编辑器,比较强大,可以安装各种插件,各种快捷键。自己不太会记快捷键,因此用的也不多。看了很多配置文档,最后还是自己搞一份算了,当做一个ide简单的python环境,很多时候也是很方便的。

1、.vimrc:

"安装插件
set nocompatible 
filetype off 

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

"插件列表,在这里添加需要的扩展
Plugin 'gmarik/Vundle.vim'
Plugin 'Chiel92/vim-autoformat'
Plugin 'https://github.com/bling/vim-airline'
Plugin 'w0rp/ale'
Plugin 'kien/rainbow_parentheses.vim'
Plugin 'Valloric/YouCompleteMe'
"Plugin 'scrooloose/syntastic'
Plugin 'scrooloose/nerdtree
Plugin 'Yggdroot/indentLine'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tell-k/vim-autopep8'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'nvie/vim-flake8'
Plugin 'preservim/nerdcommenter'
call vundle#end()           
filetype plugin indent on

"f3文件树
nnoremap <F3> :NERDTreeToggle<CR>

"f6代码格式化
nnoremap <F6> :Autoformat<CR>
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0
"f4注释当前行
map <F4> <leader>ci <CR>

"f6代码格式化
nnoremap <F6> :Autoformat<CR>
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0

"f5运行代码
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
        exec "w"
        if &filetype == 'c'
                exec "!g++ % -o %<"
                exec "!time ./%<"
        elseif &filetype == 'cpp'
                exec "!g++ % -o %<"
                exec "!time ./%<"
        elseif &filetype == 'java'
                exec "!javac %"
                exec "!time java %<"
        elseif &filetype == 'sh'
                :!time bash %
        elseif &filetype == 'python'
                exec "!clear"
                exec "!time python3 %"
        elseif &filetype == 'html'
                exec "!firefox % &"
        elseif &filetype == 'go'
                " exec "!go build %<"
                exec "!time go run %"
        elseif &filetype == 'mkd'
                exec "!~/.vim/markdown.pl % > %.html &"
                exec "!firefox %.html &"
        endif
endfunc

"缩进指示线"
let g:indentLine_char='┆'
let g:indentLine_enabled = 1

"python配置
let python_highlight_all=1
au Filetype python set tabstop=4
au Filetype python set softtabstop=4
au Filetype python set shiftwidth=4
au Filetype python set textwidth=79
au Filetype python set expandtab
au Filetype python set autoindent
au Filetype python set fileformat=unix
autocmd Filetype python set foldmethod=indent
autocmd Filetype python set foldlevel=99

"解除方向键
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

"括号颜色
let g:rbpt_colorpairs = [
                        \ ['brown',       'RoyalBlue3'],
                        \ ['Darkblue',    'SeaGreen3'],
                        \ ['darkgray',    'DarkOrchid3'],
                        \ ['darkgreen',   'firebrick3'],
                        \ ['darkcyan',    'RoyalBlue3'],
                        \ ['darkred',     'SeaGreen3'],
                        \ ['darkmagenta', 'DarkOrchid3'],
                        \ ['brown',       'firebrick3'],
                        \ ['gray',        'RoyalBlue3'],
                        \ ['darkmagenta', 'DarkOrchid3'],
                        \ ['Darkblue',    'firebrick3'],
                        \ ['darkgreen',   'RoyalBlue3'],
                        \ ['darkcyan',    'SeaGreen3'],
                        \ ['darkred',     'DarkOrchid3'],
                        \ ['red',         'firebrick3'],
                        \ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces

"ale代码检查,推荐用这个,syntastic可能会卡
let g:ale_fix_on_save = 1
 let g:ale_completion_enabled = 1
 let g:ale_sign_column_always = 1
 let g:airline#extensions#ale#enabled = 1
 
"syntastic代码检查
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
"let g:syntastic_check_on_open = 1
"let g:syntastic_check_on_wq = 0

set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

"ycm配色
highlight PMenu ctermfg=0 ctermbg=242 guifg=black guibg=darkgrey
highlight PMenuSel ctermfg=242 ctermbg=8 guifg=darkgrey guibg=black

"vim配置
syntax on
set backspace=2
set ic
set hlsearch
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,GB2312,big5
set cursorline
set autoindent
set smartindent
set scrolloff=4
set showmatch
set nu
set mouse=a
filetype indent on
set ignorecase
"代码折叠
"set foldmethod=indent
filetype plugin on
set mouse=v

使用的是Vundle做为插件管理,如果需要自己添加扩展,就在call vundle#begin()。。。call vundle#end()之间添加插件地址。

按f3 nerdtree文件树:

按f4,nerdcommenter使用#注释当前行。长按\,然后按cu,取消注释。

可以多行注释,按5\cc,向下注释5行。vim自带的在normal模式下:

:5,10 s/^/#/g,用搜索替换的方法注释也是挺好用的。

按f5,运行常见的代码

按f6,Autoformat代码格式化

按ctrl + p,ctrlp.vim模糊搜索

以上快捷键,如果和系统快捷键有冲突,可以根据自己的需求修改。

2、安装扩展,先安装Vundle插件管理:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

终端打开vim,如果报错,先忽略。在normal模式下,:PluginInstall,即可安装扩展。安装过程可能相当的慢,毕竟国内可能没有速度。

YouCompleteMe代码自动补全可能比较麻烦,如果无法补全,就需要自己编译一下:https://github.com/ycm-core/YouCompleteMe

需要自己先安装一下cmake

cd ~/.vim/bundle
git clone https://github.com/ycm-core/YouCompleteMe.git
cd ~/.vim/bundle/YouCompleteMe
./install.py --clangd-completer

如果下载编译真的很慢,自己大包了一份,放在根目录$HOME/.vim即可。

下载:http://download.zsxwz.com/file/16220046-455619032

3、pip安装需要的模块:

pip install pylint autopep8 flake8

留言

* - 必填