1.安装Vundle:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
2.拷贝'start'到'end'之间的内容到~/.vimrc
"******************start******************
set tabstop=4
set shiftwidth=4
set autoindent
set number
set ruler
syntax on
set cursorline cursorcolumn
set nocompatible " 强制Vim进入nocompatible模式
filetype off " 关闭文件类型检测
" 设置Vundle插件管理器的路径
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" 在这里列出你想要安装的插件
Plugin 'VundleVim/Vundle.vim'
Plugin 'jiangmiao/auto-pairs'
Plugin 'Chiel92/vim-autoformat'
Plugin 'godlygeek/tabular'
" 插件列表结束
call vundle#end() "所有Vundle命令都应该在vundle#begin和vundle#end之间
filetype plugin indent on " 开启文件类型检测、插件和缩进
"""""新文件标题""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.cc,*.hpp,*.sh,*.java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
" 如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1, "\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: yorkwei")
call append(line(".")+2, " > Mail: 1731939891@qq.com ")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, "\#########################################################################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: yorkwei")
call append(line(".")+2, " > Mail: 1731939891@qq.com")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if &filetype == 'cpp'
call append(line(".")+6, "#include <iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include <stdio.h>")
call append(line(".")+7, "")
endif
if &filetype == 'cc'
call append(line(".")+6, "#include <iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'hpp'
call append(line(".")+6, "#include <iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
" 新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc
" 假设你已经安装了 auto-pairs 插件
" 映射 Tab 键,在插入模式下如果光标在括号内则跳出括号
inoremap <expr> <Tab> pumvisible() ? "\<C-y>" : (strpart(getline('.'), col('.')-1, 1) =~ '[(){}]' ? "\<Right>" : "\<Tab>")
" 映射 Shift+Tab 键,用于反向跳出括号(可选)
inoremap <expr> <S-Tab> pumvisible() ? "\<C-e>" : (strpart(getline('.'), col('.')-2, 1) =~ '[(){}]' ? "\<Left>" : "\<S-Tab>")
" F3自动格式化代码
noremap <F3> :Autoformat<CR>
let g:autoformat_verbosemode=1
let g:clang_format_style_option = '~/.clang-format'
" 保存自动格式化
autocmd BufWritePre *.c,*.h,*.cpp,*.hpp,*.cc Autoformat
"******************end******************
3.保存~/.vimrc
4.终端输入vim,回车进入vim,输入:PluginInstall,等待插件下载完成
5.创建~/.clang-format文件
.clang-format文件内容:
SortIncludes: false