1 Star 0 Fork 1

kyle / 我的vimrc配置

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 5.83 KB
一键复制 编辑 原始数据 按行查看 历史
会PS的小码农 提交于 2020-05-27 15:37 . 优化创建文件自动注释

说明

"去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible
filetype off
set number " 显示行号
syntax on " 高亮
"高亮搜索
set hlsearch
"设置折叠方式
"set flodmethod=indent

"高亮光标所在行列
set cursorcolumn
set cursorline
" 自定义高亮颜色
hi CursorLine   cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white

" vim使用自动对起,也就是把当前行的对起格式应用到下一行
set autoindent
" 第二行,依据上面的对起格式,智能的选择对起方式,对于类似C语言编
set smartindent

"nnore 非递归映射
"空格控制折叠
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

"先映射逗号为 leader
let mapleader=','
let g:mapleader=','

"再映射逗号 +w 未保存
nnoremap <leader>w :w<cr>
inoremap <leader>w <Esc>:w<cr>

"vib 实现选中空格到空格
"nnoremap vib  f<space>,,lv;h

"vib 实现选中html 属性
nnoremap vib  f<space>,lvf";

"vis 实现选中php变量连字符
nnoremap vis  bbhf$ve

"自动补全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {<CR>}<ESC>O
":inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i

"下面是插件
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"插件管理插件Vundle
Plugin 'VundleVim/Vundle.vim'
"目录树插件
Plugin 'preservim/nerdtree'
""将F2设置为开关NERDTree的快捷键
map <f2> :NERDTreeToggle<cr>
" 显示行号
let NERDTreeShowLineNumbers=1
" 防止出现 ^G 问题
let g:NERDTreeNodeDelimiter = "\u00a0"

" 是否显示隐藏文件
let NERDTreeShowHidden=1
"vim git操作插件
Plugin 'tpope/vim-fugitive'

call vundle#end()

"自动保存最后修改时间
function SetLastModifiedTimes()
	let line = getline(7)
	let newtime = "* @LastEditTime: ".strftime("%Y年%m月%d日 %H时%I分%S秒")
	let repl = substitute(line,".*$",newtime,"g")
	let res = search("@LastEditTime","w")
	if res
		call setline(7,repl)
	endif
endfunction
autocmd BufWrite *.php call SetLastModifiedTimes()


" 当新建 .h .c .hpp .cpp .mk .sh等文件时自动调用SetTitle 函数
autocmd BufNewFile *.[ch],*.hpp,*.cpp,Makefile,*.mk,*.sh,*.php,*.html exec ":call SetTitle()" 
" 加入注释 

"加入c cpp h hpp ch mk php 等文件注释
func SetComment()
	call setline(1,"/*================================================================") 
	call append(line("."),   "*   Copyright (C) ".strftime("%Y")." EdisonLiu_ All rights reserved.")
	call append(line(".")+1, "*   ") 
	call append(line(".")+2, "* @Author: 偻儸小卒[EdisonLiu_]") 
	call append(line(".")+3, "* @Date:".strftime("%Y年%m月%d日 %H时%I分%S秒"))
	call append(line(".")+4, "* @LastEditTime:".strftime("%Y年%m月%d日 %H时%I分%S秒"))
	call append(line(".")+5, "* @Description:") 
	call append(line(".")+6, "*")
	call append(line(".")+7, "================================================================*/") 
	call append(line(".")+8, "")
	call append(line(".")+9, "")
endfunc

"加入html注释
func SetHtmlComment()
	call setline(1,"<!--") 
	call append(line("."),   " Copyright (C) ".strftime("%Y")." EdisonLiu_ All rights reserved.")
	call append(line(".")+1, "   ") 
	call append(line(".")+2, " @Author: 偻儸小卒[EdisonLiu_] 747357766@qq.com") 
	call append(line(".")+3, " @Date:".strftime("%Y年%m月%d日 %H时%I分%S秒"))
	call append(line(".")+4, " @LastEditTime:".strftime("%Y年%m月%d日 %H时%I分%S秒"))
	call append(line(".")+5, " @Description:") 
	call append(line(".")+6, "")
	call append(line(".")+7, "-->") 
	call append(line(".")+8, "")
	call append(line(".")+9, "")
endfunc

" 加入sh,Makefile注释
func SetComment_sh()
	call setline(3, "#================================================================") 
	call setline(4, "#   Copyright (C) ".strftime("%Y")." EdisonLiu_ All rights reserved.")
	call setline(5, "#   ") 
	call setline(6, "#   @Author: 偻儸小卒[EdisonLiu_] 747357766@qq.com") 
	call setline(7, "#   @Date:".strftime("%Y年%m月%d日 %H时%I分%S秒"))
	call setline(8, "#   @LastEditTime:".strftime("%Y年%m月%d日 %H时%I分%S秒")) 
	call setline(9, "#   @Description:") 
	call setline(10, "#")
	call setline(11, "#================================================================")
	call setline(12, "")
	call setline(13, "")
endfunc 
" 定义函数SetTitle,自动插入文件头 
func SetTitle()
	if &filetype == 'make' 
		call setline(1,"") 
		call setline(2,"")
		call SetComment_sh()
 
	elseif &filetype == 'sh' 
		call setline(1,"#!/system/bin/sh") 
		call setline(2,"")
		call SetComment_sh()
	elseif &filetype == 'html'
		call setline(2,"")
		call SetHtmlComment()
	else
	     call SetComment()
	     if expand("%:e") == 'hpp' 
		  call append(line(".")+10, "#ifndef _".toupper(expand("%:t:r"))."_H") 
		  call append(line(".")+11, "#define _".toupper(expand("%:t:r"))."_H") 
		  call append(line(".")+12, "#ifdef __cplusplus") 
		  call append(line(".")+13, "extern \"C\"") 
		  call append(line(".")+14, "{") 
		  call append(line(".")+15, "#endif") 
		  call append(line(".")+16, "") 
		  call append(line(".")+17, "#ifdef __cplusplus") 
		  call append(line(".")+18, "}") 
		  call append(line(".")+19, "#endif") 
		  call append(line(".")+20, "#endif //".toupper(expand("%:t:r"))."_H") 
 
	     elseif expand("%:e") == 'h' 
	  	call append(line(".")+10, "#pragma once") 
	     elseif &filetype == 'c' 
	  	call append(line(".")+10,"#include \"".expand("%:t:r").".h\"") 
	     elseif &filetype == 'cpp' 
	  	call append(line(".")+10, "#include \"".expand("%:t:r").".h\"") 
             elseif expand("%:e") == 'php' 
		call setline(1,"<?php  ")
		call append(line("."),"/*================================================================")
	  	call append(line(".")+11, " ?>")
	     endif
	endif
endfunc
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qqphp/my_vimrc_configuration.git
git@gitee.com:qqphp/my_vimrc_configuration.git
qqphp
my_vimrc_configuration
我的vimrc配置
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891