| 1 | " My .vimrc |
|---|
| 2 | " $Id$ |
|---|
| 3 | " SETTINGS WHICH ARE ABSOLUTELY NECESSARY "{{{1 |
|---|
| 4 | |
|---|
| 5 | " To use many extensions of Vim. |
|---|
| 6 | set nocompatible |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | " To deal with Japanese language. |
|---|
| 10 | if $ENV_WORKING ==# 'colinux' |
|---|
| 11 | set encoding=utf-8 |
|---|
| 12 | else |
|---|
| 13 | set encoding=japan |
|---|
| 14 | endif |
|---|
| 15 | if !exists('did_encoding_settings') && has('iconv') |
|---|
| 16 | let s:enc_euc = 'euc-jp' |
|---|
| 17 | let s:enc_jis = 'iso-2022-jp' |
|---|
| 18 | |
|---|
| 19 | " Does iconv support JIS X 0213 ? |
|---|
| 20 | if iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') |
|---|
| 21 | \ ==# "\xad\xc5\xad\xcb" |
|---|
| 22 | let s:enc_euc = 'euc-jisx0213,euc-jp' |
|---|
| 23 | let s:enc_jis = 'iso-2022-jp-3' |
|---|
| 24 | endif |
|---|
| 25 | |
|---|
| 26 | " Make fileencodings |
|---|
| 27 | let &fileencodings = 'ucs-bom' |
|---|
| 28 | if &encoding !=# 'utf-8' |
|---|
| 29 | let &fileencodings = &fileencodings . ',' . 'ucs-2le' |
|---|
| 30 | let &fileencodings = &fileencodings . ',' . 'ucs-2' |
|---|
| 31 | endif |
|---|
| 32 | let &fileencodings = &fileencodings . ',' . s:enc_jis |
|---|
| 33 | |
|---|
| 34 | if &encoding ==# 'utf-8' |
|---|
| 35 | let &fileencodings = &fileencodings . ',' . s:enc_euc |
|---|
| 36 | let &fileencodings = &fileencodings . ',' . 'cp932' |
|---|
| 37 | elseif &encoding =~# '^euc-\%(jp\|jisx0213\)$' |
|---|
| 38 | let &encoding = s:enc_euc |
|---|
| 39 | let &fileencodings = &fileencodings . ',' . 'utf-8' |
|---|
| 40 | let &fileencodings = &fileencodings . ',' . 'cp932' |
|---|
| 41 | else " cp932 |
|---|
| 42 | let &fileencodings = &fileencodings . ',' . 'utf-8' |
|---|
| 43 | let &fileencodings = &fileencodings . ',' . s:enc_euc |
|---|
| 44 | endif |
|---|
| 45 | let &fileencodings = &fileencodings . ',' . &encoding |
|---|
| 46 | |
|---|
| 47 | unlet s:enc_euc |
|---|
| 48 | unlet s:enc_jis |
|---|
| 49 | |
|---|
| 50 | let did_encoding_settings = 1 |
|---|
| 51 | endif |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | if $ENV_ACCESS ==# 'cygwin' |
|---|
| 55 | set termencoding=cp932 |
|---|
| 56 | elseif $ENV_ACCESS ==# 'linux' |
|---|
| 57 | set termencoding=euc-jp |
|---|
| 58 | else " 'colinux' |
|---|
| 59 | set termencoding=utf-8 |
|---|
| 60 | endif |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | " BASIC SETTINGS "{{{1 |
|---|
| 70 | |
|---|
| 71 | if 1 < &t_Co && has('syntax') |
|---|
| 72 | if &term ==# 'rxvt-cygwin-native' |
|---|
| 73 | set t_Co=256 |
|---|
| 74 | endif |
|---|
| 75 | syntax enable |
|---|
| 76 | colorscheme default |
|---|
| 77 | set background=dark |
|---|
| 78 | endif |
|---|
| 79 | |
|---|
| 80 | filetype plugin indent on |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | set autoindent |
|---|
| 84 | set backspace=indent,eol,start |
|---|
| 85 | set backup |
|---|
| 86 | set backupcopy& |
|---|
| 87 | set backupdir=.,~/tmp |
|---|
| 88 | set backupskip& |
|---|
| 89 | set backupskip+=svn-commit.tmp,svn-commit.[0-9]*.tmp |
|---|
| 90 | set cinoptions=:0,t0,(0,W1s |
|---|
| 91 | set directory=.,~/tmp |
|---|
| 92 | set noequalalways |
|---|
| 93 | set history=100 |
|---|
| 94 | set hlsearch |
|---|
| 95 | set grepprg=internal |
|---|
| 96 | set incsearch |
|---|
| 97 | set mouse= |
|---|
| 98 | set ruler |
|---|
| 99 | set showcmd |
|---|
| 100 | set showmode |
|---|
| 101 | set smartindent |
|---|
| 102 | set updatetime=60000 |
|---|
| 103 | set title |
|---|
| 104 | set titlestring=Vim:\ %f\ %h%r%m |
|---|
| 105 | |
|---|
| 106 | set viminfo=<50,'10,h,r/a,n~/.viminfo |
|---|
| 107 | |
|---|
| 108 | " To automatically detect the width and the height of the terminal, |
|---|
| 109 | " the followings must not be set. |
|---|
| 110 | " |
|---|
| 111 | " set columns=80 |
|---|
| 112 | " set lines=25 |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | let mapleader=',' |
|---|
| 116 | let maplocalleader='.' |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | " UTILITY FUNCTIONS & COMMANDS "{{{1 |
|---|
| 126 | " Misc. "{{{2 |
|---|
| 127 | |
|---|
| 128 | function! s:ToggleBell() |
|---|
| 129 | if &visualbell |
|---|
| 130 | set novisualbell t_vb& |
|---|
| 131 | echo 'bell on' |
|---|
| 132 | else |
|---|
| 133 | set visualbell t_vb= |
|---|
| 134 | echo 'bell off' |
|---|
| 135 | endif |
|---|
| 136 | endfunction |
|---|
| 137 | |
|---|
| 138 | function! s:ToggleOption(option_name) |
|---|
| 139 | execute 'setlocal' a:option_name.'!' |
|---|
| 140 | execute 'setlocal' a:option_name.'?' |
|---|
| 141 | endfunction |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | function! s:ExtendHighlight(target_group, original_group, new_settings) |
|---|
| 145 | redir => resp |
|---|
| 146 | silent execute 'highlight' a:original_group |
|---|
| 147 | redir END |
|---|
| 148 | if resp =~# 'xxx cleared' |
|---|
| 149 | let original_settings = '' |
|---|
| 150 | elseif resp =~# 'xxx links to' |
|---|
| 151 | return s:ExtendHighlight( |
|---|
| 152 | \ a:target_group, |
|---|
| 153 | \ substitute(resp, '\_.*xxx links to\s\+\(\S\+\)', '\1', ''), |
|---|
| 154 | \ a:new_settings |
|---|
| 155 | \ ) |
|---|
| 156 | else " xxx {key}={arg} ... |
|---|
| 157 | let t = substitute(resp,'\_.*xxx\(\(\_s\+[^= \t]\+=[^= \t]\+\)*\)','\1','') |
|---|
| 158 | let original_settings = substitute(t, '\_s\+', ' ', 'g') |
|---|
| 159 | endif |
|---|
| 160 | |
|---|
| 161 | silent execute 'highlight' a:target_group 'NONE' |
|---|
| 162 | \ '|' 'highlight' a:target_group original_settings |
|---|
| 163 | \ '|' 'highlight' a:target_group a:new_settings |
|---|
| 164 | endfunction |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | function! s:RenameBuffer(name) |
|---|
| 168 | let name = a:name |
|---|
| 169 | let i = 0 |
|---|
| 170 | while 1 |
|---|
| 171 | if !bufexists(name) |
|---|
| 172 | break |
|---|
| 173 | endif |
|---|
| 174 | let i = i + 1 |
|---|
| 175 | let name = a:name . ' (' . i . ')' |
|---|
| 176 | endwhile |
|---|
| 177 | file `=name` |
|---|
| 178 | endfunction |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | function! s:CreateTemporaryBuffer(name, how_to_open) |
|---|
| 182 | execute a:how_to_open |
|---|
| 183 | setlocal bufhidden=wipe buflisted buftype=nofile noswapfile |
|---|
| 184 | call s:RenameBuffer(a:name) |
|---|
| 185 | endfunction |
|---|
| 186 | |
|---|
| 187 | function! s:CreateCommandOutputBuffer(command, ...) " spliting_modifier? |
|---|
| 188 | let spliting_modifier = (1 <= a:0 ? a:1 : '') |
|---|
| 189 | let previous_window_nr = winnr() |
|---|
| 190 | let previous_windows_placement = winrestcmd() |
|---|
| 191 | |
|---|
| 192 | call s:CreateTemporaryBuffer('CMD: '.a:command, spliting_modifier.' new') |
|---|
| 193 | silent execute 'read !' a:command |
|---|
| 194 | |
|---|
| 195 | if line('$') == 1 && getline(1) == '' |
|---|
| 196 | close |
|---|
| 197 | execute previous_windows_placement |
|---|
| 198 | execute previous_window_nr 'wincmd w' |
|---|
| 199 | |
|---|
| 200 | redraw " to ensure show the following message. |
|---|
| 201 | echomsg 'No output from the command:' a:command |
|---|
| 202 | return 0 |
|---|
| 203 | else |
|---|
| 204 | 1 |
|---|
| 205 | delete |
|---|
| 206 | filetype detect |
|---|
| 207 | return 1 |
|---|
| 208 | endif |
|---|
| 209 | endfunction |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | function! s:Count(...) |
|---|
| 213 | if v:count == v:count1 " count is specified. |
|---|
| 214 | return v:count |
|---|
| 215 | else " count is not specified. (the default '' is useful for special value) |
|---|
| 216 | return a:0 == 0 ? '' : a:1 |
|---|
| 217 | endif |
|---|
| 218 | endfunction |
|---|
| 219 | |
|---|
| 220 | command! -nargs=* -complete=expression -range -count=0 Execute |
|---|
| 221 | \ call s:Execute(<f-args>) |
|---|
| 222 | function! s:Execute(...) |
|---|
| 223 | let args = [] |
|---|
| 224 | for a in a:000 |
|---|
| 225 | if a ==# '[count]' |
|---|
| 226 | let a = s:Count() |
|---|
| 227 | endif |
|---|
| 228 | call add(args, a) |
|---|
| 229 | endfor |
|---|
| 230 | execute join(args) |
|---|
| 231 | endfunction |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | " Help-related stuffs "{{{2 |
|---|
| 237 | |
|---|
| 238 | function! s:HelpBufWinNR() |
|---|
| 239 | let wn = 1 |
|---|
| 240 | while wn <= winnr('$') |
|---|
| 241 | let bn = winbufnr(wn) |
|---|
| 242 | if getbufvar(bn, '&buftype') == 'help' |
|---|
| 243 | return [bn, wn] |
|---|
| 244 | endif |
|---|
| 245 | let wn = wn + 1 |
|---|
| 246 | endwhile |
|---|
| 247 | return [-1, 0] |
|---|
| 248 | endfunction |
|---|
| 249 | |
|---|
| 250 | function! s:HelpWindowClose() |
|---|
| 251 | let [help_bufnr, help_winnr] = s:HelpBufWinNR() |
|---|
| 252 | if help_bufnr == -1 |
|---|
| 253 | return |
|---|
| 254 | endif |
|---|
| 255 | |
|---|
| 256 | let current_winnr = winnr() |
|---|
| 257 | execute help_winnr 'wincmd w' |
|---|
| 258 | execute 'wincmd c' |
|---|
| 259 | if current_winnr < help_winnr |
|---|
| 260 | execute current_winnr 'wincmd w' |
|---|
| 261 | elseif help_winnr < current_winnr |
|---|
| 262 | execute (current_winnr-1) 'wincmd w' |
|---|
| 263 | else |
|---|
| 264 | " NOP |
|---|
| 265 | endif |
|---|
| 266 | endfunction |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | " High-level key sequences "{{{2 |
|---|
| 272 | |
|---|
| 273 | function! s:KeysToComplete() |
|---|
| 274 | if strlen(&omnifunc) |
|---|
| 275 | return "\<C-x>\<C-o>" |
|---|
| 276 | elseif &filetype ==# 'vim' |
|---|
| 277 | return "\<C-x>\<C-v>" |
|---|
| 278 | else |
|---|
| 279 | return "\<C-n>" |
|---|
| 280 | endif |
|---|
| 281 | endfunction |
|---|
| 282 | |
|---|
| 283 | function! s:KeysToStopInsertModeCompletion() |
|---|
| 284 | if pumvisible() |
|---|
| 285 | return "\<C-y>" |
|---|
| 286 | else |
|---|
| 287 | return "\<Space>\<BS>" |
|---|
| 288 | endif |
|---|
| 289 | endfunction |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | " :edit with specified 'fileencoding'. "{{{2 |
|---|
| 295 | |
|---|
| 296 | com! -nargs=? -complete=file -bang -bar Cp932 edit<bang> ++enc=cp932 <args> |
|---|
| 297 | com! -nargs=? -complete=file -bang -bar Eucjp edit<bang> ++enc=euc-jp <args> |
|---|
| 298 | com! -nargs=? -complete=file -bang -bar Iso2022jp Jis<bang> <args> |
|---|
| 299 | com! -nargs=? -complete=file -bang -bar Jis edit<bang> ++enc=iso-2022-jp <args> |
|---|
| 300 | com! -nargs=? -complete=file -bang -bar Sjis Cp932<bang> <args> |
|---|
| 301 | com! -nargs=? -complete=file -bang -bar Utf8 edit<bang> ++enc=utf-8 <args> |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | " Jump sections "{{{2 |
|---|
| 307 | |
|---|
| 308 | " for normal mode. a:pattern is '/regexp' or '?regexp'. |
|---|
| 309 | function! s:JumpSectionN(pattern) |
|---|
| 310 | let pattern = strpart(a:pattern, '1') |
|---|
| 311 | if strpart(a:pattern, 0, 1) == '/' |
|---|
| 312 | let flags = 'W' |
|---|
| 313 | else |
|---|
| 314 | let flags = 'Wb' |
|---|
| 315 | endif |
|---|
| 316 | |
|---|
| 317 | mark ' |
|---|
| 318 | let i = 0 |
|---|
| 319 | while i < v:count1 |
|---|
| 320 | if search(pattern, flags) == 0 |
|---|
| 321 | if stridx(flags, 'b') != -1 |
|---|
| 322 | normal! gg |
|---|
| 323 | else |
|---|
| 324 | normal! G |
|---|
| 325 | endif |
|---|
| 326 | break |
|---|
| 327 | endif |
|---|
| 328 | let i = i + 1 |
|---|
| 329 | endwhile |
|---|
| 330 | endfunction |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | " for visual mode. a:motion is '[[', '[]', ']]' or ']['. |
|---|
| 334 | function! s:JumpSectionV(motion) |
|---|
| 335 | execute 'normal!' "gv\<Esc>" |
|---|
| 336 | execute 'normal' v:count1 . a:motion |
|---|
| 337 | let line = line('.') |
|---|
| 338 | let col = col('.') |
|---|
| 339 | |
|---|
| 340 | normal! gv |
|---|
| 341 | call cursor(line, col) |
|---|
| 342 | endfunction |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | " for operator-pending mode. a:motion is '[[', '[]', ']]' or ']['. |
|---|
| 346 | function! s:JumpSectionO(motion) |
|---|
| 347 | execute 'normal' v:count1 . a:motion |
|---|
| 348 | endfunction |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | |
|---|
| 357 | " KEY MAPPINGS "{{{1 |
|---|
| 358 | " RULES: |
|---|
| 359 | " - Separate {lhs} and {rhs} by two spaces. |
|---|
| 360 | " - Write like <C-x>, not <C-X>. |
|---|
| 361 | |
|---|
| 362 | " Misc. "{{{2 |
|---|
| 363 | |
|---|
| 364 | nnoremap <C-h> :h<Space> |
|---|
| 365 | nnoremap <C-o> :e<Space> |
|---|
| 366 | nnoremap <C-w>. :e .<Return> |
|---|
| 367 | nnoremap <silent> <Leader>cD |
|---|
| 368 | \ :<C-u>call <SID>CreateCommandOutputBuffer('svn diff', 'botright')<CR> |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | " Various hotkeys prefixed by <Space>. |
|---|
| 372 | " To show <Space> in the bottom line. |
|---|
| 373 | map <Space> [Space] |
|---|
| 374 | |
|---|
| 375 | noremap [Space] <Nop> |
|---|
| 376 | nnoremap [Space]/ :nohlsearch<Return> |
|---|
| 377 | nnoremap [Space]? :call <SID>HelpWindowClose()<Return> |
|---|
| 378 | nmap [Space]b <Plug>Buffuzzy |
|---|
| 379 | nnoremap [Space]e :setlocal encoding? termencoding? fenc? fencs?<Return> |
|---|
| 380 | nnoremap [Space]i :setlocal filetype? fileencoding? fileformat?<Return> |
|---|
| 381 | nnoremap [Space]ob :call <SID>ToggleBell()<Return> |
|---|
| 382 | nnoremap [Space]ow :call <SID>ToggleOption('wrap')<Return> |
|---|
| 383 | nnoremap [Space]s <Nop> |
|---|
| 384 | nnoremap [Space]s. :source $HOME/.vimrc<Return> |
|---|
| 385 | nnoremap [Space]ss :source %<Return> |
|---|
| 386 | vnoremap [Space]s :sort<Return> |
|---|
| 387 | nmap [Space]w [Space]ow |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | " Jump list |
|---|
| 391 | nnoremap <C-j> <C-i> |
|---|
| 392 | nnoremap <C-k> <C-o> |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | " Switch to the previously edited file (like Vz) |
|---|
| 396 | nnoremap <Esc>2 :e #<Return> |
|---|
| 397 | nmap <F2> <Esc>2 |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | " Visiting windows with one key. |
|---|
| 401 | nnoremap <C-i> <C-w>w |
|---|
| 402 | nnoremap <Esc>i <C-w>W |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | " Too lazy to press Shift key. |
|---|
| 406 | noremap ; : |
|---|
| 407 | noremap : ; |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | " Disable some dangerous key. |
|---|
| 411 | nnoremap ZZ <Nop> |
|---|
| 412 | nnoremap ZQ <Nop> |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | " Ex-mode will be never used and recordings are rarely used. |
|---|
| 416 | nnoremap Q q |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | " Use a backslash (\) to repeat last change. |
|---|
| 420 | " Since a dot (.) is used as <LocalLeader>. |
|---|
| 421 | nnoremap \ . |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | " Search slashes easily (too lazy to prefix backslashes to slashes) |
|---|
| 425 | cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/' |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | " Complete or indent. |
|---|
| 429 | inoremap <expr> <C-i> (<SID>ShouldIndentRatherThanCompleteP() |
|---|
| 430 | \ ? '<C-i>' |
|---|
| 431 | \ : <SID>KeysToComplete()) |
|---|
| 432 | |
|---|
| 433 | function! s:ShouldIndentRatherThanCompleteP() |
|---|
| 434 | let m = match(getline('.'), '\S') |
|---|
| 435 | return m == -1 || col('.')-1 <= m |
|---|
| 436 | endfunction |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | " Swap ` and ' -- I prefer ` to ' and ` is not easy to type. |
|---|
| 440 | noremap ' ` |
|---|
| 441 | noremap ` ' |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | " For plugin: scratch "{{{2 |
|---|
| 447 | " I already use <C-m> for tag jumping. |
|---|
| 448 | " But I don't use it in the scratch buffer, so it should be overridden. |
|---|
| 449 | |
|---|
| 450 | augroup Scratch |
|---|
| 451 | au! |
|---|
| 452 | au User Initialize nmap <buffer> <C-m> <Plug>Scratch_ExecuteLine |
|---|
| 453 | au User Initialize vmap <buffer> <C-m> <Plug>Scratch_ExecuteSelection |
|---|
| 454 | augroup END |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | " Tag-related hotkeys "{{{2 |
|---|
| 460 | " Fallback "{{{3 |
|---|
| 461 | |
|---|
| 462 | " ``T'' is also disabled for consistency. |
|---|
| 463 | noremap t <Nop> |
|---|
| 464 | noremap T <Nop> |
|---|
| 465 | |
|---|
| 466 | " Alternatives for the original actions. |
|---|
| 467 | noremap [Space]t t |
|---|
| 468 | noremap [Space]T T |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | " Basics "{{{3 |
|---|
| 472 | nmap t<Space> tt |
|---|
| 473 | vmap t<Space> tt |
|---|
| 474 | nnoremap tt <C-]> |
|---|
| 475 | vnoremap tt <C-]> |
|---|
| 476 | nnoremap tj :tag<Return> |
|---|
| 477 | nnoremap tk :pop<Return> |
|---|
| 478 | nnoremap tl :tags<Return> |
|---|
| 479 | nnoremap tn :tnext<Return> |
|---|
| 480 | nnoremap tp :tprevious<Return> |
|---|
| 481 | nnoremap tP :tfirst<Return> |
|---|
| 482 | nnoremap tN :tlast<Return> |
|---|
| 483 | |
|---|
| 484 | " additionals, like Web browsers |
|---|
| 485 | nmap <C-m> tt |
|---|
| 486 | vmap <C-m> tt |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | " With preview window "{{{3 |
|---|
| 490 | nmap t'<Space> t't |
|---|
| 491 | vmap t'<Space> t't |
|---|
| 492 | nnoremap t't <C-w>} |
|---|
| 493 | vnoremap t't <C-w>} |
|---|
| 494 | nnoremap t'n :ptnext<Return> |
|---|
| 495 | nnoremap t'p :ptpevious<Return> |
|---|
| 496 | nnoremap t'P :ptfirst<Return> |
|---|
| 497 | nnoremap t'N :ptlast<Return> |
|---|
| 498 | |
|---|
| 499 | " although :pclose is not related to tag. |
|---|
| 500 | nnoremap t'c :pclose<Return> |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | " With :split "{{{3 |
|---|
| 504 | nnoremap tst <C-w>] |
|---|
| 505 | vnoremap tst <C-w>] |
|---|
| 506 | nmap ts<Space> tst |
|---|
| 507 | vmap ts<Space> tst |
|---|
| 508 | nnoremap tsn :split \| tnext<Return> |
|---|
| 509 | nnoremap tsp :split \| tpevious<Return> |
|---|
| 510 | nnoremap tsP :split \| tfirst<Return> |
|---|
| 511 | nnoremap tsN :split \| tlast<Return> |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | " With :vertical split "{{{3 |
|---|
| 515 | " |:vsplit|-then-|<C-]>| is simple |
|---|
| 516 | " but its modification to tag stacks is not same as |<C-w>]|. |
|---|
| 517 | nnoremap tvt <C-]>:vsplit<Return><C-w>p<C-t><C-w>p |
|---|
| 518 | vnoremap tvt <C-]>:vsplit<Return><C-w>p<C-t><C-w>p |
|---|
| 519 | nmap tv<Space> tvt |
|---|
| 520 | vmap tv<Space> tvt |
|---|
| 521 | nnoremap tvn :vsplit \| tnext<Return> |
|---|
| 522 | nnoremap tvp :vsplit \| tpevious<Return> |
|---|
| 523 | nnoremap tvP :vsplit \| tfirst<Return> |
|---|
| 524 | nnoremap tvN :vsplit \| tlast<Return> |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | " Quickfix hotkeys "{{{2 |
|---|
| 530 | " Fallback |
|---|
| 531 | nnoremap q <Nop> |
|---|
| 532 | |
|---|
| 533 | " For quickfix list |
|---|
| 534 | nnoremap qj :Execute cnext [count]<Return> |
|---|
| 535 | nnoremap qk :Execute cprevious [count]<Return> |
|---|
| 536 | nnoremap qr :Execute crewind [count]<Return> |
|---|
| 537 | nnoremap qK :Execute cfirst [count]<Return> |
|---|
| 538 | nnoremap qJ :Execute clast [count]<Return> |
|---|
| 539 | nnoremap qfj :Execute cnfile [count]<Return> |
|---|
| 540 | nnoremap qfk :Execute cpfile [count]<Return> |
|---|
| 541 | nnoremap ql :clist<Return> |
|---|
| 542 | nnoremap qq :Execute cc [count]<Return> |
|---|
| 543 | nnoremap qo :Execute copen [count]<Return> |
|---|
| 544 | nnoremap qc :cclose<Return> |
|---|
| 545 | nnoremap qp :Execute colder [count]<Return> |
|---|
| 546 | nnoremap qn :Execute cnewer [count]<Return> |
|---|
| 547 | nnoremap qm :make<Return> |
|---|
| 548 | nnoremap qM :make<Space> |
|---|
| 549 | nnoremap q<Space> :make<Space> |
|---|
| 550 | nnoremap qg :grep<Space> |
|---|
| 551 | |
|---|
| 552 | " For location list (mnemonic: Quickfix list for the current Window) |
|---|
| 553 | nnoremap qwj :Execute lnext [count]<Return> |
|---|
| 554 | nnoremap qwk :Execute lprevious [count]<Return> |
|---|
| 555 | nnoremap qwr :Execute lrewind [count]<Return> |
|---|
| 556 | nnoremap qwK :Execute lfirst [count]<Return> |
|---|
| 557 | nnoremap qwJ :Execute llast [count]<Return> |
|---|
| 558 | nnoremap qwfj :Execute lnfile [count]<Return> |
|---|
| 559 | nnoremap qwfk :Execute lpfile [count]<Return> |
|---|
| 560 | nnoremap qwl :llist<Return> |
|---|
| 561 | nnoremap qwq :Execute ll [count]<Return> |
|---|
| 562 | nnoremap qwo :Execute lopen [count]<Return> |
|---|
| 563 | nnoremap qwc :lclose<Return> |
|---|
| 564 | nnoremap qwp :Execute lolder [count]<Return> |
|---|
| 565 | nnoremap qwn :Execute lnewer [count]<Return> |
|---|
| 566 | nnoremap qwm :lmake<Return> |
|---|
| 567 | nnoremap qwM :lmake<Space> |
|---|
| 568 | nnoremap qw<Space> :lmake<Space> |
|---|
| 569 | nnoremap qwg :lgrep<Space> |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | " Tab-pages hotkeys "{{{2 |
|---|
| 575 | " FIXME: sometimes, hit-enter prompt appears. but no idea for the reason. |
|---|
| 576 | " Misc. "{{{3 |
|---|
| 577 | nnoremap <C-t> <Nop> |
|---|
| 578 | |
|---|
| 579 | nnoremap <C-t>n :<C-u>tabnew<Return> |
|---|
| 580 | nnoremap <C-t>c :<C-u>tabclose<Return> |
|---|
| 581 | nnoremap <C-t>o :<C-u>tabonly<Return> |
|---|
| 582 | nnoremap <C-t>i :<C-u>tabs<Return> |
|---|
| 583 | |
|---|
| 584 | nmap <C-t><C-n> <C-t>n |
|---|
| 585 | nmap <C-t><C-c> <C-t>c |
|---|
| 586 | nmap <C-t><C-o> <C-t>o |
|---|
| 587 | nmap <C-t><C-i> <C-t>i |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | " Moving around tabs. "{{{3 |
|---|
| 591 | nnoremap <C-t>j :<C-u>execute 'tabnext' |
|---|
| 592 | \ 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$')<Return> |
|---|
| 593 | nnoremap <C-t>k :Execute tabprevious [count]<Return> |
|---|
| 594 | nnoremap <C-t>K :<C-u>tabfirst<Return> |
|---|
| 595 | nnoremap <C-t>J :<C-u>tablast<Return> |
|---|
| 596 | nmap <C-t>t <C-t>j |
|---|
| 597 | nmap <C-t>T <C-t>k |
|---|
| 598 | |
|---|
| 599 | nmap <C-t><C-j> <C-t>j |
|---|
| 600 | nmap <C-t><C-k> <C-t>k |
|---|
| 601 | nmap <C-t><C-t> <C-t>t |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | " Moving tabs themselves. "{{{3 |
|---|
| 605 | nnoremap <C-t>l :<C-u>execute 'tabmove' |
|---|
| 606 | \ min([tabpagenr() + v:count1 - 1, tabpagenr('$')])<Return> |
|---|
| 607 | nnoremap <C-t>h :<C-u>execute 'tabmove' |
|---|
| 608 | \ max([tabpagenr() - v:count1 - 1, 0])<Return> |
|---|
| 609 | nnoremap <C-t>L :<C-u>tabmove<Return> |
|---|
| 610 | nnoremap <C-t>H :<C-u>tabmove 0<Return> |
|---|
| 611 | |
|---|
| 612 | nmap <C-t><C-l> <C-t>l |
|---|
| 613 | nmap <C-t><C-h> <C-t>h |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | " For command-line editting "{{{2 |
|---|
| 619 | |
|---|
| 620 | cnoremap <C-u> <C-e><C-u> |
|---|
| 621 | |
|---|
| 622 | cnoremap <Esc>h <Left> |
|---|
| 623 | cnoremap <Esc>j <Down> |
|---|
| 624 | cnoremap <Esc>k <Up> |
|---|
| 625 | cnoremap <Esc>l <Right> |
|---|
| 626 | cnoremap <Esc>H <Home> |
|---|
| 627 | cnoremap <Esc>L <End> |
|---|
| 628 | cnoremap <Esc>w <S-Right> |
|---|
| 629 | cnoremap <Esc>b <S-Left> |
|---|
| 630 | cnoremap <Esc>x <Del> |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | " Input the current date/time (Full, Date, Time). "{{{2 |
|---|
| 636 | |
|---|
| 637 | inoremap <Leader>dF <C-r>=strftime('%Y-%m-%dT%H:%M:%S+09:00')<Return> |
|---|
| 638 | inoremap <Leader>df <C-r>=strftime('%Y-%m-%dT%H:%M:%S')<Return> |
|---|
| 639 | inoremap <Leader>dd <C-r>=strftime('%Y-%m-%d')<Return> |
|---|
| 640 | inoremap <Leader>dT <C-r>=strftime('%H:%M:%S')<Return> |
|---|
| 641 | inoremap <Leader>dt <C-r>=strftime('%H:%M')<Return> |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | " Enable ]] and other motions in visual and operator-pending mode. "{{{2 |
|---|
| 647 | |
|---|
| 648 | vnoremap <silent> ]] :<C-u>call <SID>JumpSectionV(']]')<Return> |
|---|
| 649 | vnoremap <silent> ][ :<C-u>call <SID>JumpSectionV('][')<Return> |
|---|
| 650 | vnoremap <silent> [[ :<C-u>call <SID>JumpSectionV('[[')<Return> |
|---|
| 651 | vnoremap <silent> [] :<C-u>call <SID>JumpSectionV('[]')<Return> |
|---|
| 652 | onoremap <silent> ]] :<C-u>call <SID>JumpSectionO(']]')<Return> |
|---|
| 653 | onoremap <silent> ][ :<C-u>call <SID>JumpSectionO('][')<Return> |
|---|
| 654 | onoremap <silent> [[ :<C-u>call <SID>JumpSectionO('[[')<Return> |
|---|
| 655 | onoremap <silent> [] :<C-u>call <SID>JumpSectionO('[]')<Return> |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | " FILETYPE "{{{1 |
|---|
| 665 | " Misc. "{{{2 |
|---|
| 666 | |
|---|
| 667 | augroup MyAutoCmd |
|---|
| 668 | autocmd! |
|---|
| 669 | |
|---|
| 670 | autocmd FileType dosini |
|---|
| 671 | \ call <SID>FileType_dosini() |
|---|
| 672 | |
|---|
| 673 | autocmd FileType python |
|---|
| 674 | \ call <SID>SetShortIndent() |
|---|
| 675 | \ | let python_highlight_numbers=1 |
|---|
| 676 | \ | let python_highlight_builtins=1 |
|---|
| 677 | \ | let python_highlight_space_errors=1 |
|---|
| 678 | |
|---|
| 679 | autocmd FileType vim |
|---|
| 680 | \ call <SID>FileType_vim() |
|---|
| 681 | |
|---|
| 682 | autocmd FileType html,xhtml,xml,xslt |
|---|
| 683 | \ call <SID>FileType_xml() |
|---|
| 684 | |
|---|
| 685 | " Misc. |
|---|
| 686 | autocmd FileType lua,sh,tex |
|---|
| 687 | \ call <SID>SetShortIndent() |
|---|
| 688 | |
|---|
| 689 | autocmd FileType * |
|---|
| 690 | \ call <SID>FileType_any() |
|---|
| 691 | |
|---|
| 692 | autocmd ColorScheme * |
|---|
| 693 | \ call <SID>ExtendHighlight('Pmenu', 'Normal', 'cterm=underline') |
|---|
| 694 | \ | call <SID>ExtendHighlight('PmenuSel', 'Search', 'cterm=underline') |
|---|
| 695 | \ | call <SID>ExtendHighlight('PmenuSbar', 'Normal', 'cterm=reverse') |
|---|
| 696 | \ | call <SID>ExtendHighlight('PmenuThumb', 'Search', '') |
|---|
| 697 | doautocmd ColorScheme because-colorscheme-has-been-set-above. |
|---|
| 698 | |
|---|
| 699 | " I consider that these buffers have another filetype=netrw. |
|---|
| 700 | autocmd BufReadPost {dav,file,ftp,http,rcp,rsync,scp,sftp}://* |
|---|
| 701 | \ setlocal bufhidden=hide |
|---|
| 702 | augroup END |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | function! s:SetShortIndent() |
|---|
| 706 | setlocal expandtab softtabstop=2 shiftwidth=2 |
|---|
| 707 | endfunction |
|---|
| 708 | |
|---|
| 709 | |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | " All "{{{2 |
|---|
| 713 | |
|---|
| 714 | function! s:FileType_any() |
|---|
| 715 | " To use my global mappings for section jumping, |
|---|
| 716 | " remove buffer local mappings for them. |
|---|
| 717 | silent! vunmap <buffer> ]] |
|---|
| 718 | silent! vunmap <buffer> ][ |
|---|
| 719 | silent! vunmap <buffer> [] |
|---|
| 720 | silent! vunmap <buffer> [[ |
|---|
| 721 | silent! ounmap <buffer> ]] |
|---|
| 722 | silent! ounmap <buffer> ][ |
|---|
| 723 | silent! ounmap <buffer> [] |
|---|
| 724 | silent! ounmap <buffer> [[ |
|---|
| 725 | endfunction |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | " Dosini (.ini) "{{{2 |
|---|
| 731 | |
|---|
| 732 | function! s:FileType_dosini() |
|---|
| 733 | nnoremap <buffer> <silent> ]] :<C-u>call <SID>JumpSectionN('/^\[')<Return> |
|---|
| 734 | nnoremap <buffer> <silent> ][ :<C-u>call <SID>JumpSectionN('/\n\[\@=')<CR> |
|---|
| 735 | nnoremap <buffer> <silent> [[ :<C-u>call <SID>JumpSectionN('?^\[')<Return> |
|---|
| 736 | nnoremap <buffer> <silent> [] :<C-u>call <SID>JumpSectionN('?\n\[\@=')<CR> |
|---|
| 737 | endfunction |
|---|
| 738 | |
|---|
| 739 | |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | " sh "{{{2 |
|---|
| 743 | |
|---|
| 744 | let g:is_bash = 1 |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | " Vim "{{{2 |
|---|
| 750 | |
|---|
| 751 | function! s:FileType_vim() |
|---|
| 752 | call <SID>SetShortIndent() |
|---|
| 753 | let vim_indent_cont = &shiftwidth |
|---|
| 754 | endfunction |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | " XML/SGML and other applications "{{{2 |
|---|
| 760 | |
|---|
| 761 | function! s:FileType_xml() |
|---|
| 762 | call <SID>SetShortIndent() |
|---|
| 763 | |
|---|
| 764 | " To deal with namespace prefixes and tag-name-including-hyphens. |
|---|
| 765 | setlocal iskeyword+=45 " hyphen (-) |
|---|
| 766 | setlocal iskeyword+=58 " colon (:) |
|---|
| 767 | |
|---|
| 768 | " Support to input some parts of tags. |
|---|
| 769 | inoremap <buffer> <LT>? </ |
|---|
| 770 | imap <buffer> ?<LT> <LT>? |
|---|
| 771 | inoremap <buffer> ?> /> |
|---|
| 772 | imap <buffer> >? ?> |
|---|
| 773 | |
|---|
| 774 | " Support to input some blocks. |
|---|
| 775 | inoremap <buffer> <LT>!C <LT>![CDATA[]]><Left><Left><Left> |
|---|
| 776 | inoremap <buffer> <LT># <LT>!----><Left><Left><Left><C-r>= |
|---|
| 777 | \ <SID>FileType_xml_comment_dispatch() |
|---|
| 778 | \ <Return> |
|---|
| 779 | |
|---|
| 780 | " Complete proper end-tags. |
|---|
| 781 | " In the following description, {|} means the cursor position. |
|---|
| 782 | |
|---|
| 783 | " Insert the end tag after the cursor. |
|---|
| 784 | " Before: <code{|} |
|---|
| 785 | " After: <code>{|}</code> |
|---|
| 786 | inoremap <buffer> <LT><LT> ><LT>/<C-x><C-o><C-r>= |
|---|
| 787 | \ <SID>KeysToStopInsertModeCompletion() |
|---|
| 788 | \ <Return><C-o>F<LT> |
|---|
| 789 | |
|---|
| 790 | " Wrap the cursor with the tag. |
|---|
| 791 | " Before: <code{|} |
|---|
| 792 | " After: <code> |
|---|
| 793 | " {|} |
|---|
| 794 | " </code> |
|---|
| 795 | inoremap <buffer> >> ><Return>X<Return><LT>/<C-x><C-o><C-r>= |
|---|
| 796 | \ <SID>KeysToStopInsertModeCompletion() |
|---|
| 797 | \ <Return><C-o><Up><BS> |
|---|
| 798 | endfunction |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | function! s:FileType_xml_comment_dispatch() |
|---|
| 802 | let c = nr2char(getchar()) |
|---|
| 803 | return get(s:FileType_xml_comment_data, c, c) |
|---|
| 804 | endfunction |
|---|
| 805 | let s:FileType_xml_comment_data = { |
|---|
| 806 | \ "\<Space>": "\<Space>\<Space>\<Left>", |
|---|
| 807 | \ "\<Return>": "\<Return>X\<Return>\<Up>\<End>\<BS>", |
|---|
| 808 | \ '_': '', |
|---|
| 809 | \ '-': '', |
|---|
| 810 | \ '{': '{{{', |
|---|
| 811 | \ '}': '}}}', |
|---|
| 812 | \ } |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | " MISC. "{{{1 |
|---|
| 822 | |
|---|
| 823 | " Plugin: cygclip |
|---|
| 824 | |
|---|
| 825 | " Because plugins will be loaded after ~/.vimrc. |
|---|
| 826 | autocmd MyAutoCmd VimEnter * |
|---|
| 827 | \ if exists('g:loaded_cygclip') |
|---|
| 828 | \ | call Cygclip_DefaultKeymappings() |
|---|
| 829 | \ | endif |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | " Plugin: surround |
|---|
| 835 | |
|---|
| 836 | " The default mapping ys for <Plug>Ysurround is not consistent with |
|---|
| 837 | " the default mappings of vi -- y is for yank. |
|---|
| 838 | nmap s <Plug>Ysurround |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | |
|---|
| 842 | |
|---|
| 843 | " Plugin: vcscommand |
|---|
| 844 | |
|---|
| 845 | let g:VCSCommandDeleteOnHide = 1 |
|---|
| 846 | |
|---|
| 847 | nmap <Leader>cR <Plug>VCSDelete |
|---|
| 848 | |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | " Plugin: xml_autons |
|---|
| 853 | |
|---|
| 854 | let g:AutoXMLns_Dict = {} |
|---|
| 855 | let g:AutoXMLns_Dict['http://www.w3.org/2000/svg'] = 'svg11' |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | set secure |
|---|
| 861 | |
|---|
| 862 | " __END__ |
|---|
| 863 | " vim: foldmethod=marker |
|---|