vim配置vimrc
新建文件,自动加入文件头
修改文件,保存时,自动更新修改时间字段
自动匹配括号,引号等
vimrc文件如下
"==========================================
"General
"========================================== " history存储长度。
set history=
set encoding=utf-
set fileencodings=ucs-bom,utf-,cp936
set fileencoding=gb2312
set termencoding=utf- "检测文件类型
filetype on
" 针对不同的文件类型采用不同的缩进格式
filetype indent on
"允许插件
filetype plugin on
"启动自动补全
filetype plugin indent on " 非兼容vi模式。去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible
set autoread " 文件修改之后自动载入。 " 取消备份。
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile " No annoying sound on errors
" 去掉输入错误的提示声音
set noerrorbells
set novisualbell
set t_vb=
set tm= "==========================================
" show and format
"==========================================
"显示行号:
set number
set nowrap " 取消换行。
""为方便复制,用<F2>开启/关闭行号显示:
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=<CR> "括号配对情况
set showmatch
" How many tenths of a second to blink when matching brackets
set mat= "设置文内智能搜索提示
" 高亮search命中的文本。
set hlsearch
" 搜索时忽略大小写
set ignorecase
" 随着键入即时搜索
set incsearch
" 有一个或以上大写字母时仍大小写敏感
set smartcase " 代码折叠
" set foldenable
" 折叠方法
" manual 手工折叠
" indent 使用缩进表示折叠
" expr 使用表达式定义折叠
" syntax 使用语法定义折叠
" diff 对没有更改的文本进行折叠
" marker 使用标记进行折叠, 默认标记是 {{{ 和 }}}
" set foldmethod=syntax
" 在左侧显示折叠的层次
" set foldcolumn=4 set tabstop= " 设置Tab键的宽度 [等同的空格个数]
set shiftwidth=
set expandtab " 将Tab自动转化成空格 [需要输入真正的Tab键时,使用 Ctrl+V + Tab]
" 按退格键时可以一次删掉 4 个空格
set softtabstop= set ai "Auto indent
set si "Smart indent "==========================================
" status
"==========================================
"显示当前的行号列号:
set ruler
""在状态栏显示正在输入的命令
set showcmd " Set 7 lines to the cursor - when moving vertically using j/k 上下滚动,始终在中间
set so= "set cursorline " 突出显示当前行 " 命令行(在状态行下)的高度,默认为1,这里是2
" set cmdheight=2
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
" Always show the status line
set laststatus= "==========================================
"colors and fonts
"==========================================
"开启语法高亮
syntax enable
syntax on "配色方案 三种,选一个
"colorscheme darkblue " 深蓝色配色方案。 "colorscheme desert " 经典配色方案。
"set background=dark " Set extra options when running in GUI mode
if has("gui_running")
set guioptions-=T
set guioptions+=e
set t_Co=
set guitablabel=%M\ %t
endif
"set guifont=Monaco:h20 " 字体 && 字号 "==========================================
" file encode
"========================================== " Use Unix as the standard file type
set ffs=unix,dos,mac " 如遇Unicode值大于255的文本,不必等到空格再折行。
set formatoptions+=m
" 合并两行中文时,不在中间加空格:
set formatoptions+=B "==========================================
"others
"========================================== " 自动完成
set completeopt=longest,menu
" 增强模式中的命令行自动完成操作
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc " Python 文件的一般设置,比如不要 tab 等
autocmd FileType python set tabstop= shiftwidth= expandtab
"自动补全配置
autocmd FileType python set omnifunc=pythoncomplete#Complete " Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif " A buffer becomes hidden when it is abandoned
"set hid " For regular expressions turn magic on
set magic " Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l "新建.c,.h,.sh,.Java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.hpp,*.cc,*.[ch],*.sh,*.Java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
if &filetype == 'sh'
call setline(,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+, "\# Author: carbonyang@shuame.com")
call append(line(".")+, "\# Description: carbonyang@shuame.com")
call append(line(".")+, "\# Created Time: ".strftime("%c"))
call append(line(".")+, "\# Modified Time: ".strftime("%c"))
call append(line(".")+, "\#########################################################################")
call append(line(".")+, "")
call append(line(".")+, "")
call append(line(".")+, "")
call append(line(".")+, "\#!/bin/bash")
call append(line(".")+, "")
else
call setline(, "/*************************************************************************")
call append(line("."), "\ * File Name: ".expand("%"))
call append(line(".")+, "\ * Author: carbonyang@shuame.com")
call append(line(".")+, "\ * Created Time: ".strftime("%Y-%m-%d %H:%M:%S %Z"))
call append(line(".")+, "\ * Modified Time: ".strftime("%Y-%m-%d %H:%M:%S %Z"))
call append(line(".")+, "\ * Description: ")
call append(line(".")+, "\ * ┏┛ ┻━━━━━┛ ┻┓")
call append(line(".")+, "\ * ┃ ┃")
call append(line(".")+, "\ * ┃ ━ ┃")
call append(line(".")+, "\ * ┃ ┳┛ ┗┳ ┃")
call append(line(".")+, "\ * ┃ ┃")
call append(line(".")+, "\ * ┃ ┻ ┃")
call append(line(".")+, "\ * ┃ ┃")
call append(line(".")+, "\ * ┗━┓ ┏━━━┛")
call append(line(".")+, "\ * ┃ ┃ 神兽保佑")
call append(line(".")+, "\ * ┃ ┃ 代码无虫")
call append(line(".")+, "\ * ┃ ┗━━━━━━━━━┓")
call append(line(".")+, "\ * ┃ ┣┓")
call append(line(".")+, "\ * ┃ ┏┛")
call append(line(".")+, "\ * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛")
call append(line(".")+, "\ * ┃ ┫ ┫ ┃ ┫ ┫")
call append(line(".")+, "\ * ┗━┻━┛ ┗━┻━┛")
call append(line(".")+, "************************************************************************/")
call append(line(".")+, "")
call append(line(".")+, "")
call append(line(".")+, "")
endif
if &filetype == 'cpp'
call append(line(".")+, "#include<iostream>")
call append(line(".")+, "")
call append(line(".")+, "using namespace std;")
call append(line(".")+, "")
call append(line(".")+, "")
endif
if &filetype == 'c'
call append(line(".")+, "#include<stdio.h>")
call append(line(".")+, "")
call append(line(".")+, "")
endif
autocmd BufNewFile * normal G
endfunc let g:update_time_time_stamp_leader = 'Modified Time: '
let g:update_time_enable =
let g:update_time_time_format = '%Y-%m-%d %H:%M:%S %Z'
map <F4> gg: <Esc>O<Esc>: call SetTitle()<cr> <Esc>G " 括号自动补全
inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {<CR>}<Esc>O
autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR> function ClosePair(char)
if getline('.')[col('.') - ] == a:char
return "\<Right>"
else
return a:char
endif
endf function CloseBracket()
if match(getline(line('.') + ), '\s*}') <
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - ] == "\\"
return a:char
elseif line[col - ] == a:char
return "\<Right>"
else
return a:char.a:char."\<Esc>i"
endif
endf
vimrc
自动更新修改时间需要用到插件update-time.vim
保存至.vim/plugin/即可自动加载
update-time代码:
" File: update-time.vim
" Author: QianChenglong <qianchenglong2012@gmail.com>
" Create Time: 2013-12-04 19:36:21 CST
" Last Change: 2013-12-05 12:14:15 CST
" Description: Automatic update Last Change time " SECTION: Init"{{{
if exists("g:loaded_update_time")
finish
endif
let g:loaded_update_time = let s:save_cpo = &cpo
set cpo&vim
"}}}
" SECTION: Varible"{{{
if !exists('g:update_time_time_stamp_leader')
let s:time_stamp_leader = 'Last Change: '
else
let s:time_stamp_leader = g:update_time_time_stamp_leader
endif if !exists('g:update_time_time_format')
let s:time_format = '%Y-%m-%d %H:%M:%S %Z'
else
let s:time_format = g:update_time_time_format
endif if !exists("g:update_time_begin_line")
let s:begin_line =
else
let s:begin_line = g:update_time_begin_line
endif if !exists('g:update_time_end_line')
let s:end_line =
else
let s:end_line = g:update_time_end_line
endif if !exists('g:update_time_enable')
let s:update_time_enable =
else
let s:update_time_enable = g:update_time_enable
endif
"}}}
" SECTION: Funtions"{{{
fun Update_time_update()
if ! &modifiable
return
endif
if ! s:update_time_enable
return
endif
let bufmodified = getbufvar('%', '&mod')
if ! bufmodified
return
endif
let pos = line('.').' | normal! '.virtcol('.').'|'
exe s:begin_line
let line_num = search(s:time_stamp_leader, '', s:end_line)
if line_num >
let line = getline(line_num)
let line = substitute(line, s:time_stamp_leader . '\zs.*', strftime(s:time_format), '')
call setline(line_num, line)
endif
exe pos
endf
fun Update_time_toggle()
let s:update_time_enable = !s:update_time_enable
endf
"}}}
" SECTION: Autocommands"{{{
autocmd BufWritePre * call Update_time_update()
"}}}
" SECTION: Commands"{{{
com! -nargs= UpdateTimeToggle call Update_time_toggle()
"}}}
" SECTION: Clean up"{{{
let &cpo = s:save_cpo
unlet s:save_cpo
"}}}
update-time
vim配置vimrc的更多相关文章
- vim 配置.vimrc文件
下面这个.vimrc文件是根据公司里的一个前辈配置的,这里记录下,方便以后使用.它的功能,其实跟网上很多.vimrc配置的相比,还是小儿科.我记录下来,主要还是因为自己已经习惯了这个工作环境跟快捷键. ...
- vim配置vimrc详解
vimrc的存放位置: 系统 vimrc 文件: "$VIM/vimrc" 用户 vimrc 文件: "$HOME/.vimrc" 用户 exrc 文件: &q ...
- vim配置vimrc详解(转)
vimrc的存放位置: 系统 vimrc 文件: "$VIM/vimrc" 用户 vimrc 文件: "$HOME/.vimrc" 用户 exrc 文件: &q ...
- 个人vim配置(.vimrc文件分享)
syntax enable syntax on colorscheme desert set nu! set nowrap set nobackup set backspace= set tabsto ...
- vim配置go语法高亮
操作系统 : CentOS7.3.1611_x64 go 版本 : go1.8.3 linux/amd64 vim版本 :version 7.4.160 vim配置go语言语法高亮的问题已经遇到过好几 ...
- ubuntu 配置vim(vimrc)
打开终端:ctrl+alt+t 进入vim文件:cd /etc/vim 打开vimrc文件:sudo gedit vimrc 然后在行末if语句前加上下面的内容," 这个符号为注释,后面内 ...
- linux 配置vim(vimrc)
打开终端:ctrl+alt+t 进入vim文件:cd /etc/vim 打开vimrc文件:sudo gedit vimrc 然后在行末if语句前加上下面的内容," 这个符号为注释,后面内 ...
- acm的ubuntu (ubuntu16.04 安装指南,chrome安装,vim配置,git设置和github,装QQ)
日常手贱把ubuntu14.04更新到了16.04,然后就game over了.mdzz,不然泥萌也看不到这篇博客了=.= 然后花了些时间重装了一个16.04版的,原来那个14.04的用可以用,就是动 ...
- 快速学习C语言三: 开发环境, VIM配置, TCP基础,Linux开发基础,Socket开发基础
上次学了一些C开发相关的工具,这次再配置一下VIM,让开发过程更爽一些. 另外再学一些linux下网络开发的基础,好多人学C也是为了做网络开发. 开发环境 首先得有个Linux环境,有时候家里机器是W ...
随机推荐
- Java中的String和StringBuffer
在任何编程语言中,字符串都是我们编写程序时不可避免要用到的常用的数据类型之一. 对于Java初学者而言,当谈到String和StringBuffer的区别时,通常都会有些困惑. 而要弄清楚两者之间的区 ...
- css可应用的渐进增强新特性
1. 让有滚动行为的元素平滑滚动 scroll-behavior: smooth; <div class="smooth"> </dvi> .smooth ...
- Python str 与 bytes 类型 之间的转换
bytes:字节数组,通常用它可以描述 “一个字符串”,只不过该字符串是 “bytes类型”,所以容易与str类型混淆,他们二者之间的转换: https://blog.csdn.net/lanchu ...
- 使用POI动态更新导出的EXCEL模板中的列
基本思路: 1.从附件服务器上取得模板的流文件 2.拿到流文件之后再使用workbook.write(outs);方法改变流文件中的数据. else if (pageContext.getParame ...
- python学习笔记(六)---sublime text3 创建python项目
1.创建项目 依次鼠标左键点击Project>Add Folder to Project...,选择test文件夹: 2.保存项目 依次鼠标左键点击Project>Save Project ...
- BZOJ2986 Non-Squarefree Numbers
神马的容斥原理实在是太神啦! 就是先二分一个数mid,看看有几个满足要求的数比他小. 查看的方法就是容斥原理... res = ((2 ^ 2)倍数个数 - ((2 ^ 2) * (3 ^ 2)倍数个 ...
- [例1.10]使用setw设置输出宽度的例子
[例1.10]使用setw设置输出宽度的例子: #include <iostream> #include <iomanip> using namespace std; void ...
- zepto 的 css 方法 -- 待续
链接 获取样式: getComputedStyle 什么是计算后的样式 就是经过css样式组合 和 js操作后 的 最后的结果 设置样式有三种方法: div.style.backgroundCol ...
- zend 2.2 db select 使用例子
<?php use Zend\Db\Sql\Select; // basic table $select0 = new Select; $select0->from('foo'); // ...
- BusyBox ifup udhcpc后台运行
/********************************************************************** * BusyBox ifup udhcpc后台运行 * ...