1 " vi:set ts=8 sts=2 sw=2 tw=0:
3 " cmdex.vim - Extra coomands
5 " Maintainer: Muraoka Taro <koron@tka.att.ne.jp>
6 " Last Change: 06-Feb-2006.
9 " (language: none/ja/zh...etc.)
20 " To make vim DO NOT LOAD this plugin, write next line in your .vimrc:
21 " :let plugin_cmdex_disable = 1
23 if exists('plugin_cmdex_disable')
28 " Like perl's "=~ tr/ABC/xyz/"
29 " function Transform(from_group, to_group, target)
30 command! -nargs=* -range Transform <line1>,<line2>call Transform(<f-args>)
31 function! Transform(from_str, to_str, ...)
32 if a:0 | let string = a:1 | else | let string = getline(".") | endif
33 let from_ptr = 0 | let to_ptr = 0
35 let from_char = matchstr(a:from_str, '^.', from_ptr)
39 let to_char = matchstr(a:to_str, '^.', to_ptr)
40 let from_ptr = from_ptr + strlen(from_char)
41 let to_ptr = to_ptr + strlen(to_char)
42 let string = substitute(string, from_char, to_char, 'g')
44 if a:0 | return string | else | call setline(".", string) | endif
48 " Stronger :nohlsearch
49 command! -nargs=0 Nohlsearch let @/ = ''
52 command! -nargs=0 Tutorial call <SID>StartTutorial()
53 function! s:StartTutorial()
56 let tutor = tutor . '.' . strpart($LANG, 0, 2)
60 let tutor = tutor . '.'. (&encoding ==# 'cp932' ? 'sjis' : 'euc')
62 execute "edit! $VIMRUNTIME/tutor/" . tutor
63 execute "file TUTORCOPY"
68 " Change current directory to current file's one.
69 command! -nargs=0 CdCurrent cd %:p:h
72 command! -nargs=1 -complete=file VDsplit vertical diffsplit <args>
75 command! -nargs=0 IminsertOff inoremap <buffer> <silent> <ESC> <ESC>:set iminsert=0<CR>
76 command! -nargs=0 IminsertOn iunmap <buffer> <ESC>
79 " Open a scratch (no file) buffer.
80 command! -nargs=0 Scratch new | setlocal bt=nofile noswf | let b:cmdex_scratch = 1
81 function! s:CheckScratchWritten()
82 if &buftype ==# 'nofile' && expand('%').'x' !=# 'x' && exists('b:cmdex_scratch') && b:cmdex_scratch == 1
83 setlocal buftype= swapfile
89 autocmd BufWritePost * call <SID>CheckScratchWritten()
92 " :MenuLang {language}
93 command! -nargs=1 MenuLang call <SID>ChangeMenu("<args>")
94 function! s:ChangeMenu(name)
95 source $VIMRUNTIME/delmenu.vim
97 source $VIMRUNTIME/menu.vim
101 command! -nargs=0 HTMLConvert call <SID>HTMLConvert()
102 function! s:HTMLConvert()
103 source $VIMRUNTIME/syntax/2html.vim
104 "silent! %s!\%(https\|http\|ftp\):[^<]*!<A HREF="&">&</A>!g
105 call histdel("search", -1)
109 " Input current buffer's directory on command line.
110 cnoremap <C-X> <C-R>=<SID>GetBufferDirectory()<CR>/
111 function! s:GetBufferDirectory()
112 let path = expand('%:p:h')
114 if match(path, cwd) != 0
116 elseif strlen(path) > strlen(cwd)
117 return strpart(path, strlen(cwd) + 1)
124 " Turn off diff mode for current buffer.
125 command! -nargs=0 Undiff set nodiff noscrollbind wrap