Vim配置文件

2008年11月06日 23:23

"if v:progname =~? "evim"
" finish
"endif

" 禁止兼容模式
set nocompatible

" 设置<BS>可以删除的字符
set backspace=indent,eol,start

" 除了VMS系统外 覆盖文件时保留备份
if has("vms")
set nobackup       
else
set backup       
endif

set history=50        " 保存50个命令历史
set ruler        " 始终显示当前位置
set showcmd        " 显示未完成的命令
set incsearch        " 输入搜索时显示匹配

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" 不使用Ex模式, 将Q映射
map Q gq

" In many terminal emulators the mouse works just fine, thus enable it.
set mouse=a

" 颜色数目大于2 或在 GUI 的情况下运行时
" 开启语法高亮与查找模式匹配
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif

" 如果支持自动命令
if has("autocmd")

" 允许文件类型探测.
" 使用文件类型相关的插件
" 'cindent' is on in C files, etc.
" 使用缩进文件.
filetype plugin indent on

" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!

" 一行长于78字符时自动换行.
autocmd FileType text setlocal textwidth=78

" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

augroup END

else

set autoindent        " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
         \ | wincmd p | diffthis

//输入括号或引号后 光标自动移到括号中
:inoremap () ()<Left>
:inoremap [] []<Left>
:inoremap "" ""<Left>

//在插入模式中使用Ctrl-x 来控制光标
:inoremap <C-H> <Left>
:inoremap <C-L> <Right>
:inoremap <C-J> <Down>
:inoremap <C-K> <Up>

//颜色主题
:colorscheme darkblue

Vim 学习笔记

2008年8月25日 22:31

Vim user_05.txt

普通模式

移动

向上滚屏 CTRL-u                向下滚屏 CTRL-d

当前文本位于屏幕顶部 zt    中央 zz        底部 zb

词首移动 w   反向 b    词末移动 e   反向 ge

$ 移到行尾   0 移到行首   ^移到第一行非空字符

移动到指定字符x fx    反向查找 F \
                      > ;重复命令 ,反向重复
移动到指定字符x tx    反向查找 T /

括号匹配 %

确定位置 CTRL-G

移动到指定行 xG     移动到文件首 gg    移动到文件指定部分 x% 按百分比

屏幕上方H 屏幕中间M 屏幕下方L

跳转

跳转 CTRL-]    回跳 CTRL-O    来回跳转 CTRL-O CTRL-I

返回G跳转之前的位置 '

显示跳转位置列表 :jumps

标记当前光标位置 m[a-z]    跳到该标记行首'[a-z]        跳到该标记行首列上`[a-z]   

取得所有标记列表 :marks

编辑

连接两行 J

保存文件并退出 ZZ

撤销操作 u    回退命令 CTRL-R

修改文本 c2wbe<Esc>         cc修改一整行

替换单个字符 r            重复修改 .

p 粘贴        光标前粘贴 P         交换两个字符 xp

拷贝文本 y          删除一个单词 daw

文件间拷贝粘贴 visual模式下 拷贝"+y     粘贴"+p

删除

删除字符 x

删除一整行 dd

删除单词 dw        删除到行尾 d$

设置

显示模式 set showmode

加行号 set number 关闭 set nonumber

查找

反向查找 ?

查找忽略大小写 set ignorecase

查找当前单词 *   反向查找 #   遍历 n     

高亮匹配 set hlsearch       查找过程中显示匹配 set incsearch     到达文件结尾后停止查找 set nowrapscan

进入插入模式 i a

光标下方添加新行 o    光标上方添加新行 O

可视模式     v  

行选择可视模式 V    块选择 CTRL-v   移动到另一端 o 块模式下O   

替换模式 R

Vim 自定义语法颜色显示

文件放在 ~/.vim/after/syntax/下 C语言的文件为c.vim

分屏

:new                                                      
左右分屏          ctrl+w+v    分屏间切换    ctrl+w+w                
扩大窗口          ctrl+w+                 缩小窗口          ctrl+w-
到窗口左面      ctrl+w+h                  到窗口右面      ctrl+w+l
到窗口上面      ctrl+w+k                  到窗口下面      ctrl+w+j