自己的vimrc配置

VIM的配置

正在学习vim中…
个人简单配置, 仅供参考

vim位置

打开vim, 输入:version, 向下浏览即可看到以下信息
个人用户主要修改~/.vimrc文件

    system vimrc file: "$VIM/vimrc"
    user vimrc file: "$HOME/.vimrc"
    2nd user vimrc file: "~/.vim/vimrc"
    user exrc file: "$HOME/.exrc"
    system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
    2nd user gvimrc file: "~/.vim/gvimrc"
    defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
    fall-back for $VIM: "/usr/share/vim"

个人vimrc文件

内容如下:

" 显示行号
set nu

" 定义tab的宽度
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab

" 取消vi和vim的一致性
set nocompatible

" 语法高亮
syntax on
" 检测文件类型
filetype on
" 为特定的文件类型载入相关缩进文件
filetype indent on

" 显示输入命令
set showcmd

" 显示标尺; 光标位置将显示在状态行上
set ruler

" 命令行(在状态行下)的高度,默认为1,这里是2
set laststatus=2
" cmd命令高度为2
set cmdheight=2

" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l

" 处理未保存的或只读文件的时候,弹出确认
set confirm

" 自动缩进
set cindent
set autoindent
set smartindent

" 搜索忽略大小写
set ignorecase
" 搜索逐字符高亮
set hlsearch
set incsearch

" 不生成临时文件(不建议)
set noswapfile
set nobackup

" 高亮显示匹配的括号
set showmatch

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自动为后缀名为py,sh,tcl,tk,csh的新文件执行文件头函数(注意后缀名逗号分隔没有空格处理)
autocmd BufNewFile *.py,*.sh,*.tcl,*.tk,*csh exec ":call SetTitle()" 
""定义函数SetTitle,自动插入文件头 
func SetTitle()
	if &filetype == 'sh'
		call setline(1, "#!/bin/bash")
	endif
	if &filetype == 'tcl'
		call setline(1, "#!/usr/bin/tclsh")
	endif
	if &filetype == 'python'
		call setline(1, "#!/usr/bin/python3")
	endif
	" tk 文件,修改filetype.vim,将tk类型从tcl类型中分离出来
	if &filetype == 'wish'
		call setline(1, "#!/usr/bin/wish")
	endif
	if &filetype == 'csh'
		call setline(1, "#!/usr/bin/csh")
	endif
	call append(line("."), "#*************************************************************************") 
	call append(line(".")+1, "#	> File Name: ".expand("%")) 
	call append(line(".")+2, "#	> Author: Leowin Xu") 
	call append(line(".")+3, "#	> Mail: xxxxxx@126.com ") 
	call append(line(".")+4, "#	> Created Time: ".strftime("%c")) 
	call append(line(".")+5, "# ************************************************************************/") 
	call append(line(".")+6, "")
endfunc 
" 创建新文件后,自动定位到文档的结尾
autocmd BufNewFile * normal G
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" 一键编译
"" F5 to run scripts (base on bash shell, cshell的time命令略有不同)
map <F5> :call CompileRun()<CR>
func! CompileRun()
	exec "w"
	if &filetype == 'c'
		exec "!gcc % -o %<"
		exec "!time ./%<"
	elseif &filetype == 'cpp'
		exec "!g++ % -o %<"
		exec "!time ./%<"
	elseif &filetype == 'python'
		exec "!time python3 %"
	elseif &filetype == 'sh'
		:!time bash %
	elseif &filetype == 'tcl'
		exec "!time tclsh %"
	elseif &filetype == 'wish'
		exec "!time wish %"
	elseif &filetype == 'csh'
		exec "!time csh %"
	endif
endfunc
  1. 其他的vimrc配置(选用)
" 高亮光标所在的当前行
" red(红),white(白),black(黑),green(绿),yellow(黄),blue(蓝),gray(灰),brown(棕),tan(褐色),syan(青色) 可以把darkred,white等换成你喜欢的颜色。ctermbg和ctermfg修改的是背景的颜色,可以删去。
set cursorline 
hi CursorLine      cterm=NONE ctermbg=darkred ctermfg=white 
hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white 

" 使用鼠标
" 模式: n(普通模式), v(可视模式), i(插入模式), c(命令行模式), h(在帮助文件里,以上所有模式)
" a(以上的所有模式)
" 以上模式可以搭配使用.
set mouse=a

" 本选项定义选择区的行为.只有可视和选择模式使用本选项
" 值: old(非越行, 是闭区间), inclusive(可越行,是闭区间), exclusive(可越行,非闭区间)
" "越行": 意味着光标是否允许定位在行后一个字符的地方
" "闭区间":意味着选择区的最后一个字符包含在操作范围之内
set selection=exclusive
" 逗号分隔的单词列表,指定什么场合开始选择时启动选择模式而不是可视模式
" 值: mouse(使用鼠标时), key(使用Shift+特殊键时), cmd(使用"v","V"或"Ctrl+V"时)
set selectmode=mouse,key

" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime = 1

" 共享剪贴板
set clipboard+=unnamed

" 设置魔术;改变搜索模式所用的特殊字符
set magic

" 自动保存
set autowrite

" 不要使用空格代替制表符
set noexpandtab

" 历史记录数
set history=1000
```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值