关于Vim

来源:互联网 发布:淘宝上网 编辑:程序博客网 时间:2024/06/05 11:21
工欲善其事,必先利其器

好早之前就想用了,太懒,一直没用,好吧,现在正式进军Vim啦



配置文件

先看一下我自己的配置文件(以后陆续更新):

set nocompatiblesource $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswinset diffexpr=MyDiff()function MyDiff()  let opt = '-a --binary '  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif  let arg1 = v:fname_in  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif  let arg2 = v:fname_new  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif  let arg3 = v:fname_out  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif  let eq = ''  if $VIMRUNTIME =~ ' '    if &sh =~ '\<cmd'      let cmd = '""' . $VIMRUNTIME . '\diff"'      let eq = '"'    else      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'    endif  else    let cmd = $VIMRUNTIME . '\diff'  endif  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eqendfunction"设置存储路径cd F:/code""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""显示相关""""""""""""""""""""""""""""""""""""""""""""""  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""windows 下 gvim打开默认全屏显示autocmd GUIEnter * simalt ~x"set shortmess=atI   " 启动的时候不显示那个援助乌干达儿童的提示  "winpos 0 0          " 设定窗口位置  "set lines=40 columns=155    " 设定窗口大小"显示行号set nuset backspace=indent,eol,start"语法高亮syntax on" 设置配色方案"colorscheme murphy"映射F3编译map <F3> :!g++ -std=c++11 % -o %<<cr>"映射F4运行map <F4> :!%<<cr>"linux 下把上面那行改成下面这一行"map <F4> :!./%<<cr>"映射F5 保存CPP文件并直接编译运行map <F5> :call CompileRunCpp()<CR>func! CompileRunCpp()    exec ":w"    exec "!g++ % -o %<"    exec "! %<"endfunc"映射F6 保存java文件并且编译运行map <F6> :call JAVA()<CR>func! JAVA()    exec ":w"    exec "!javac %"    exec "!java %<"endfunc"映射F2自动添加头文件等内容map <F2> :call SetTitle()<CR>func SetTitle()    let l = 0    let l = l + 1 | call setline(l,'/* **********************************************')    let l = l + 1 | call setline(l,'    > Auther        :  zzuspy')    let l = l + 1 | call setline(l,'    > Mail          :  zzuspy@qq.com')    let l = l + 1 | call setline(l,'    > Created Time  :  '.strftime('%c'))    "let l = l + 1 | call setline(l,'File Name   : '.expand('%'))    let l = l + 1 | call setline(l,'*********************************************** */')    let l = l + 1 | call setline(l, '#include <map>')    let l = l + 1 | call setline(l, '#include <set>')    let l = l + 1 | call setline(l, '#include <list>')    let l = l + 1 | call setline(l, '#include <cmath>')    let l = l + 1 | call setline(l, '#include <deque>')    let l = l + 1 | call setline(l, '#include <queue>')    let l = l + 1 | call setline(l, '#include <stack>')    let l = l + 1 | call setline(l, '#include <bitset>')    let l = l + 1 | call setline(l, '#include <cctype>')    let l = l + 1 | call setline(l, '#include <cstdio>')    let l = l + 1 | call setline(l, '#include <string>')    let l = l + 1 | call setline(l, '#include <vector>')    let l = l + 1 | call setline(l, '#include <complex>')    let l = l + 1 | call setline(l, '#include <cstdlib>')    let l = l + 1 | call setline(l, '#include <cstring>')    let l = l + 1 | call setline(l, '#include <fstream>')    let l = l + 1 | call setline(l, '#include <sstream>')    let l = l + 1 | call setline(l, '#include <utility>')    let l = l + 1 | call setline(l, '#include <iostream>')    let l = l + 1 | call setline(l, '#include <algorithm>')    let l = l + 1 | call setline(l, '#include <functional>')    let l = l + 1 | call setline(l, '#define LL long long')    let l = l + 1 | call setline(l, '#define INF 0x7fffffff')    let l = l + 1 | call setline(l, 'using namespace std;')    let l = l + 1 | call setline(l, '')    let l = l + 1 | call setline(l, 'int main() {')    let l = l + 1 | call setline(l, '')    let l = l + 1 | call setline(l, '   return 0;')    let l = l + 1 | call setline(l, '}')endfunc""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""键盘命令""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 映射全选+复制 ctrl+a""map <C-A> ggVGY""map! <C-A> <Esc>ggVGY""map <F12> gg=G" 选中状态下 Ctrl+c 复制vmap <C-c> "+y""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""实用设置""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 设置当文件被改动时自动载入set autoread" 隐藏工具栏set guioptions-=T  " 隐藏菜单栏"set guioptions-=m         " Tab键的宽度set tabstop=4" 统一缩进为4set softtabstop=4set shiftwidth=4" 不要用空格代替制表符set noexpandtab" 在行和段开始处使用制表符set smarttab" 显示行号set number" 历史记录数set history=1000"禁止生成临时文件set nobackupset noswapfile"搜索忽略大小写set ignorecase"搜索逐字符高亮set hlsearchset incsearch"行内替换set gdefault"编码设置"set enc=utf-8"set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936"语言设置set langmenu=zh_CN.UTF-8set helplang=cn"自动补全: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>ifunction! ClosePair(char)    if getline('.')[col('.') - 1] == a:char        return "\<Right>"    else        return a:char    endifendfunctionfiletype plugin indent on "打开文件类型检测, 加了这句才可以用智能补全set completeopt=longest,menu



vim多标签的切换

vim 从 vim7 开始加入了多标签切换的功能, 相当于多窗口.
之前的版本虽然也有多文件编辑功能, 但是总之不如这个方便啦。
用法:

:tabnew [++opt选项] [+cmd] 文件 建立对指定文件新的tab
:tabc 关闭当前的tab
:tabo 关闭所有其他的tab
:tabs 查看所有打开的tab
:tabp 前一个
:tabn 后一个

标准模式下:

gt , gT 可以直接在tab之间切换。

还有很多他命令 :help table



0 0
原创粉丝点击