vim72-20100325-kaoriya-w64j.zip
[MacVim/KaoriYa.git] / runtime / plugin / cmdex.vim
blob6e742608d5e422c33da782824a6a1eaa6258fbc0
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.
7 " Commands:
8 "               :MenuLang {language}
9 "                   (language: none/ja/zh...etc.)
10 "               :Scratch
11 "               :IminsertOff
12 "               :IminsertOn
13 "               :VDsplit {filename}
14 "               :Tutorial
15 "               :Nohlsearch
16 "               :Transform
17 "               c_CTRL-X
18 "               :Undiff
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')
24   finish
25 endif
27 " :Transform
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
34   while 1
35     let from_char = matchstr(a:from_str, '^.', from_ptr)
36     if from_char == ''
37       break
38     endif
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')
43   endwhile
44   if a:0 | return string | else | call setline(".", string) | endif
45 endfunction
47 " :Nohlsearch
48 "   Stronger :nohlsearch
49 command! -nargs=0 Nohlsearch let @/ = ''
50 " :Tutorial
51 "   Start vim training.
52 command! -nargs=0 Tutorial call <SID>StartTutorial()
53 function! s:StartTutorial()
54   let tutor = 'tutor'
55   if $LANG !=# ''
56     let tutor = tutor . '.' . strpart($LANG, 0, 2)
57   endif
58   " Japan special
59   if $LANG =~ '^ja'
60     let tutor = tutor . '.'. (&encoding ==# 'cp932' ? 'sjis' : 'euc')
61   endif
62   execute "edit! $VIMRUNTIME/tutor/" . tutor
63   execute "file TUTORCOPY"
64   execute "write!"
65 endfunction
67 " :CdCurrent
68 "   Change current directory to current file's one.
69 command! -nargs=0 CdCurrent cd %:p:h
71 " :VDsplit
72 command! -nargs=1 -complete=file VDsplit vertical diffsplit <args>
74 " :IminsertOff/On
75 command! -nargs=0 IminsertOff inoremap <buffer> <silent> <ESC> <ESC>:set iminsert=0<CR>
76 command! -nargs=0 IminsertOn iunmap <buffer> <ESC>
78 " :Scratch
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
84     unlet b:cmdex_scratch
85   endif
86 endfunction
87 augroup CmdexScratch
88 autocmd!
89 autocmd BufWritePost * call <SID>CheckScratchWritten()
90 augroup END
92 " :MenuLang {language}
93 command! -nargs=1 MenuLang call <SID>ChangeMenu("<args>")
94 function! s:ChangeMenu(name)
95   source $VIMRUNTIME/delmenu.vim
96   let &langmenu=a:name
97   source $VIMRUNTIME/menu.vim
98 endfunction
100 " :HTMLConvert
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)
106 endfunction
108 " c_CTRL-X
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')
113   let cwd = getcwd()
114   if match(path, cwd) != 0
115     return path
116   elseif strlen(path) > strlen(cwd)
117     return strpart(path, strlen(cwd) + 1)
118   else
119     return '.'
120   endif
121 endfunction
123 " :Undiff
124 "   Turn off diff mode for current buffer.
125 command! -nargs=0 Undiff set nodiff noscrollbind wrap