总结的一些常用的vim配置
cd 到在home目录中的用户目录下
$ cd /home/[用户目录名]
$ touch .vimrc
然后将一下设置复制到 .vimrc这个文件中即可。
set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nu " 显示行号
syntax on " 语法高亮
set cursorline " 突出显示当前行
"set cursorcolumn " 突出显示当前列"
set tabstop=4 " tab键的空格数
set autoindent " 自动缩进
set softtabstop=4 " tab键的一个制表符,如果softtabstop=5,tabstop=4,则tab是1个制表符加1个空格的混合
set shiftwidth=4 " 设置缩进的空格数为
set cindent " 使用 C/C++ 语言的自动缩进方式
set ruler " 显示标尺
set hlsearch " 将搜索内容反白高亮 取消高亮,在命令行输入 :noh
set ignorecase "搜索忽略大小写
set mouse=a " 设置鼠标可用
"set guifont=Courier_New:h10:cANSI " 设置字体
"autocmd InsertLeave * se nocul " 用浅色高亮当前行
autocmd InsertEnter * se cul " 用浅色高亮当前行
set showcmd " 输入的命令显示出来,看的清楚些
set laststatus=2 " 启动显示状态行(1),总是显示状态行(2)
"set foldenable " 允许折叠
"set foldmethod=manual " 手动折叠
set cmdheight=2 " 总是显示状态行
filetype on " 侦测文件类型
filetype plugin on " 载入文件类型插件
filetype indent on " 为特定文件类型载入相关缩进文件
set viminfo+=! " 保存全局变量
set iskeyword+=_,$,@,%,#,- " 带有如下符号的单词不要被换行分割
set completeopt=preview,menu "代码补全
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"add括号之类的补全
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
: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
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1,"\#!/bin/bash")
call append(line("."), "")
elseif &filetype == 'python'
call setline(1,"#!/usr/bin/env python")
call append(line("."),"# coding=utf-8")
call append(line(".")+1, "")
elseif &filetype == 'ruby'
call setline(1,"#!/usr/bin/env ruby")
call append(line("."),"# encoding: utf-8")
call append(line(".")+1, "")
" elseif &filetype == 'mkd'
" call setline(1,"<head><meta charset=\"UTF-8\"></head>")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%:t"))
call append(line(".")+1, " > Author: Yunpeng.S")
call append(line(".")+2, " > Mail: syunpeng1122@163.com")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if expand("%:e") == 'cpp'
call append(line(".")+6, "#include<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
call append(line(".")+9, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
call append(line(".")+8, "")
endif
if expand("%:e") == 'h'
call append(line(".")+6, "#ifndef _".toupper(expand("%:t:r"))."_H_")
call append(line(".")+7, "#define _".toupper(expand("%:t:r"))."_H_")
call append(line(".")+8, "#ifdef __cplusplus")
call append(line(".")+9, "extern \"C\"")
call append(line(".")+10, "{")
call append(line(".")+11, "#endif")
call append(line(".")+12, "")
call append(line(".")+13, "")
call append(line(".")+14, "#ifdef __cplusplus")
call append(line(".")+15, "}")
call append(line(".")+16, "#endif")
call append(line(".")+17, "#endif //".toupper(expand("%:t:r"))."_H_")
endif
if &filetype == 'java'
call append(line(".")+6,"public class ".expand("%:r"))
call append(line(".")+7,"")
endif
endfunc
autocmd BufNewFile * normal G "新建文件后,自动定位到文件末尾