[整理]vim常用命令速查卡片
-
- 帖子: 2
- 注册时间: 2006-05-01 21:07
[整理]vim常用命令速查卡片
最近在学vim,由于命令较多查找不方便,就自己整理了这个
linuxsir上也有类似的,这个要比那个多些
尽量抽取些比较常见的,有些命令只有在经常编辑文本时才能体会它的方便
这些都是最基本的,本想把参见命令组合也加上,不过太多太灵活了~
很多时候其实你想做到什么效果,试一下真的能做到,所以多发挥想象试哈
程序部分太多了,有很多方便编写和查看程序的方法,ctags什么的等,这些大家就自己研究了
送给大家一句《建筑永恒之道》中的话
“学习所有方法,然后忘记它”
附上我的.vimrc
" 安装: sudo apt-get install vim-gtk
" 用法: 将本文件(.vimrc)拷贝到$HOME/
" 使用 murphy 调色板
" colo murphy
"中文help
if version >= 603
set helplang=cn
endif
" 设置自动缩进
set autoindent
" 设定文件浏览器目录为当前目录
set bsdir=buffer
" 设置编码
set enc=utf-8
" 设置文件编码
set fenc=utf-8
" 设置文件编码检测类型及支持格式
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
" 指定菜单语言
set langmenu=zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" 设置语法高亮度
" set syn=cpp
" 语法高亮
syntax enable
"显示行号
set nu!
set ruler
" 查找结果高亮度显示,立即匹配
set hlsearch
set showmatch
set incsearch
"设置退格键为普通模式
set backspace=2
"设定自动换行
set wrap
"HTML<>匹配
"set mps+=<:>
" C/C++注释
" set comments=://
" 修正自动C式样注释功能 <2005/07/16>
set comments=s1:/*,mb:*,ex0:/
" 增强检索功能
set tags=./tags,./../tags,./**/tags
" 保存文件格式
set fileformats=unix,dos
" 键盘操作
map <Up> gk
map <Down> gj
" 命令行高度
set cmdheight=1
"cscope"
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
set cscopetag
set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i-
endif
if has('gui_running')
let do_syntax_sel_menu=1
endif
set nobackup
set fileencodings=ucs-bom,utf-8,gbk
"显示文件编码信息
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P
if has('mouse')
set mouse=a
endif
" Key mappings to ease browsing long lines
noremap <C-J> gj
noremap <C-K> gk
noremap <Down> gj
noremap <Up> gk
inoremap <Down> <C-O>gj
inoremap <Up> <C-O>gk
if has('autocmd')
function! SetFileEncodings(encodings)
let b:my_fileencodings_bak=&fileencodings
let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
let &fileencodings=b:my_fileencodings_bak
unlet b:my_fileencodings_bak
endfunction
function! CheckFileEncoding()
if &modified && &fileencoding != ''
exec 'e! ++enc=' . &fileencoding
endif
endfunction
function! ConvertHtmlEncoding(encoding)
if a:encoding ==? 'gb2312'
return 'gbk' " GB2312 imprecisely means GBK in HTML
elseif a:encoding ==? 'iso-8859-1'
return 'latin1' " The canonical encoding name in Vim
elseif a:encoding ==? 'utf8'
return 'utf-8' " Other encoding aliases should follow here
else
return a:encoding
endif
endfunction
function! DetectHtmlEncoding()
if &filetype != 'html'
return
endif
normal m`
normal gg
if search('\c<meta http-equiv=\("\?\)Content-Type\1 content="text/html; charset=[-A-Za-z0-9_]\+">') != 0
let reg_bak=@"
normal y$
let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+')
let charset=ConvertHtmlEncoding(charset)
normal ``
let @"=reg_bak
if &fileencodings == ''
let auto_encodings=',' . &encoding . ','
else
let auto_encodings=',' . &fileencodings . ','
endif
if charset !=? &fileencoding &&
\(auto_encodings =~ ',' . &fileencoding . ',' || &fileencoding == '')
silent! exec 'e ++enc=' . charset
endif
else
normal ``
endif
endfunction
function! GnuIndent()
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
setlocal shiftwidth=2
setlocal tabstop=8
endfunction
function! RemoveTrailingSpace()
if $VIM_HATE_SPACE_ERRORS != '0' &&
\(&filetype == 'c' || &filetype == 'cpp' || &filetype == 'vim')
normal m`
silent! :%s/\s\+$//e
normal ``
endif
endfunction
" Highlight space errors in C/C++ source files (Vim tip #935)
if $VIM_HATE_SPACE_ERRORS != '0'
let c_space_errors=1
endif
" Use Canadian spelling convention in engspchk (Vim script #195)
let spchkdialect='can'
" Show syntax highlighting attributes of character under cursor (Vim
" script #383)
map <Leader>a :call SyntaxAttr()<CR>
" Automatically find scripts in the autoload directory
au FuncUndefined * exec 'runtime autoload/' . expand('<afile>') . '.vim'
" File type related autosetting
au FileType c,cpp setlocal cinoptions=:0,g0,(0,w1 shiftwidth=4 tabstop=4
au FileType diff setlocal shiftwidth=4 tabstop=4
au FileType html setlocal autoindent indentexpr=
au FileType changelog setlocal textwidth=76
" Text file encoding autodetection
au BufReadPre *.gb call SetFileEncodings('gbk')
au BufReadPre *.big5 call SetFileEncodings('big5')
au BufReadPre *.nfo call SetFileEncodings('cp437')
au BufReadPost *.gb,*.big5,*.nfo call RestoreFileEncodings()
au BufWinEnter *.txt call CheckFileEncoding()
" Detect charset encoding in an HTML file
au BufReadPost *.htm* nested call DetectHtmlEncoding()
" Recognize standard C++ headers
au BufEnter /usr/include/c++/* setf cpp
au BufEnter /usr/include/g++-3/* setf cpp
" Setting for files following the GNU coding standard
au BufEnter /usr/* call GnuIndent()
" Remove trailing spaces for C/C++ and Vim files
au BufWritePre * call RemoveTrailingSpace()
endif
linuxsir上也有类似的,这个要比那个多些
尽量抽取些比较常见的,有些命令只有在经常编辑文本时才能体会它的方便
这些都是最基本的,本想把参见命令组合也加上,不过太多太灵活了~
很多时候其实你想做到什么效果,试一下真的能做到,所以多发挥想象试哈
程序部分太多了,有很多方便编写和查看程序的方法,ctags什么的等,这些大家就自己研究了
送给大家一句《建筑永恒之道》中的话
“学习所有方法,然后忘记它”
附上我的.vimrc
" 安装: sudo apt-get install vim-gtk
" 用法: 将本文件(.vimrc)拷贝到$HOME/
" 使用 murphy 调色板
" colo murphy
"中文help
if version >= 603
set helplang=cn
endif
" 设置自动缩进
set autoindent
" 设定文件浏览器目录为当前目录
set bsdir=buffer
" 设置编码
set enc=utf-8
" 设置文件编码
set fenc=utf-8
" 设置文件编码检测类型及支持格式
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
" 指定菜单语言
set langmenu=zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" 设置语法高亮度
" set syn=cpp
" 语法高亮
syntax enable
"显示行号
set nu!
set ruler
" 查找结果高亮度显示,立即匹配
set hlsearch
set showmatch
set incsearch
"设置退格键为普通模式
set backspace=2
"设定自动换行
set wrap
"HTML<>匹配
"set mps+=<:>
" C/C++注释
" set comments=://
" 修正自动C式样注释功能 <2005/07/16>
set comments=s1:/*,mb:*,ex0:/
" 增强检索功能
set tags=./tags,./../tags,./**/tags
" 保存文件格式
set fileformats=unix,dos
" 键盘操作
map <Up> gk
map <Down> gj
" 命令行高度
set cmdheight=1
"cscope"
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
set cscopetag
set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i-
endif
if has('gui_running')
let do_syntax_sel_menu=1
endif
set nobackup
set fileencodings=ucs-bom,utf-8,gbk
"显示文件编码信息
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P
if has('mouse')
set mouse=a
endif
" Key mappings to ease browsing long lines
noremap <C-J> gj
noremap <C-K> gk
noremap <Down> gj
noremap <Up> gk
inoremap <Down> <C-O>gj
inoremap <Up> <C-O>gk
if has('autocmd')
function! SetFileEncodings(encodings)
let b:my_fileencodings_bak=&fileencodings
let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
let &fileencodings=b:my_fileencodings_bak
unlet b:my_fileencodings_bak
endfunction
function! CheckFileEncoding()
if &modified && &fileencoding != ''
exec 'e! ++enc=' . &fileencoding
endif
endfunction
function! ConvertHtmlEncoding(encoding)
if a:encoding ==? 'gb2312'
return 'gbk' " GB2312 imprecisely means GBK in HTML
elseif a:encoding ==? 'iso-8859-1'
return 'latin1' " The canonical encoding name in Vim
elseif a:encoding ==? 'utf8'
return 'utf-8' " Other encoding aliases should follow here
else
return a:encoding
endif
endfunction
function! DetectHtmlEncoding()
if &filetype != 'html'
return
endif
normal m`
normal gg
if search('\c<meta http-equiv=\("\?\)Content-Type\1 content="text/html; charset=[-A-Za-z0-9_]\+">') != 0
let reg_bak=@"
normal y$
let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+')
let charset=ConvertHtmlEncoding(charset)
normal ``
let @"=reg_bak
if &fileencodings == ''
let auto_encodings=',' . &encoding . ','
else
let auto_encodings=',' . &fileencodings . ','
endif
if charset !=? &fileencoding &&
\(auto_encodings =~ ',' . &fileencoding . ',' || &fileencoding == '')
silent! exec 'e ++enc=' . charset
endif
else
normal ``
endif
endfunction
function! GnuIndent()
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
setlocal shiftwidth=2
setlocal tabstop=8
endfunction
function! RemoveTrailingSpace()
if $VIM_HATE_SPACE_ERRORS != '0' &&
\(&filetype == 'c' || &filetype == 'cpp' || &filetype == 'vim')
normal m`
silent! :%s/\s\+$//e
normal ``
endif
endfunction
" Highlight space errors in C/C++ source files (Vim tip #935)
if $VIM_HATE_SPACE_ERRORS != '0'
let c_space_errors=1
endif
" Use Canadian spelling convention in engspchk (Vim script #195)
let spchkdialect='can'
" Show syntax highlighting attributes of character under cursor (Vim
" script #383)
map <Leader>a :call SyntaxAttr()<CR>
" Automatically find scripts in the autoload directory
au FuncUndefined * exec 'runtime autoload/' . expand('<afile>') . '.vim'
" File type related autosetting
au FileType c,cpp setlocal cinoptions=:0,g0,(0,w1 shiftwidth=4 tabstop=4
au FileType diff setlocal shiftwidth=4 tabstop=4
au FileType html setlocal autoindent indentexpr=
au FileType changelog setlocal textwidth=76
" Text file encoding autodetection
au BufReadPre *.gb call SetFileEncodings('gbk')
au BufReadPre *.big5 call SetFileEncodings('big5')
au BufReadPre *.nfo call SetFileEncodings('cp437')
au BufReadPost *.gb,*.big5,*.nfo call RestoreFileEncodings()
au BufWinEnter *.txt call CheckFileEncoding()
" Detect charset encoding in an HTML file
au BufReadPost *.htm* nested call DetectHtmlEncoding()
" Recognize standard C++ headers
au BufEnter /usr/include/c++/* setf cpp
au BufEnter /usr/include/g++-3/* setf cpp
" Setting for files following the GNU coding standard
au BufEnter /usr/* call GnuIndent()
" Remove trailing spaces for C/C++ and Vim files
au BufWritePre * call RemoveTrailingSpace()
endif
- leal
- 帖子: 1119
- 注册时间: 2005-08-29 14:49
- 来自: 杭州
- 联系:
-
- 帖子: 2
- 注册时间: 2006-05-01 21:07
- adagio
- 论坛版主
- 帖子: 22110
- 注册时间: 2008-02-17 23:47
- 来自: 美丽富饶的那啥星球
可恶的挖坟党
明天就换大三八!
——8核CPU、8G内存、8T硬盘……
8卡交火,80寸大屏放8个……
IPv8的光纤要8条……
---------------------------------------------------------------------------------
★ [图片版]新手当自强(续)FAQ
★ [新手进阶]挂载、fstab、调整linux分区
★ [图片版]E17桌面环境配置手把手
——8核CPU、8G内存、8T硬盘……
8卡交火,80寸大屏放8个……
IPv8的光纤要8条……
---------------------------------------------------------------------------------
★ [图片版]新手当自强(续)FAQ
★ [新手进阶]挂载、fstab、调整linux分区
★ [图片版]E17桌面环境配置手把手
- ebok
- 帖子: 852
- 注册时间: 2008-02-15 0:09
- fortruth
- 帖子: 1795
- 注册时间: 2005-11-06 1:51
- 来自: 七彩云世界
- 联系:
- aquCHAOS
- 帖子: 58
- 注册时间: 2008-08-14 11:26
Re: [整理]vim常用命令速查卡片
弱弱问一下,那个:set warp自动换行为什么我设置不了?
- eagle5678
- 帖子: 1865
- 注册时间: 2006-07-08 14:07
-
- 帖子: 4
- 注册时间: 2009-02-14 14:41
Re: [整理]vim常用命令速查卡片
这个图 真是好东西啊~~
正在做操作系统课设 ,不得不用 vim了 ,用惯了 cb~~唉~
不过这样更专业~~专业~~
正在做操作系统课设 ,不得不用 vim了 ,用惯了 cb~~唉~
不过这样更专业~~专业~~
-
- 帖子: 100
- 注册时间: 2008-09-19 1:03
Re: [整理]vim常用命令速查卡片
额……也附上我的vimrc好了……
用Vim打开就可以看到折叠效果,不过要完全使用里面所有的功能至少需要vimtweak和其余提到的插件才行。
下面是我的插件包:
代码: 全选
" ==========================================================
" File Name: vimrc
" Author: StarWing
" Version: 0.5 (652)
" Last Change: 2009-06-08 13:02:29
" Must After Vim 7.0 {{{1
if v:version < 700
finish
endif
" }}}1
" ==========================================================
" Settings {{{1
" Init settings {{{2
silent! so $VIMRUNTIME/vimrc_example.vim
set encoding=utf-8
scriptencoding utf-8
if has('eval')
let s:cpo_save = &cpo
endif
set cpo&vim " set cpo-=C cpo-=b
" Generic Settings {{{2
set ambiwidth=double
set bsdir=buffer
set complete-=i
set completeopt=longest,menu
set diffopt+=vertical
set display=lastline
set fileencodings=ucs-bom,utf-8,cp936,gb18030,latin1
set formatoptions+=mB2
set shiftwidth=4
set textwidth=78
set titlestring=%f%(\ %m%h%r%)\ -\ StarWing's\ Vim
set viminfo+=!
set virtualedit=block
set wildcharm=<C-Z>
set wildmenu
if v:version >= 603
set helplang=cn
endif
if has('eval')
" diffexpr {{{3
set diffexpr=rc:my_diff('diff')
function! rc:my_diff(cmd)
let cmd = [a:cmd, '-a --binary', v:fname_in, v:fname_new]
if &diffopt =~ 'icase'
let cmd[1] .= ' -i'
endif
if &diffopt =~ 'iwhite'
let cmd[1] .= ' -b'
endif
call writefile(split(system(join(cmd)), "\n"), v:fname_out)
endfunction " }}}3
endif
" System specified Settings {{{2
if has("win32") " {{{3
if !isdirectory($VIM.'/swapfiles')
call mkdir($VIM.'/swapfiles', 'p')
endif
if isdirectory($VIM.'/swapfiles')
set backupdir=$VIM/swapfiles
set directory=$VIM/swapfiles
endif
if &encoding !=? "cp936"
set termencoding=cp936
lang mes zh_CN.UTF-8
set langmenu=zh_CN.UTF-8
silent! so $VIMRUNTIME/delmenu.vim
silent! so $VIMRUNTIME/menu.vim
endif
elseif has('unix') " {{{3
if !isdirectory(expand('~/.vim/swapfiles'))
silent! call mkdir('~/.vim/swapfiles', 'p')
endif
if isdirectory(expand('~/.vim/swapfiles'))
set backupdir=~/.vim/swapfiles
set directory=~/.vim/swapfiles
endif
if &term == 'linux'
" lang C
endif
endif " }}}3
" }}}2
" ----------------------------------------------------------
" Helpers {{{1
" Environment Variables Setting {{{2
if has('eval')
function! s:globfirst(pattern) " {{{3
return simplify(split(glob(a:pattern), '\n', 1)[0])
endfunction " }}}3
" $VIMDIR {{{3
for dir in split(globpath(&rtp, "plugin/*.vim"), "\<NL>")
let $VIMDIR = fnamemodify(dir, ":p:h:h")
break
endfor
" $PATH in win32 {{{3
if has("win32")
let $PATH = $VIM."/vimfiles/tools;".$PATH
if isdirectory($VIM.'/../minGW/bin') && $PATH !~ 'minGW/bin'
let s:mingw_path = s:globfirst($VIM.'/../minGW/')
let $PATH = s:mingw_path.'bin;'.$PATH
let s:mingw_path = escape(s:mingw_path, ' ')
let &path .= ','.s:mingw_path.'include,'.s:mingw_path.'include\**,'.
\ s:mingw_path.'lib\gcc\**'
unlet s:mingw_path
endif
endif
" $DOC and $WORK {{{3
let s:spec_path = has('win32') ? [['$DOC', 'F:\Document'],
\ ['$WORK', 'F:\Work']]
\ : [['$DOC', '~/Document'],
\ ['$WORK', '~/Work']]
for [var, path] in s:spec_path
if isdirectory(path)
exec 'let '.var.'="'.escape(path,'\"').'"'
endif
endfor
unlet s:spec_path
" $PRJDIR {{{3
for dir in ['~', $VIM, $VIM.'/..', $WORK]
if isdirectory(expand(dir."/prj"))
let $PRJDIR = s:globfirst(dir."/prj")
break
endif
endfor
if !exists('$PRJDIR') && exists('$WORK')
let $PRJDIR = $WORK
endif
if exists('$PRJDIR')
cd $PRJDIR
endif " }}}3
endif " }}}2
" Generic autocmds {{{2
if has('autocmd')
augroup vimrc_autocmds
function! s:vimrc_write() " {{{3
let time = strftime("%Y-%m-%d %H:%M:%S")
let pos = winsaveview()
$|if search('\c^" Vimrc History', 'bW')
call append(line('.'), '" Write at '.time)
endif
1|if search('\c^"\s*Last Change:', 'W')
call setline(line('.'),
\ matchstr(getline('.'), '\c^"\s*Last Change:\s*').time)
endif
1|if search('\c^"\s*Version:', 'W')
let pat = '^"\s*[Vv]ersion:\v.{-}\ze%(\s*\((\d+)\))=$'
let pv = matchlist(getline('.'), pat)
if empty(pv[1])
call setline('.', getline('.').' (1)')
else
call setline('.', pv[0].' ('.(str2nr(pv[1], 10)+1).')')
endif
endif
call winrestview(pos)
endfunction
" }}}3
au BufFilePost * filetype detect|redraw
au BufWritePre $MYVIMRC silent call s:vimrc_write()
au BufWritePre * let &backup = (getfsize(expand('%')) > 500000)
if has("cscope")
au VimLeave * cs kill -1
endif
augroup END
endif
" Generic commands {{{2
if has("eval")
" RestoreGUI {{{3
if has('gui_running')
let s:gfn_vim = has('win32') ? 'Consolas:h10:cANSI' : 'Consolas\ 10'
let s:囗囗囗_vim = has('win32') ? iconv('新宋体', 'utf-8', 'cp936').
\ ':h10:cGB2312' : 'WenQuanYi\ Bitmap\ Song\ 10'
let s:clrs_vim = has('win32') ? 'evening' : 'brookstream'
command! -bar RestoreGUI
\ exec 'silent! colorscheme '.s:clrs_vim
\| set go=eLr co=120 lines=35
\| exec 'set gfn='.s:gfn_vim.' 囗囗囗='.s:囗囗囗_vim
RestoreGUI
else
silent! colorscheme brookstream
endif
" EX, EV, EF, ES, EP {{{3
let EX_exec = ''
if has('win32')
let EX_exec = 'start explorer'
elseif has('unix')
let EX_exec = 'nautilus'
endif
command! -nargs=* -complete=file EX exec '!'.EX_exec.' '.
\ matchstr(glob(<q-args>), '\v.{-}\ze(\n|$)')
\ |call feedkeys("\n", 't')
command! EV EX $VIM
command! EF EX %:p:h
if exists('$VIMDIR')
command! ES EX $VIMDIR
endif
if exists('$PRJDIR')
command! EP EX $PRJDIR
endif
" DarkRoom {{{3
if has('win32')
function! s:dark_room(alpha, bang)
" a bug in Vista
if !exists('g:cur_alpha') && !exists('g:go_save')
\ && system('ver') =~ ' 6.'
call libcallnr("vimtweak.dll", "EnableTopMost", 0)
endif
if exists('g:cur_alpha') && a:alpha == g:cur_alpha
\ || !exists('g:cur_alpha') && a:alpha == 255
if !exists('g:go_save')
let g:go_save = &go
set go& go-=m go-=L go-=T go-=r stal&
if a:bang == '!'
call libcallnr("vimtweak.dll", "EnableTopMost", 1)
endif
call libcallnr("vimtweak.dll", "EnableCaption", 0)
call libcallnr("vimtweak.dll", "EnableMaximize", 1)
else
let &go = g:go_save
unlet g:go_save
call libcallnr("vimtweak.dll", "EnableMaximize", 0)
call libcallnr("vimtweak.dll", "EnableCaption", 1)
call libcallnr("vimtweak.dll", "EnableTopMost", 0)
endif
else
let g:cur_alpha = a:alpha
call libcallnr("vimtweak.dll", "SetAlpha", a:alpha)
endif
endfunction
command! -bang -bar -count=255 Darkroom call s:dark_room(<count>, '<bang>')
for var in ['TopMost', 'Caption', 'Maximize']
exec "command! -bar -count=1 Enable".var.
\ " call libcallnr('vimtweak.dll',".
\ "'Enable".var."', <count>)"
endfor
map <F12> :<C-U>Darkroom!<CR>
imap <F12> <ESC><F12>a
endif
" AddTo, SoScript {{{3
if exists("$VIMDIR")
command! -nargs=1 -complete=customlist,VimfilesDirComplete
\ AddTo call rename(expand('%'),
\ $VIMDIR.'/<args>/'.expand('%:t')) | checkt
let Script_folder = 'script'
command! -nargs=1 -complete=customlist,ScriptDirFileComplete
\ SoScript exec 'so $VIMDIR/'.Script_folder.'/<args>'
function! VimfilesDirComplete(ArgLead, ...)
return map(filter(split(globpath($VIMDIR,
\ escape(a:ArgLead, '?*[').'*'), "\n"),
\ 'isdirectory(v:val)'),
\ 'fnamemodify(v:val, ":t")')
endfunction
function! ScriptDirFileComplete(ArgLead, ...)
return map(split(globpath($VIMDIR.'/scripts',
\ escape(a:ArgLead, '?*[').'*'), "\n"),
\ 'fnamemodify(v:val, ":t")')
endfunction
endif
" Font Size {{{3
let s:gf_pat = has('win32') ? 'h\zs\d\+' : '\d\+$'
command! -bar -count=10 FSIZE let &gfn = substitute(&gfn, s:gf_pat,
\ <count>, '') | let &囗囗囗 = substitute(&囗囗囗, s:gf_pat,
\ <count>, '')
" }}}3
endif " }}}2
" Generic maps {{{2
" explorer invoke {{{3
if exists(':Explorer') == 2
nmap <leader>ex :EX<CR>
vmap <leader>ex "ey:EX <C-R>e<CR>
map <leader>ev :<C-U>EV<CR>
map <leader>es :<C-U>ES<CR>
map <leader>ep :<C-U>EP<CR>
map <leader>es :<C-U>ES<CR>
endif
" filetype settings {{{3
map <leader>fc :<C-U>setf c<CR>
map <leader>f+ :<C-U>setf cpp<CR>
map <leader>fj :<C-U>setf java<CR>
map <leader>ft :<C-U>setf text<CR>
map <leader>fv :<C-U>setf vim<CR>
" run current line {{{3
nmap <leader>rc :exec getline('.')[col('.')-1:]<CR>
vmap <leader>rc y:exec @"<CR>
nmap <leader>ec :echo eval(getline('.'))[col('.')-1:]<CR>
vmap <leader>ec y:echo eval(@")<CR>
" syntax stack {{{3
nmap <leader>ss :for id in synstack(line('.'),col('.'))
\\|echo synIDattr(id, "name")
\\|endfor<CR>
" vimrc edit {{{3
map <leader>re :drop $MYVIMRC<CR>
map <leader>rr :so $MYVIMRC<CR>
" clipboard operations {{{3
if has('eval')
for op in ['y', 'Y', 'p', 'P']
exec 'nmap <leader>c'.op.' "+'.op
exec 'vmap <leader>c'.op.' "+'.op.'gv'
endfor
" inner buffer
function! s:inner_buf()
let line1 = nextnonblank(1)
if line1 == 0
" the buffer is blank, select it like with aa
norm! ggVG
return
endif
exec "norm!" line1."ggV". prevnonblank("$")."G"
endfunc
nor ii :<C-U>call <SID>inner_buf()<CR>
nun ii| sunm ii
" all buffer
nor aa :<C-U>norm! ggVG<CR>
nun aa| sunm aa
" get Global
nor gG :norm! ggVG<CR>
sunm gG
" Build buffer with zip
nmap zB gGzp
" get text zipped
nmap gz zyaa``
" Zip Yank and Put
map zy <leader>cy
map zY <leader>cY
map zp <leader>cp
map zP <leader>cP
" set Y operator tp y$
map Y y$
endif
" indent {{{3
xmap > >gv
xmap < <gv
map g= gg=G
" quick complete (against supertab) {{{3
inor <m-n> <c-n>
inor <m-p> <c-p>
" window moving {{{3
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
map <C-,> <C-W><
map <C-.> <C-W>>
map <C--> <C-W>-
map <C-+> <C-W>+
map <C-=> <C-W>=
" Function Key maps {{{3
" f1: show the wildmenu {{{4
map <F1> :<C-U>emenu <C-Z>
imap <F1> <ESC><F1>
" in cmode, it means print time
cnoremap <f1> <C-R>=escape(strftime("%Y-%m-%d %H:%M:%S"), '\ ')<CR>
" f4: clear hlsearch and qf/loc window {{{4
map <F4> :<C-U>noh\|pcl\|ccl\|lcl<CR>
imap <F4> <ESC><F4>a
" f12: full screen in Windows {{{4
if has("win32") && has("gui_running")
map <F12> :<C-U>simalt ~x<CR>
imap <F12> <ESC><M-CR>a
endif
" }}}3
" }}}2
" ----------------------------------------------------------
" plugin settings {{{1
" calendar {{{2
for dir in ['~', $VIM, $VIM.'/..', $PRJDIR, $PRJDIR.'/..']
if isdirectory(dir.'/diary')
let g:calendar_diary = s:globfirst(dir.'/diary')
break
endif
endfor
let g:calendar_focus_today = 1
nmap <leader>da <leader>cal<CR>Go<CR><C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR><CR>
nmap <leader>DA <leader>caL<CR>Go<CR><C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR><CR>
vmap <leader>da "dy<leader>da<BS> - 摘要:<CR><ESC>"dP
vmap <leader>DA "dy<leader>DA<BS> - 摘要:<CR><ESC>"dP
" minibufexpl {{{2
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplorerMoreThanOne = 2
nmap <leader>on :on<CR><leader>mbe
vmap <leader>on <ESC><leader>on
" mru {{{2
let g:MRU_Check_File = 1
let g:MRU_Exclude_Files = '\c\v(\\|\/)%(Temp|Tmp)\1'
if has('win32')
let g:MRU_File = expand($VIM.'/_vim_mru_files')
else
let g:MRU_File = expand('~/.vim/_vim_mru_files')
endif
let g:MRU_Max_Entries = 80
menutrans Recent\ Files 最近使用的文件(&R)
menutrans Refresh\ list 刷新列表(&R)
" omnicppcomplete {{{2
let g:OmniCpp_GlobalScopeSearch = 1 " 0 or 1
let g:OmniCpp_NamespaceSearch = 1 " 0 , 1 or 2
let g:OmniCpp_DisplayMode = 1
let g:OmniCpp_ShowScopeInAbbr = 0
let g:OmniCpp_ShowPrototypeInAbbr = 1
let g:OmniCpp_ShowAccess = 1
let g:OmniCpp_MayCompleteDot = 1
let g:OmniCpp_MayCompleteArrow = 1
let g:OmniCpp_MayCompleteScope = 1
" supertab {{{2
let g:SuperTabRetainCompletionType = 2
let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabContextDefaultCompletionType = "<c-x><c-p>"
" taglist {{{2
if !executable("ctags")
let g:loaded_taglist = 'no'
else
let g:Tlist_Show_One_File = 1
let g:Tlist_Exit_OnlyWindow = 1
endif
" winmanager {{{2
let g:winManagerWindowLayout = 'FileExplorer|TagList'
map <leader>wm :<c-u>WMToggle<CR>
map <F2> <leader>wm
imap <F2> <ESC><leader>wm
" }}}2
if exists('s:cpo_save')
let &cpo = s:cpo_save
unlet s:cpo_save
endif
" }}}1
" vim: ft=vim ff=unix fdm=marker ts=4 nu
下面是我的插件包:
- 附件
-
- vimfiles.zip
- 插件包
- (737.79 KiB) 已下载 67 次
-
- 帖子: 386
- 注册时间: 2009-01-30 20:54
Re: [整理]vim常用命令速查卡片
Mark。。。