1 Star 0 Fork 1

kyle / 我的vimrc配置

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
.vimrc 10.64 KB
一键复制 编辑 原始数据 按行查看 历史
会PS的小码农 提交于 2021-05-07 10:27 . 优化注释
"去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible
filetype off
set number " 显示行号
syntax on " 高亮
" 设置字体大小
set guifont=Courier_new:h100:b:cDEFAULT
"高亮搜索
set hlsearch
"设置折叠方式
"set flodmethod=indent
"设置一个tab为4个空格
set ts=4
set expandtab
set autoindent
"高亮光标所在行
set cursorline
hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
"高亮光标所在列
set cursorcolumn
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>
"全选文档内容
nnoremap via ggvG$;
nnoremap <leader>a :call Foobar<cr>
function! Foobar()
echo 1
let first_argument = input()
echo first_argument
return first_argument
endfunction
"标签切换 配合ctrlp插件的 ctrl+t 方法使用很强大
"映射 leader n 为前一个标签
nnoremap <leader>n :tabn<cr>
"映射 leader p 为后一个标签
nnoremap <leader>p :tabp<cr>
"nnoremap <leader>o :tabo<cr> "关闭其他标签
"备注gt 命令会自动从左到右切换标签
"vib 实现选中空格到空格
"nnoremap vib f<space>,,lv;h
"vib 实现选中html 属性
nnoremap vib f<space>,lvf";
"vis 实现选中php变量连字符
nnoremap vis bbhf$ve
"简单注释方法
"vmap <silent> <Leader>/ :s_^\(\s\)\?_\1//<CR><Esc>:noh<CR>
"vmap <silent> <Leader>\ :s_^\(\s\)\?//_\1<CR><Esc>:noh<CR>
"nnoremap <silent> <Leader>/ :s_^\(\s\)\?_\1//<CR><Esc>:noh<CR>
"nnoremap <silent> <Leader>\ :s_^\(\s\)\?//_\1<CR><Esc>:noh<CR>
"上面的注释不是很好 不能兼容不同文件 有时间研究一下按文件自动注释然后写个函数
"
" 定义转化为HTML COMMENT的宏
" 使用方法: <F12>
map <F12> <ESC>0i<!--<ESC>$a--><ESC>
map <F10> <ESC>04x$hh3x<ESC>
"
"
"自动补全括号引号
:inoremap ( ()<ESC>i
":inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {<CR>}<ESC>O "换行补全法(if语句的{比较常用)
:inoremap { {}<ESC>i
":inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
":inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
"下面是插件 安装Vundle的方法: git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
"安装完Vundl后执行PluginInstall安装所有插件
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"插件管理插件Vundle
Plugin 'VundleVim/Vundle.vim'
"目录树插件
Plugin 'preservim/nerdtree'
""将F2设置为开关NERDTree的快捷键
map <f2> :NERDTreeToggle<cr>
"在NERDTree中打开当前文件位置
map <leader>v :NERDTreeFind<CR>
" 显示行号
let NERDTreeShowLineNumbers=1
" 防止出现 ^G 问题
let g:NERDTreeNodeDelimiter = "\u00a0"
" 是否显示隐藏文件
let NERDTreeShowHidden=1
"vim git操作插件
Plugin 'tpope/vim-fugitive'
"vim 标签首位跳转插件
"Plugin 'redguardtoo/evil-matchit'
"vim 强大的搜索插件
Plugin 'kien/ctrlp.vim'
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
"调用时,除非指定了起始目录,否则ctrlp将根据此变量设置其本地工作目录
"let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_working_path_mode = ''
"忽略目录、文件、符号链接
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)$',
\ 'file': '\v\.(exe|so|dll)$',
\ 'link': 'some_bad_symbolic_links',
\ }
"如果一个文件已经打开,会在新框里再次打开它,而非切换到当前方框。
let g:ctrlp_switch_buffer = 'et'
"默认设置项目跟目录为当前搜索目录
noremap <C-P> <Esc>:CtrlP pwd<CR>
"vim 代码补全插件
Plugin 'ervandew/supertab'
let g:SuperTabDefaultCompletionType = "<c-n>"
let g:SuperTabRetainCompletionType=2
"开启文件系统插件【自动注释插件依赖于此插件 】
filetype plugin on
"注释插件
Plugin 'scrooloose/nerdcommenter'
"多行注释压缩语法
let g:NERDCompactSexyComs = 1
"默认注释标签
let g:NERDCustomDelimiters = { 'c': { 'left': '/*','right': '*/' },'php': { 'left': '/*','right': '*/' },'py': { 'left': '#' },'sh': { 'left': '#' },'html': { 'left': '<!--','right': '-->' } }
"autocmd FileType html call commenter() "按当前文件执行方法
"成对符号操作插件
"比如单词首位插入双引号、去除双引号、双引号改单引号、双引号改括号等
Plugin 'tpope/vim-surround'
"目录文本匹配搜索插件
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plugin 'junegunn/fzf.vim'
"这个插件有个bug 问题如下 目前还没找到解决方法
"Error running '/home/liushuai/.vim/bundle/fzf/bin/fzf' '-m' '--prompt' './'
"'--preview-window' 'right' '--preview'
"''\''/home/liushuai/.vim/bundle/fzf.vim/bin/preview.sh'\'' {}'
"--expect=ctrl-v,ctrl-x,ctrl-t --h
"eight=22 > /tmp/vjEJcKa/8
"另一款文件内容搜索插件
Plugin 'dyng/ctrlsf.vim'
"语法检测插件 要求 VIM8以上才能安装
"下面是Ubuntu安装新VIM的方法
"sudo add-apt-repository ppa:jonathonf/vim
"sudo apt-get update
"sudo apt-get install vim
Plugin 'w0rp/ale'
"显示状态栏+不需要高亮行
let g:ale_sign_column_always = 1
let g:ale_set_highlights = 0
"错误和警告标志
let g:ale_sign_error = 'x'
let g:ale_sign_warning = '!'
"文件保存时,显示警告
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = 0
"使用clang对c和c++进行语法检查,对python使用pylint进行语法检查
let g:ale_linters = {
\ 'c++': ['clang'],
\ 'c': ['clang'],
\ 'python': ['pylint'],
\}
"使用clang分析的话,确保clang已经安装, 如若没有安装,即可运行如下命令进行安装
"sudo apt-get install -y clang
"html标签对应高亮
Plugin 'Valloric/MatchTagAlways'
"html 标签 按%首尾跳转
Plugin 'vim-scripts/matchit.zip'
"跳转html
let b:match_word='\<begin\>:\<end\>,'
\ . '\<while\>:\<continue\>:<break\>:\<endwhile\>,'
\ . '\<if\>:\<else if\>:<else\>,'
\ . '\<module\>:\<endmodule\>,'
\ . '\<task\>:\<endtask\>,'
\ . '\<function\>:\<endfunction\>,'
\ . '\<program\>:\<endprogram\>'
let b:matchit_ignorecase=1 "开启 忽略大小写
call vundle#end()
"自动保存最后修改时间
function SetLastModifiedTimes()
let cursor= line('.')
"获取行
let column=col('.')
"获取列
"获取光标位置
let pos = getpos(".")
let res = search("@LastEditTime","w")
let line = getline(res)
let newtime = " * @LastEditTime:".strftime("%Y-%m-%d %H:%I:%S")
let repl = substitute(line,".*$",newtime,"g")
if res
call setline(res,repl)
"执行Normal命令 将光标定位到函数执行之前的位置 这种方法不好用
"exec ":"+cursor+" gg"
"exec ":"+column+" l"
"定位光标到原来的位置 这个很好用
call setpos(".", pos)
endif
endfunction
autocmd BufWrite *.php call SetLastModifiedTimes()
"written
" 当新建 .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
" 加入shell,Makefile注释
func SetComment_sh()
call setline(3, "#================================================================")
call setline(4, "# Copyright (C) ".strftime("%Y")." EdisonLiu_ All rights reserved.")
call setline(5, "# ")
call setline(6, "# 文件名称:".expand("%:t"))
call setline(7, "# 创 建 者:LuZhenrong")
call setline(8, "# 创建日期:".strftime("%Y-%m-%d"))
call setline(9, "# 描 述:")
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