不带ycm的版本" 定义<Leader>
let mapleader=";"
set number " 显示行号
set laststatus=2 " 总是显示状态栏
set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离
set nowrap " 禁止折行
set hlsearch " 高亮显示搜索结果
set incsearch " 开启实时搜索
set ignorecase " 搜索时大小写不敏感
set nocompatible " 关闭兼容模式
set wildmenu " vim自身命令行模式智能补全
set noshowmatch " 不要高亮匹配括号
" 关键字高亮
syntax on
" 编码格式
set encoding=utf-8
set fileencodings=utf-8,default,gb18030,gbk,gb2312
" 启用自动备份
set backup
" 折叠
set foldmethod=manual " 手工定义折叠
set foldlevel=99 " 启动vim默认不折叠
" 设置快捷键将选中文本复制至系统剪贴板
vnoremap <Leader>y "+y
" 设置快捷键将系统剪贴板内容粘贴至vim
nmap <Leader>p "*p
nmap <Leader>P "*P
" 自动跳到上一次的光标位置
au BufReadPost * if line("'"") > 1 && line("'"") <= line("$") | exe "normal! g'"" | endif
" 关闭插入模式识别 <Esc> 开始的功能键
set noesckeys
" 设置不可见字符的显示方式
set list
set listchars=tab:-->,space:.
highlight SpecialKey ctermfg=darkgray
" C/C++ 代码格式
set cinoptions=l1,g0
" 设置缩进
autocmd BufNewFile,BufReadPost,BufNew * exec "call SetTab(4)"
autocmd BufNewFile,BufReadPost Makefile exec "set noexpandtab"
func SetTab(size)
exec 'set tabstop='.a:size
exec 'set softtabstop='.a:size
exec 'set shiftwidth='.a:size
set expandtab
set cindent
set smartindent
set autoindent
endfunc
" 新建文件,自动插入文件头
autocmd BufNewFile *.sh,*.py,*.c,*.cpp,*.h,*.hpp exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1, "#!/bin/bash")
call append(line("$"), "")
exec ":2"
elseif expand("%:e") == 'py'
call setline(1, "#!/usr/bin/env python")
call append(line("$"), "#coding=utf-8")
call append(line("$"), "")
exec ":3"
elseif expand("%:e") == 'c'
if expand("%") == "main.c"
call setline(1, "#include <stdio.h>")
call append(line("$"), "")
call append(line("$"), "int main(void) {")
call append(line("$"), " ")
call append(line("$"), " return 0;")
call append(line("$"), "}")
exec ":4"
endif
elseif expand("%:e") == 'cpp'
if expand("%") == "main.cpp"
call setline(1, "#include <iostream>")
call append(line("$"), "")
call append(line("$"), "int main() {")
call append(line("$"), " ")
call append(line("$"), " return 0;")
call append(line("$"), "}")
exec ":4"
endif
elseif expand("%:e") == 'h' || expand("%:e") == 'hpp'
call setline(1, "#ifndef _".toupper(expand("%:r"))."_".toupper(expand("%:e"))."_")
call append(line("$"), "#define _".toupper(expand("%:r"))."_".toupper(expand("%:e"))."_")
call append(line("$"), "")
call append(line("$"), "#endif")
exec ":3"
endif
endfunc
|