| 1 | " My .vimrc |
|---|
| 2 | " $Id$ |
|---|
| 3 | " Notes "{{{1 |
|---|
| 4 | " |
|---|
| 5 | " * This file consists of "sections". |
|---|
| 6 | " |
|---|
| 7 | " - The name of each section should be one word. |
|---|
| 8 | " |
|---|
| 9 | " * Each section consists of zero or more "subsections". |
|---|
| 10 | " |
|---|
| 11 | " - There is no rule for the name of each subsection. |
|---|
| 12 | " |
|---|
| 13 | " * The last subsection in a section should be named as "Misc.". |
|---|
| 14 | " |
|---|
| 15 | " * Whenever new subsection is inserted, |
|---|
| 16 | " it should be inserted just before Misc. subsection. |
|---|
| 17 | " |
|---|
| 18 | " * If a setting can be categorized into two or more sections, |
|---|
| 19 | " it should be put into the most bottom section in this file. |
|---|
| 20 | " |
|---|
| 21 | " For example, key mappings for a specific plugin should be put into the |
|---|
| 22 | " Plugins section. |
|---|
| 23 | " |
|---|
| 24 | " |
|---|
| 25 | " Coding Rule |
|---|
| 26 | " |
|---|
| 27 | " * Separate sections with 8 blank lines. |
|---|
| 28 | " |
|---|
| 29 | " * Separate subsections with 4 blank lines. |
|---|
| 30 | " |
|---|
| 31 | " * Character Encoding and Indentation: |
|---|
| 32 | " see the modelines in the bottom of this files. |
|---|
| 33 | " |
|---|
| 34 | " * Limit all lines to a maximum of 79 characters. |
|---|
| 35 | " |
|---|
| 36 | " * Separate {lhs} and {rhs} of key mappings with 2 spaces. |
|---|
| 37 | " |
|---|
| 38 | " * Separate {cmd} and {rep} of :command definitions with 2 spaces. |
|---|
| 39 | " |
|---|
| 40 | " * Write the full name for each command, |
|---|
| 41 | " e.g., write nnoremap not nn. |
|---|
| 42 | " |
|---|
| 43 | " - But abbreviated names may be used to follow the maximum line length. |
|---|
| 44 | " |
|---|
| 45 | " * Key Notation: |
|---|
| 46 | " |
|---|
| 47 | " - Control-keys: Write as <C-x>, neither <C-X> nor <c-x>. |
|---|
| 48 | " |
|---|
| 49 | " - Carriage return: Write as <Return>, neither <Enter> nor <CR>. |
|---|
| 50 | " |
|---|
| 51 | " - But <CR> may be used to follow the maximum line length. |
|---|
| 52 | " |
|---|
| 53 | " - Other characters: Write as same as :help key-notation |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | " Basic "{{{1 |
|---|
| 63 | " Absolute "{{{2 |
|---|
| 64 | |
|---|
| 65 | set nocompatible " to use many extensions of Vim. |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | " Encoding "{{{2 |
|---|
| 71 | |
|---|
| 72 | " To deal with Japanese language. |
|---|
| 73 | if $ENV_WORKING ==# 'colinux' |
|---|
| 74 | set encoding=utf-8 |
|---|
| 75 | else |
|---|
| 76 | set encoding=japan |
|---|
| 77 | endif |
|---|
| 78 | if !exists('did_encoding_settings') && has('iconv') |
|---|
| 79 | let s:enc_euc = 'euc-jp' |
|---|
| 80 | let s:enc_jis = 'iso-2022-jp' |
|---|
| 81 | |
|---|
| 82 | " Does iconv support JIS X 0213 ? |
|---|
| 83 | if iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') |
|---|
| 84 | \ ==# "\xad\xc5\xad\xcb" |
|---|
| 85 | let s:enc_euc = 'euc-jisx0213,euc-jp' |
|---|
| 86 | let s:enc_jis = 'iso-2022-jp-3' |
|---|
| 87 | endif |
|---|
| 88 | |
|---|
| 89 | " Make fileencodings |
|---|
| 90 | let &fileencodings = 'ucs-bom' |
|---|
| 91 | if &encoding !=# 'utf-8' |
|---|
| 92 | let &fileencodings = &fileencodings . ',' . 'ucs-2le' |
|---|
| 93 | let &fileencodings = &fileencodings . ',' . 'ucs-2' |
|---|
| 94 | endif |
|---|
| 95 | let &fileencodings = &fileencodings . ',' . s:enc_jis |
|---|
| 96 | |
|---|
| 97 | if &encoding ==# 'utf-8' |
|---|
| 98 | let &fileencodings = &fileencodings . ',' . s:enc_euc |
|---|
| 99 | let &fileencodings = &fileencodings . ',' . 'cp932' |
|---|
| 100 | elseif &encoding =~# '^euc-\%(jp\|jisx0213\)$' |
|---|
| 101 | let &encoding = s:enc_euc |
|---|
| 102 | let &fileencodings = &fileencodings . ',' . 'utf-8' |
|---|
| 103 | let &fileencodings = &fileencodings . ',' . 'cp932' |
|---|
| 104 | else " cp932 |
|---|
| 105 | let &fileencodings = &fileencodings . ',' . 'utf-8' |
|---|
| 106 | let &fileencodings = &fileencodings . ',' . s:enc_euc |
|---|
| 107 | endif |
|---|
| 108 | let &fileencodings = &fileencodings . ',' . &encoding |
|---|
| 109 | |
|---|
| 110 | unlet s:enc_euc |
|---|
| 111 | unlet s:enc_jis |
|---|
| 112 | |
|---|
| 113 | let did_encoding_settings = 1 |
|---|
| 114 | endif |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | if $ENV_ACCESS ==# 'cygwin' |
|---|
| 118 | set termencoding=cp932 |
|---|
| 119 | elseif $ENV_ACCESS ==# 'linux' |
|---|
| 120 | set termencoding=euc-jp |
|---|
| 121 | else " 'colinux' |
|---|
| 122 | set termencoding=utf-8 |
|---|
| 123 | endif |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | " Options "{{{2 |
|---|
| 129 | |
|---|
| 130 | if 1 < &t_Co && has('syntax') |
|---|
| 131 | if &term ==# 'rxvt-cygwin-native' |
|---|
| 132 | set t_Co=256 |
|---|
| 133 | endif |
|---|
| 134 | syntax enable |
|---|
| 135 | colorscheme default |
|---|
| 136 | set background=dark |
|---|
| 137 | endif |
|---|
| 138 | |
|---|
| 139 | filetype plugin indent on |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | set ambiwidth=double |
|---|
| 143 | set autoindent |
|---|
| 144 | set backspace=indent,eol,start |
|---|
| 145 | set backup |
|---|
| 146 | set backupcopy& |
|---|
| 147 | set backupdir=.,~/tmp |
|---|
| 148 | set backupskip& |
|---|
| 149 | set backupskip+=svn-commit.tmp,svn-commit.[0-9]*.tmp |
|---|
| 150 | set cinoptions=:0,t0,(0,W1s |
|---|
| 151 | set directory=.,~/tmp |
|---|
| 152 | set noequalalways |
|---|
| 153 | set formatoptions=tcroqnlM1 |
|---|
| 154 | set history=100 |
|---|
| 155 | set hlsearch |
|---|
| 156 | set grepprg=internal |
|---|
| 157 | set incsearch |
|---|
| 158 | set mouse= |
|---|
| 159 | set ruler |
|---|
| 160 | set showcmd |
|---|
| 161 | set showmode |
|---|
| 162 | set smartindent |
|---|
| 163 | set updatetime=60000 |
|---|
| 164 | set title |
|---|
| 165 | set titlestring=Vim:\ %f\ %h%r%m |
|---|
| 166 | set wildmenu |
|---|
| 167 | |
|---|
| 168 | set viminfo=<50,'10,h,r/a,n~/.viminfo |
|---|
| 169 | |
|---|
| 170 | " To automatically detect the width and the height of the terminal, |
|---|
| 171 | " the followings must not be set. |
|---|
| 172 | " |
|---|
| 173 | " set columns=80 |
|---|
| 174 | " set lines=25 |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | let mapleader=',' |
|---|
| 178 | let maplocalleader='.' |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | " Use this group for any autocmd defined in this file. |
|---|
| 182 | augroup MyAutoCmd |
|---|
| 183 | autocmd! |
|---|
| 184 | augroup END |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | " Utilities "{{{1 |
|---|
| 194 | " CMapABC: support input for Alternate Built-in Commands "{{{2 |
|---|
| 195 | |
|---|
| 196 | let s:CMapABC_Entries = [] |
|---|
| 197 | function! s:CMapABC_Add(original_pattern, alternate_name) |
|---|
| 198 | call add(s:CMapABC_Entries, [a:original_pattern, a:alternate_name]) |
|---|
| 199 | endfunction |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | cnoremap <expr> <Space> <SID>CMapABC() |
|---|
| 203 | function! s:CMapABC() |
|---|
| 204 | let cmdline = getcmdline() |
|---|
| 205 | for [original_pattern, alternate_name] in s:CMapABC_Entries |
|---|
| 206 | if cmdline =~# original_pattern |
|---|
| 207 | return "\<C-u>" . alternate_name . ' ' |
|---|
| 208 | endif |
|---|
| 209 | endfor |
|---|
| 210 | return ' ' |
|---|
| 211 | endfunction |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | " Alternate :cd which uses 'cdpath' for completion "{{{2 |
|---|
| 217 | |
|---|
| 218 | command! -complete=customlist,<SID>CommandComplete_cdpath -nargs=1 |
|---|
| 219 | \ CD cd <args> |
|---|
| 220 | |
|---|
| 221 | function! s:CommandComplete_cdpath(arglead, cmdline, cursorpos) |
|---|
| 222 | return split(globpath(&cdpath, a:arglead . '*/'), "\n") |
|---|
| 223 | endfunction |
|---|
| 224 | |
|---|
| 225 | call s:CMapABC_Add('^cd', 'CD') |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | " Help-related stuffs "{{{2 |
|---|
| 231 | |
|---|
| 232 | function! s:HelpBufWinNR() |
|---|
| 233 | let wn = 1 |
|---|
| 234 | while wn <= winnr('$') |
|---|
| 235 | let bn = winbufnr(wn) |
|---|
| 236 | if getbufvar(bn, '&buftype') == 'help' |
|---|
| 237 | return [bn, wn] |
|---|
| 238 | endif |
|---|
| 239 | let wn = wn + 1 |
|---|
| 240 | endwhile |
|---|
| 241 | return [-1, 0] |
|---|
| 242 | endfunction |
|---|
| 243 | |
|---|
| 244 | function! s:HelpWindowClose() |
|---|
| 245 | let [help_bufnr, help_winnr] = s:HelpBufWinNR() |
|---|
| 246 | if help_bufnr == -1 |
|---|
| 247 | return |
|---|
| 248 | endif |
|---|
| 249 | |
|---|
| 250 | let current_winnr = winnr() |
|---|
| 251 | execute help_winnr 'wincmd w' |
|---|
| 252 | execute 'wincmd c' |
|---|
| 253 | if current_winnr < help_winnr |
|---|
| 254 | execute current_winnr 'wincmd w' |
|---|
| 255 | elseif help_winnr < current_winnr |
|---|
| 256 | execute (current_winnr-1) 'wincmd w' |
|---|
| 257 | else |
|---|
| 258 | " NOP |
|---|
| 259 | endif |
|---|
| 260 | endfunction |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | " High-level key sequences "{{{2 |
|---|
| 266 | |
|---|
| 267 | function! s:KeysToComplete() |
|---|
| 268 | if strlen(&omnifunc) |
|---|
| 269 | return "\<C-x>\<C-o>" |
|---|
| 270 | elseif &filetype ==# 'vim' |
|---|
| 271 | return "\<C-x>\<C-v>" |
|---|
| 272 | else |
|---|
| 273 | return "\<C-n>" |
|---|
| 274 | endif |
|---|
| 275 | endfunction |
|---|
| 276 | |
|---|
| 277 | function! s:KeysToStopInsertModeCompletion() |
|---|
| 278 | if pumvisible() |
|---|
| 279 | return "\<C-y>" |
|---|
| 280 | else |
|---|
| 281 | return "\<Space>\<BS>" |
|---|
| 282 | endif |
|---|
| 283 | endfunction |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | function! s:KeysToEscapeCommandlineModeIfEmpty(key) |
|---|
| 287 | if getcmdline() == '' |
|---|
| 288 | return "\<Esc>" |
|---|
| 289 | else |
|---|
| 290 | return a:key |
|---|
| 291 | end |
|---|
| 292 | endfunction |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | function! s:KeysToInsertOneCharacter() |
|---|
| 296 | echohl ModeMsg |
|---|
| 297 | echo '-- INSERT (one char) --' |
|---|
| 298 | return nr2char(getchar()) . "\<Esc>" |
|---|
| 299 | endfunction |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | " :edit with specified 'fileencoding'. "{{{2 |
|---|
| 305 | |
|---|
| 306 | com! -nargs=? -complete=file -bang -bar Cp932 edit<bang> ++enc=cp932 <args> |
|---|
| 307 | com! -nargs=? -complete=file -bang -bar Eucjp edit<bang> ++enc=euc-jp <args> |
|---|
| 308 | com! -nargs=? -complete=file -bang -bar Iso2022jp Jis<bang> <args> |
|---|
| 309 | com! -nargs=? -complete=file -bang -bar Jis edit<bang> ++enc=iso-2022-jp <args> |
|---|
| 310 | com! -nargs=? -complete=file -bang -bar Sjis Cp932<bang> <args> |
|---|
| 311 | com! -nargs=? -complete=file -bang -bar Utf8 edit<bang> ++enc=utf-8 <args> |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | " Jump sections "{{{2 |
|---|
| 317 | |
|---|
| 318 | " for normal mode. a:pattern is '/regexp' or '?regexp'. |
|---|
| 319 | function! s:JumpSectionN(pattern) |
|---|
| 320 | let pattern = strpart(a:pattern, '1') |
|---|
| 321 | if strpart(a:pattern, 0, 1) == '/' |
|---|
| 322 | let flags = 'W' |
|---|
| 323 | else |
|---|
| 324 | let flags = 'Wb' |
|---|
| 325 | endif |
|---|
| 326 | |
|---|
| 327 | mark ' |
|---|
| 328 | let i = 0 |
|---|
| 329 | while i < v:count1 |
|---|
| 330 | if search(pattern, flags) == 0 |
|---|
| 331 | if stridx(flags, 'b') != -1 |
|---|
| 332 | normal! gg |
|---|
| 333 | else |
|---|
| 334 | normal! G |
|---|
| 335 | endif |
|---|
| 336 | break |
|---|
| 337 | endif |
|---|
| 338 | let i = i + 1 |
|---|
| 339 | endwhile |
|---|
| 340 | endfunction |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | " for visual mode. a:motion is '[[', '[]', ']]' or ']['. |
|---|
| 344 | function! s:JumpSectionV(motion) |
|---|
| 345 | execute 'normal!' "gv\<Esc>" |
|---|
| 346 | execute 'normal' v:count1 . a:motion |
|---|
| 347 | let line = line('.') |
|---|
| 348 | let col = col('.') |
|---|
| 349 | |
|---|
| 350 | normal! gv |
|---|
| 351 | call cursor(line, col) |
|---|
| 352 | endfunction |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | " for operator-pending mode. a:motion is '[[', '[]', ']]' or ']['. |
|---|
| 356 | function! s:JumpSectionO(motion) |
|---|
| 357 | execute 'normal' v:count1 . a:motion |
|---|
| 358 | endfunction |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | " Misc. "{{{2 |
|---|
| 364 | |
|---|
| 365 | function! s:ToggleBell() |
|---|
| 366 | if &visualbell |
|---|
| 367 | set novisualbell t_vb& |
|---|
| 368 | echo 'bell on' |
|---|
| 369 | else |
|---|
| 370 | set visualbell t_vb= |
|---|
| 371 | echo 'bell off' |
|---|
| 372 | endif |
|---|
| 373 | endfunction |
|---|
| 374 | |
|---|
| 375 | function! s:ToggleOption(option_name) |
|---|
| 376 | execute 'setlocal' a:option_name.'!' |
|---|
| 377 | execute 'setlocal' a:option_name.'?' |
|---|
| 378 | endfunction |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | function! s:ExtendHighlight(target_group, original_group, new_settings) |
|---|
| 382 | redir => resp |
|---|
| 383 | silent execute 'highlight' a:original_group |
|---|
| 384 | redir END |
|---|
| 385 | if resp =~# 'xxx cleared' |
|---|
| 386 | let original_settings = '' |
|---|
| 387 | elseif resp =~# 'xxx links to' |
|---|
| 388 | return s:ExtendHighlight( |
|---|
| 389 | \ a:target_group, |
|---|
| 390 | \ substitute(resp, '\_.*xxx links to\s\+\(\S\+\)', '\1', ''), |
|---|
| 391 | \ a:new_settings |
|---|
| 392 | \ ) |
|---|
| 393 | else " xxx {key}={arg} ... |
|---|
| 394 | let t = substitute(resp,'\_.*xxx\(\(\_s\+[^= \t]\+=[^= \t]\+\)*\)','\1','') |
|---|
| 395 | let original_settings = substitute(t, '\_s\+', ' ', 'g') |
|---|
| 396 | endif |
|---|
| 397 | |
|---|
| 398 | silent execute 'highlight' a:target_group 'NONE' |
|---|
| 399 | \ '|' 'highlight' a:target_group original_settings |
|---|
| 400 | \ '|' 'highlight' a:target_group a:new_settings |
|---|
| 401 | endfunction |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | function! s:RenameBuffer(name) |
|---|
| 405 | let name = a:name |
|---|
| 406 | let i = 0 |
|---|
| 407 | while 1 |
|---|
| 408 | if !bufexists(name) |
|---|
| 409 | break |
|---|
| 410 | endif |
|---|
| 411 | let i = i + 1 |
|---|
| 412 | let name = a:name . ' (' . i . ')' |
|---|
| 413 | endwhile |
|---|
| 414 | file `=name` |
|---|
| 415 | endfunction |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | function! s:CreateTemporaryBuffer(name, how_to_open) |
|---|
| 419 | execute a:how_to_open |
|---|
| 420 | setlocal bufhidden=wipe buflisted buftype=nofile noswapfile |
|---|
| 421 | call s:RenameBuffer(a:name) |
|---|
| 422 | endfunction |
|---|
| 423 | |
|---|
| 424 | function! s:CreateCommandOutputBuffer(command, ...) " spliting_modifier? |
|---|
| 425 | let spliting_modifier = (1 <= a:0 ? a:1 : '') |
|---|
| 426 | let previous_window_nr = winnr() |
|---|
| 427 | let previous_windows_placement = winrestcmd() |
|---|
| 428 | |
|---|
| 429 | call s:CreateTemporaryBuffer('CMD: '.a:command, spliting_modifier.' new') |
|---|
| 430 | silent execute 'read !' a:command |
|---|
| 431 | |
|---|
| 432 | if line('$') == 1 && getline(1) == '' |
|---|
| 433 | close |
|---|
| 434 | execute previous_windows_placement |
|---|
| 435 | execute previous_window_nr 'wincmd w' |
|---|
| 436 | |
|---|
| 437 | redraw " to ensure show the following message. |
|---|
| 438 | echomsg 'No output from the command:' a:command |
|---|
| 439 | return 0 |
|---|
| 440 | else |
|---|
| 441 | 1 |
|---|
| 442 | delete |
|---|
| 443 | filetype detect |
|---|
| 444 | return 1 |
|---|
| 445 | endif |
|---|
| 446 | endfunction |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | function! s:Count(...) |
|---|
| 450 | if v:count == v:count1 " count is specified. |
|---|
| 451 | return v:count |
|---|
| 452 | else " count is not specified. (the default '' is useful for special value) |
|---|
| 453 | return a:0 == 0 ? '' : a:1 |
|---|
| 454 | endif |
|---|
| 455 | endfunction |
|---|
| 456 | |
|---|
| 457 | command! -nargs=* -complete=expression -range -count=0 Execute |
|---|
| 458 | \ call s:Execute(<f-args>) |
|---|
| 459 | function! s:Execute(...) |
|---|
| 460 | let args = [] |
|---|
| 461 | for a in a:000 |
|---|
| 462 | if a ==# '[count]' |
|---|
| 463 | let a = s:Count() |
|---|
| 464 | endif |
|---|
| 465 | call add(args, a) |
|---|
| 466 | endfor |
|---|
| 467 | execute join(args) |
|---|
| 468 | endfunction |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | " like join (J), but move the next line into the cursor position. |
|---|
| 472 | function! s:JoinHere(...) |
|---|
| 473 | let adjust_spacesp = a:0 ? a:1 : 1 |
|---|
| 474 | let pos = getpos('.') |
|---|
| 475 | let r = @" |
|---|
| 476 | |
|---|
| 477 | if adjust_spacesp " adjust spaces between texts being joined as same as J. |
|---|
| 478 | normal! D |
|---|
| 479 | let l = @" |
|---|
| 480 | |
|---|
| 481 | normal! J |
|---|
| 482 | |
|---|
| 483 | call append(line('.'), '') |
|---|
| 484 | call setreg('"', l, 'c') |
|---|
| 485 | normal! jpkJ |
|---|
| 486 | else " don't adjust spaces like gJ. |
|---|
| 487 | call setreg('"', getline(line('.') + 1), 'c') |
|---|
| 488 | normal! ""Pjdd |
|---|
| 489 | endif |
|---|
| 490 | |
|---|
| 491 | let @" = r |
|---|
| 492 | call setpos('.', pos) |
|---|
| 493 | endfunction |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | function! s:SCCSDiffAll() |
|---|
| 497 | if isdirectory('.svn') |
|---|
| 498 | let cmd = 'svn' |
|---|
| 499 | elseif isdirectory('CVS') |
|---|
| 500 | let cmd = 'cvs' |
|---|
| 501 | else |
|---|
| 502 | let cmd = 'svk' |
|---|
| 503 | endif |
|---|
| 504 | |
|---|
| 505 | let was_tab_boredp = s:BoringTabP() |
|---|
| 506 | let openp = s:CreateCommandOutputBuffer(cmd.' diff', 'botright') |
|---|
| 507 | if was_tab_boredp && openp |
|---|
| 508 | only " close all boring windows. |
|---|
| 509 | endif |
|---|
| 510 | endfunction |
|---|
| 511 | |
|---|
| 512 | |
|---|
| 513 | function! s:BoringTabP(...) " are all windows in the tab boring? |
|---|
| 514 | " boring window is a window which shows a boring buffer. |
|---|
| 515 | let tid = a:0 ? a:1 : tabpagenr() |
|---|
| 516 | for wid in range(1, tabpagewinnr(tid, '$')) |
|---|
| 517 | let bid = winbufnr(wid) |
|---|
| 518 | if !s:BoringBufferP(bid) |
|---|
| 519 | return 0 |
|---|
| 520 | endif |
|---|
| 521 | endfor |
|---|
| 522 | return 1 |
|---|
| 523 | endfunction |
|---|
| 524 | |
|---|
| 525 | function! s:BoringBufferP(bid) " is the buffer unnamed and not editted? |
|---|
| 526 | return bufname(a:bid) == '' && getbufvar(a:bid, '&modified') == 0 |
|---|
| 527 | endfunction |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | function! s:SetShortIndent() |
|---|
| 531 | setlocal expandtab softtabstop=2 shiftwidth=2 |
|---|
| 532 | endfunction |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | " Are the windows :split'ed and :vsplit'ed? |
|---|
| 536 | function! s:WindowsJumbledP() |
|---|
| 537 | " Calculate the terminal height by some values other than 'lines'. |
|---|
| 538 | " Don't consider about :vsplit. |
|---|
| 539 | let calculated_height = &cmdheight |
|---|
| 540 | let winid = winnr('$') |
|---|
| 541 | while 0 < winid |
|---|
| 542 | let calculated_height += 1 " statusline |
|---|
| 543 | let calculated_height += winheight(winid) |
|---|
| 544 | let winid = winid - 1 |
|---|
| 545 | endwhile |
|---|
| 546 | if &laststatus == 0 |
|---|
| 547 | let calculated_height -= 1 |
|---|
| 548 | elseif &laststatus == 1 && winnr('$') == 1 |
|---|
| 549 | let calculated_height -= 1 |
|---|
| 550 | else " &laststatus == 2 |
|---|
| 551 | " nothing to do |
|---|
| 552 | endif |
|---|
| 553 | |
|---|
| 554 | " Calculate the terminal width by some values other than 'columns'. |
|---|
| 555 | " Don't consider about :split. |
|---|
| 556 | let calculated_width = 0 |
|---|
| 557 | let winid = winnr('$') |
|---|
| 558 | while 0 < winid |
|---|
| 559 | let calculated_width += 1 " VertSplit |
|---|
| 560 | let calculated_width += winwidth(winid) |
|---|
| 561 | let winid = winid - 1 |
|---|
| 562 | endwhile |
|---|
| 563 | let calculated_width -= 1 |
|---|
| 564 | |
|---|
| 565 | " If the windows are only :split'ed, &lines == calculated_height. |
|---|
| 566 | " If the windows are only :vsplit'ed, &columns == calculated_width. |
|---|
| 567 | " If there is only one window, both pairs are same. |
|---|
| 568 | " If the windows are :split'ed and :vsplit'ed, both pairs are different. |
|---|
| 569 | return (&lines != calculated_height) && (&columns != calculated_width) |
|---|
| 570 | endfunction |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | function! s:MoveWindowThenEqualizeIfNecessary(direction) |
|---|
| 574 | let jumbled_beforep = s:WindowsJumbledP() |
|---|
| 575 | execute 'wincmd' a:direction |
|---|
| 576 | let jumbled_afterp = s:WindowsJumbledP() |
|---|
| 577 | |
|---|
| 578 | if jumbled_beforep || jumbled_afterp |
|---|
| 579 | wincmd = |
|---|
| 580 | endif |
|---|
| 581 | endfunction |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | " Key Mappings "{{{1 |
|---|
| 591 | " FIXME: many {rhs}s use : without <C-u> (clearing count effect). |
|---|
| 592 | " FIXME: some mappings are not countable. |
|---|
| 593 | " Tag jumping "{{{2 |
|---|
| 594 | " FIXME: the target window of :split/:vsplit version. |
|---|
| 595 | " Fallback "{{{3 |
|---|
| 596 | |
|---|
| 597 | " ``T'' is also disabled for consistency. |
|---|
| 598 | noremap t <Nop> |
|---|
| 599 | noremap T <Nop> |
|---|
| 600 | |
|---|
| 601 | " Alternatives for the original actions. |
|---|
| 602 | noremap [Space]t t |
|---|
| 603 | noremap [Space]T T |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | " Basic "{{{3 |
|---|
| 607 | |
|---|
| 608 | nmap t<Space> tt |
|---|
| 609 | vmap t<Space> tt |
|---|
| 610 | nnoremap tt <C-]> |
|---|
| 611 | vnoremap tt <C-]> |
|---|
| 612 | nnoremap tj :tag<Return> |
|---|
| 613 | nnoremap tk :pop<Return> |
|---|
| 614 | nnoremap tl :tags<Return> |
|---|
| 615 | nnoremap tn :tnext<Return> |
|---|
| 616 | nnoremap tp :tprevious<Return> |
|---|
| 617 | nnoremap tP :tfirst<Return> |
|---|
| 618 | nnoremap tN :tlast<Return> |
|---|
| 619 | |
|---|
| 620 | " additionals, like Web browsers |
|---|
| 621 | nmap <C-m> tt |
|---|
| 622 | vmap <C-m> tt |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | " With the preview window "{{{3 |
|---|
| 626 | |
|---|
| 627 | nmap t'<Space> t't |
|---|
| 628 | vmap t'<Space> t't |
|---|
| 629 | nnoremap t't <C-w>} |
|---|
| 630 | vnoremap t't <C-w>} |
|---|
| 631 | nnoremap t'n :ptnext<Return> |
|---|
| 632 | nnoremap t'p :ptpevious<Return> |
|---|
| 633 | nnoremap t'P :ptfirst<Return> |
|---|
| 634 | nnoremap t'N :ptlast<Return> |
|---|
| 635 | |
|---|
| 636 | " although :pclose is not related to tag. |
|---|
| 637 | nnoremap t'c :pclose<Return> |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | " With :split "{{{3 |
|---|
| 641 | |
|---|
| 642 | nnoremap tst <C-w>] |
|---|
| 643 | vnoremap tst <C-w>] |
|---|
| 644 | nmap ts<Space> tst |
|---|
| 645 | vmap ts<Space> tst |
|---|
| 646 | nnoremap tsn :split \| tnext<Return> |
|---|
| 647 | nnoremap tsp :split \| tpevious<Return> |
|---|
| 648 | nnoremap tsP :split \| tfirst<Return> |
|---|
| 649 | nnoremap tsN :split \| tlast<Return> |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | " With :vertical split "{{{3 |
|---|
| 653 | |
|---|
| 654 | " |:vsplit|-then-|<C-]>| is simple |
|---|
| 655 | " but its modification to tag stacks is not same as |<C-w>]|. |
|---|
| 656 | nnoremap tvt <C-]>:vsplit<Return><C-w>p<C-t><C-w>p |
|---|
| 657 | vnoremap tvt <C-]>:vsplit<Return><C-w>p<C-t><C-w>p |
|---|
| 658 | nmap tv<Space> tvt |
|---|
| 659 | vmap tv<Space> tvt |
|---|
| 660 | nnoremap tvn :vsplit \| tnext<Return> |
|---|
| 661 | nnoremap tvp :vsplit \| tpevious<Return> |
|---|
| 662 | nnoremap tvP :vsplit \| tfirst<Return> |
|---|
| 663 | nnoremap tvN :vsplit \| tlast<Return> |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | " Quickfix "{{{2 |
|---|
| 669 | " Fallback "{{{3 |
|---|
| 670 | |
|---|
| 671 | " the prefix key. |
|---|
| 672 | nnoremap q <Nop> |
|---|
| 673 | |
|---|
| 674 | " alternative key for the original action. |
|---|
| 675 | " -- Ex-mode will be never used and recordings are rarely used. |
|---|
| 676 | nnoremap Q q |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | " For quickfix list "{{{3 |
|---|
| 680 | |
|---|
| 681 | nnoremap qj :Execute cnext [count]<Return> |
|---|
| 682 | nnoremap qk :Execute cprevious [count]<Return> |
|---|
| 683 | nnoremap qr :Execute crewind [count]<Return> |
|---|
| 684 | nnoremap qK :Execute cfirst [count]<Return> |
|---|
| 685 | nnoremap qJ :Execute clast [count]<Return> |
|---|
| 686 | nnoremap qfj :Execute cnfile [count]<Return> |
|---|
| 687 | nnoremap qfk :Execute cpfile [count]<Return> |
|---|
| 688 | nnoremap ql :clist<Return> |
|---|
| 689 | nnoremap qq :Execute cc [count]<Return> |
|---|
| 690 | nnoremap qo :Execute copen [count]<Return> |
|---|
| 691 | nnoremap qc :cclose<Return> |
|---|
| 692 | nnoremap qp :Execute colder [count]<Return> |
|---|
| 693 | nnoremap qn :Execute cnewer [count]<Return> |
|---|
| 694 | nnoremap qm :make<Return> |
|---|
| 695 | nnoremap qM :make<Space> |
|---|
| 696 | nnoremap q<Space> :make<Space> |
|---|
| 697 | nnoremap qg :grep<Space> |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | " For location list (mnemonic: Quickfix list for the current Window) "{{{3 |
|---|
| 701 | |
|---|
| 702 | nnoremap qwj :Execute lnext [count]<Return> |
|---|
| 703 | nnoremap qwk :Execute lprevious [count]<Return> |
|---|
| 704 | nnoremap qwr :Execute lrewind [count]<Return> |
|---|
| 705 | nnoremap qwK :Execute lfirst [count]<Return> |
|---|
| 706 | nnoremap qwJ :Execute llast [count]<Return> |
|---|
| 707 | nnoremap qwfj :Execute lnfile [count]<Return> |
|---|
| 708 | nnoremap qwfk :Execute lpfile [count]<Return> |
|---|
| 709 | nnoremap qwl :llist<Return> |
|---|
| 710 | nnoremap qwq :Execute ll [count]<Return> |
|---|
| 711 | nnoremap qwo :Execute lopen [count]<Return> |
|---|
| 712 | nnoremap qwc :lclose<Return> |
|---|
| 713 | nnoremap qwp :Execute lolder [count]<Return> |
|---|
| 714 | nnoremap qwn :Execute lnewer [count]<Return> |
|---|
| 715 | nnoremap qwm :lmake<Return> |
|---|
| 716 | nnoremap qwM :lmake<Space> |
|---|
| 717 | nnoremap qw<Space> :lmake<Space> |
|---|
| 718 | nnoremap qwg :lgrep<Space> |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | " Tab pages "{{{2 |
|---|
| 724 | " The mappings defined here are similar to the ones for windows. |
|---|
| 725 | " FIXME: sometimes, hit-enter prompt appears. but no idea for the reason. |
|---|
| 726 | " Fallback "{{{3 |
|---|
| 727 | |
|---|
| 728 | " the prefix key. |
|---|
| 729 | " -- see Tag jumping subsection for alternative keys for the original action |
|---|
| 730 | " of <C-t>. |
|---|
| 731 | nnoremap <C-t> <Nop> |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | " Basic "{{{3 |
|---|
| 735 | |
|---|
| 736 | nnoremap <C-t>n :<C-u>tabnew<Return> |
|---|
| 737 | nnoremap <C-t>c :<C-u>tabclose<Return> |
|---|
| 738 | nnoremap <C-t>o :<C-u>tabonly<Return> |
|---|
| 739 | nnoremap <C-t>i :<C-u>tabs<Return> |
|---|
| 740 | |
|---|
| 741 | nmap <C-t><C-n> <C-t>n |
|---|
| 742 | nmap <C-t><C-c> <C-t>c |
|---|
| 743 | nmap <C-t><C-o> <C-t>o |
|---|
| 744 | nmap <C-t><C-i> <C-t>i |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | " Moving around tabs. "{{{3 |
|---|
| 748 | |
|---|
| 749 | nnoremap <C-t>j :<C-u>execute 'tabnext' |
|---|
| 750 | \ 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$')<Return> |
|---|
| 751 | nnoremap <C-t>k :Execute tabprevious [count]<Return> |
|---|
| 752 | nnoremap <C-t>K :<C-u>tabfirst<Return> |
|---|
| 753 | nnoremap <C-t>J :<C-u>tablast<Return> |
|---|
| 754 | nmap <C-t>t <C-t>j |
|---|
| 755 | nmap <C-t>T <C-t>k |
|---|
| 756 | |
|---|
| 757 | nmap <C-t><C-j> <C-t>j |
|---|
| 758 | nmap <C-t><C-k> <C-t>k |
|---|
| 759 | nmap <C-t><C-t> <C-t>t |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | " Moving tabs themselves. "{{{3 |
|---|
| 763 | |
|---|
| 764 | nnoremap <C-t>l :<C-u>execute 'tabmove' |
|---|
| 765 | \ min([tabpagenr() + v:count1 - 1, tabpagenr('$')])<Return> |
|---|
| 766 | nnoremap <C-t>h :<C-u>execute 'tabmove' |
|---|
| 767 | \ max([tabpagenr() - v:count1 - 1, 0])<Return> |
|---|
| 768 | nnoremap <C-t>L :<C-u>tabmove<Return> |
|---|
| 769 | nnoremap <C-t>H :<C-u>tabmove 0<Return> |
|---|
| 770 | |
|---|
| 771 | nmap <C-t><C-l> <C-t>l |
|---|
| 772 | nmap <C-t><C-h> <C-t>h |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | " Command-line editting "{{{2 |
|---|
| 778 | |
|---|
| 779 | " pseudo vi-like keys |
|---|
| 780 | cnoremap <Esc>h <Left> |
|---|
| 781 | cnoremap <Esc>j <Down> |
|---|
| 782 | cnoremap <Esc>k <Up> |
|---|
| 783 | cnoremap <Esc>l <Right> |
|---|
| 784 | cnoremap <Esc>H <Home> |
|---|
| 785 | cnoremap <Esc>L <End> |
|---|
| 786 | cnoremap <Esc>w <S-Right> |
|---|
| 787 | cnoremap <Esc>b <S-Left> |
|---|
| 788 | cnoremap <Esc>x <Del> |
|---|
| 789 | |
|---|
| 790 | " escape Command-line mode if the command line is empty (like <C-h>) |
|---|
| 791 | cnoremap <expr> <C-u> <SID>KeysToEscapeCommandlineModeIfEmpty("\<C-u>") |
|---|
| 792 | cnoremap <expr> <C-w> <SID>KeysToEscapeCommandlineModeIfEmpty("\<C-w>") |
|---|
| 793 | |
|---|
| 794 | " Search slashes easily (too lazy to prefix backslashes to slashes) |
|---|
| 795 | cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/' |
|---|
| 796 | |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | |
|---|
| 800 | " Input: datetime "{{{2 |
|---|
| 801 | " |
|---|
| 802 | " Input the current date/time (Full, Date, Time). |
|---|
| 803 | " |
|---|
| 804 | " FIXME: use timezone of the system, instead of static one. |
|---|
| 805 | " |
|---|
| 806 | " FIXME: revise the {lhs}s, compare with the default keys of todatetime. |
|---|
| 807 | |
|---|
| 808 | inoremap <Leader>dF <C-r>=strftime('%Y-%m-%dT%H:%M:%S+09:00')<Return> |
|---|
| 809 | inoremap <Leader>df <C-r>=strftime('%Y-%m-%dT%H:%M:%S')<Return> |
|---|
| 810 | inoremap <Leader>dd <C-r>=strftime('%Y-%m-%d')<Return> |
|---|
| 811 | inoremap <Leader>dT <C-r>=strftime('%H:%M:%S')<Return> |
|---|
| 812 | inoremap <Leader>dt <C-r>=strftime('%H:%M')<Return> |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | " Section jumping "{{{2 |
|---|
| 818 | " |
|---|
| 819 | " Enable *consistent* ]] and other motions in Visual and Operator-pending |
|---|
| 820 | " mode. Because some ftplugins provide these motions only for Normal mode |
|---|
| 821 | " and other ftplugins provides provide these motions with some faults, e.g., |
|---|
| 822 | " not countable. |
|---|
| 823 | |
|---|
| 824 | vnoremap <silent> ]] :<C-u>call <SID>JumpSectionV(']]')<Return> |
|---|
| 825 | vnoremap <silent> ][ :<C-u>call <SID>JumpSectionV('][')<Return> |
|---|
| 826 | vnoremap <silent> [[ :<C-u>call <SID>JumpSectionV('[[')<Return> |
|---|
| 827 | vnoremap <silent> [] :<C-u>call <SID>JumpSectionV('[]')<Return> |
|---|
| 828 | onoremap <silent> ]] :<C-u>call <SID>JumpSectionO(']]')<Return> |
|---|
| 829 | onoremap <silent> ][ :<C-u>call <SID>JumpSectionO('][')<Return> |
|---|
| 830 | onoremap <silent> [[ :<C-u>call <SID>JumpSectionO('[[')<Return> |
|---|
| 831 | onoremap <silent> [] :<C-u>call <SID>JumpSectionO('[]')<Return> |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | " The <Space> "{{{2 |
|---|
| 837 | " |
|---|
| 838 | " Various hotkeys prefixed by <Space>. |
|---|
| 839 | |
|---|
| 840 | " to show <Space> in the bottom line. |
|---|
| 841 | map <Space> [Space] |
|---|
| 842 | |
|---|
| 843 | " fallback |
|---|
| 844 | noremap [Space] <Nop> |
|---|
| 845 | |
|---|
| 846 | |
|---|
| 847 | nnoremap [Space]/ :nohlsearch<Return> |
|---|
| 848 | |
|---|
| 849 | nnoremap [Space]? :call <SID>HelpWindowClose()<Return> |
|---|
| 850 | |
|---|
| 851 | " append one character |
|---|
| 852 | nnoremap [Space]A A<C-r>=<SID>KeysToInsertOneCharacter()<Return> |
|---|
| 853 | nnoremap [Space]a a<C-r>=<SID>KeysToInsertOneCharacter()<Return> |
|---|
| 854 | |
|---|
| 855 | nnoremap [Space]e :setlocal encoding? termencoding? fenc? fencs?<Return> |
|---|
| 856 | nnoremap [Space]f :setlocal filetype? fileencoding? fileformat?<Return> |
|---|
| 857 | |
|---|
| 858 | " insert one character |
|---|
| 859 | nnoremap [Space]I I<C-r>=<SID>KeysToInsertOneCharacter()<Return> |
|---|
| 860 | nnoremap [Space]i i<C-r>=<SID>KeysToInsertOneCharacter()<Return> |
|---|
| 861 | |
|---|
| 862 | nnoremap [Space]J :<C-u>call <SID>JoinHere(1)<Return> |
|---|
| 863 | nnoremap [Space]gJ :<C-u>call <SID>JoinHere(0)<Return> |
|---|
| 864 | " unjoin |
|---|
| 865 | nnoremap [Space]j i<Return><Esc> |
|---|
| 866 | |
|---|
| 867 | nnoremap [Space]ob :call <SID>ToggleBell()<Return> |
|---|
| 868 | nnoremap [Space]ow :call <SID>ToggleOption('wrap')<Return> |
|---|
| 869 | |
|---|
| 870 | nnoremap [Space]q :help quickref<Return> |
|---|
| 871 | |
|---|
| 872 | nnoremap [Space]r :registers<Return> |
|---|
| 873 | |
|---|
| 874 | nnoremap [Space]s <Nop> |
|---|
| 875 | nnoremap [Space]s. :source $HOME/.vimrc<Return> |
|---|
| 876 | nnoremap [Space]ss :source %<Return> |
|---|
| 877 | |
|---|
| 878 | vnoremap [Space]s :sort<Return> |
|---|
| 879 | |
|---|
| 880 | " for backward compatibility |
|---|
| 881 | nmap [Space]w [Space]ow |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | " Windows "{{{2 |
|---|
| 887 | " |
|---|
| 888 | " Synonyms for the default mappings, with single key strokes. |
|---|
| 889 | |
|---|
| 890 | nnoremap <Esc>h <C-w>h |
|---|
| 891 | nnoremap <Esc>j <C-w>j |
|---|
| 892 | nnoremap <Esc>k <C-w>k |
|---|
| 893 | nnoremap <Esc>l <C-w>l |
|---|
| 894 | |
|---|
| 895 | nnoremap <Esc>H :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('H')<Return> |
|---|
| 896 | nnoremap <Esc>J :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('J')<Return> |
|---|
| 897 | nnoremap <Esc>K :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('K')<Return> |
|---|
| 898 | nnoremap <Esc>L :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('L')<Return> |
|---|
| 899 | |
|---|
| 900 | nnoremap <C-i> <C-w>w |
|---|
| 901 | " <Tab> = <C-i> |
|---|
| 902 | nnoremap <Esc>i <C-w>W |
|---|
| 903 | nmap <S-Tab> <Esc>i |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | |
|---|
| 908 | " Misc. "{{{2 |
|---|
| 909 | |
|---|
| 910 | nnoremap <C-h> :h<Space> |
|---|
| 911 | nnoremap <C-o> :e<Space> |
|---|
| 912 | nnoremap <C-w>. :e .<Return> |
|---|
| 913 | nnoremap <silent> <Leader>cD :<C-u>call <SID>SCCSDiffAll()<CR> |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | " Jump list |
|---|
| 917 | nnoremap <C-j> <C-i> |
|---|
| 918 | nnoremap <C-k> <C-o> |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | " Switch to the previously edited file (like Vz) |
|---|
| 922 | nnoremap <Esc>2 :e #<Return> |
|---|
| 923 | nmap <F2> <Esc>2 |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | " Too lazy to press Shift key. |
|---|
| 927 | noremap ; : |
|---|
| 928 | noremap : ; |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | " Disable some dangerous key. |
|---|
| 932 | nnoremap ZZ <Nop> |
|---|
| 933 | nnoremap ZQ <Nop> |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | " Use a backslash (\) to repeat last change. |
|---|
| 937 | " Since a dot (.) is used as <LocalLeader>. |
|---|
| 938 | nnoremap \ . |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | " Complete or indent. |
|---|
| 942 | inoremap <expr> <C-i> (<SID>ShouldIndentRatherThanCompleteP() |
|---|
| 943 | \ ? '<C-i>' |
|---|
| 944 | \ : <SID>KeysToComplete()) |
|---|
| 945 | |
|---|
| 946 | function! s:ShouldIndentRatherThanCompleteP() |
|---|
| 947 | let m = match(getline('.'), '\S') |
|---|
| 948 | return m == -1 || col('.')-1 <= m |
|---|
| 949 | endfunction |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | " Swap ` and ' -- I prefer ` to ' and ` is not easy to type. |
|---|
| 953 | noremap ' ` |
|---|
| 954 | noremap ` ' |
|---|
| 955 | |
|---|
| 956 | |
|---|
| 957 | " To be able to undo these types of deletion in Insert mode. |
|---|
| 958 | inoremap <C-w> <C-g>u<C-w> |
|---|
| 959 | inoremap <C-u> <C-g>u<C-u> |
|---|
| 960 | |
|---|
| 961 | |
|---|
| 962 | " Search the word nearest to the cursor in new window. |
|---|
| 963 | nnoremap <C-w>* <C-w>s* |
|---|
| 964 | nnoremap <C-w># <C-g>s# |
|---|
| 965 | |
|---|
| 966 | |
|---|
| 967 | " Synonyms for <> and [], same as plugin surround. |
|---|
| 968 | vnoremap aa a> |
|---|
| 969 | vnoremap ia i> |
|---|
| 970 | |
|---|
| 971 | vnoremap ar a] |
|---|
| 972 | vnoremap ir i] |
|---|
| 973 | |
|---|
| 974 | |
|---|
| 975 | |
|---|
| 976 | |
|---|
| 977 | |
|---|
| 978 | |
|---|
| 979 | |
|---|
| 980 | |
|---|
| 981 | " Filetypes "{{{1 |
|---|
| 982 | " All "{{{2 |
|---|
| 983 | |
|---|
| 984 | autocmd MyAutoCmd FileType * |
|---|
| 985 | \ call <SID>FileType_any() |
|---|
| 986 | |
|---|
| 987 | function! s:FileType_any() |
|---|
| 988 | " To use my global mappings for section jumping, |
|---|
| 989 | " remove buffer local mappings defined by ftplugin. |
|---|
| 990 | silent! vunmap <buffer> ]] |
|---|
| 991 | silent! vunmap <buffer> ][ |
|---|
| 992 | silent! vunmap <buffer> [] |
|---|
| 993 | silent! vunmap <buffer> [[ |
|---|
| 994 | silent! ounmap <buffer> ]] |
|---|
| 995 | silent! ounmap <buffer> ][ |
|---|
| 996 | silent! ounmap <buffer> [] |
|---|
| 997 | silent! ounmap <buffer> [[ |
|---|
| 998 | endfunction |
|---|
| 999 | |
|---|
| 1000 | |
|---|
| 1001 | " although this is not a filetype settings. |
|---|
| 1002 | autocmd MyAutoCmd ColorScheme * |
|---|
| 1003 | \ call <SID>ExtendHighlight('Pmenu', 'Normal', 'cterm=underline') |
|---|
| 1004 | \ | call <SID>ExtendHighlight('PmenuSel', 'Search', 'cterm=underline') |
|---|
| 1005 | \ | call <SID>ExtendHighlight('PmenuSbar', 'Normal', 'cterm=reverse') |
|---|
| 1006 | \ | call <SID>ExtendHighlight('PmenuThumb', 'Search', '') |
|---|
| 1007 | doautocmd MyAutoCmd ColorScheme because-colorscheme-has-been-set-above. |
|---|
| 1008 | |
|---|
| 1009 | |
|---|
| 1010 | |
|---|
| 1011 | |
|---|
| 1012 | " dosini (.ini) "{{{2 |
|---|
| 1013 | |
|---|
| 1014 | autocmd MyAutoCmd FileType dosini |
|---|
| 1015 | \ call <SID>FileType_dosini() |
|---|
| 1016 | |
|---|
| 1017 | function! s:FileType_dosini() |
|---|
| 1018 | nnoremap <buffer> <silent> ]] :<C-u>call <SID>JumpSectionN('/^\[')<Return> |
|---|
| 1019 | nnoremap <buffer> <silent> ][ :<C-u>call <SID>JumpSectionN('/\n\[\@=')<CR> |
|---|
| 1020 | nnoremap <buffer> <silent> [[ :<C-u>call <SID>JumpSectionN('?^\[')<Return> |
|---|
| 1021 | nnoremap <buffer> <silent> [] :<C-u>call <SID>JumpSectionN('?\n\[\@=')<CR> |
|---|
| 1022 | endfunction |
|---|
| 1023 | |
|---|
| 1024 | |
|---|
| 1025 | |
|---|
| 1026 | |
|---|
| 1027 | " lua "{{{2 |
|---|
| 1028 | |
|---|
| 1029 | autocmd MyAutoCmd FileType lua |
|---|
| 1030 | \ call <SID>SetShortIndent() |
|---|
| 1031 | |
|---|
| 1032 | |
|---|
| 1033 | |
|---|
| 1034 | |
|---|
| 1035 | " netrw "{{{2 |
|---|
| 1036 | " |
|---|
| 1037 | " Consider these buffers have "another" filetype=netrw. |
|---|
| 1038 | |
|---|
| 1039 | autocmd MyAutoCmd BufReadPost {dav,file,ftp,http,rcp,rsync,scp,sftp}://* |
|---|
| 1040 | \ setlocal bufhidden=hide |
|---|
| 1041 | |
|---|
| 1042 | |
|---|
| 1043 | |
|---|
| 1044 | |
|---|
| 1045 | " python "{{{2 |
|---|
| 1046 | |
|---|
| 1047 | autocmd MyAutoCmd FileType python |
|---|
| 1048 | \ call <SID>SetShortIndent() |
|---|
| 1049 | \ | let python_highlight_numbers=1 |
|---|
| 1050 | \ | let python_highlight_builtins=1 |
|---|
| 1051 | \ | let python_highlight_space_errors=1 |
|---|
| 1052 | |
|---|
| 1053 | |
|---|
| 1054 | |
|---|
| 1055 | |
|---|
| 1056 | " sh "{{{2 |
|---|
| 1057 | |
|---|
| 1058 | autocmd MyAutoCmd FileType sh |
|---|
| 1059 | \ call <SID>SetShortIndent() |
|---|
| 1060 | |
|---|
| 1061 | " FIXME: use $SHELL. |
|---|
| 1062 | let g:is_bash = 1 |
|---|
| 1063 | |
|---|
| 1064 | |
|---|
| 1065 | |
|---|
| 1066 | |
|---|
| 1067 | " tex "{{{2 |
|---|
| 1068 | |
|---|
| 1069 | autocmd MyAutoCmd FileType tex |
|---|
| 1070 | \ call <SID>SetShortIndent() |
|---|
| 1071 | |
|---|
| 1072 | |
|---|
| 1073 | |
|---|
| 1074 | |
|---|
| 1075 | " vim "{{{2 |
|---|
| 1076 | |
|---|
| 1077 | autocmd MyAutoCmd FileType vim |
|---|
| 1078 | \ call <SID>FileType_vim() |
|---|
| 1079 | |
|---|
| 1080 | function! s:FileType_vim() |
|---|
| 1081 | call <SID>SetShortIndent() |
|---|
| 1082 | let vim_indent_cont = &shiftwidth |
|---|
| 1083 | endfunction |
|---|
| 1084 | |
|---|
| 1085 | |
|---|
| 1086 | |
|---|
| 1087 | |
|---|
| 1088 | " XML/SGML and other applications "{{{2 |
|---|
| 1089 | |
|---|
| 1090 | autocmd MyAutoCmd FileType html,xhtml,xml,xslt |
|---|
| 1091 | \ call <SID>FileType_xml() |
|---|
| 1092 | |
|---|
| 1093 | function! s:FileType_xml() |
|---|
| 1094 | call <SID>SetShortIndent() |
|---|
| 1095 | |
|---|
| 1096 | " To deal with namespace prefixes and tag-name-including-hyphens. |
|---|
| 1097 | setlocal iskeyword+=45 " hyphen (-) |
|---|
| 1098 | setlocal iskeyword+=58 " colon (:) |
|---|
| 1099 | |
|---|
| 1100 | " Support to input some parts of tags. |
|---|
| 1101 | inoremap <buffer> <LT>? </ |
|---|
| 1102 | imap <buffer> ?<LT> <LT>? |
|---|
| 1103 | inoremap <buffer> ?> /> |
|---|
| 1104 | imap <buffer> >? ?> |
|---|
| 1105 | |
|---|
| 1106 | " Support to input some blocks. |
|---|
| 1107 | inoremap <buffer> <LT>!C <LT>![CDATA[]]><Left><Left><Left> |
|---|
| 1108 | inoremap <buffer> <LT># <LT>!----><Left><Left><Left><C-r>= |
|---|
| 1109 | \ <SID>FileType_xml_comment_dispatch() |
|---|
| 1110 | \ <Return> |
|---|
| 1111 | |
|---|
| 1112 | " Complete proper end-tags. |
|---|
| 1113 | " In the following description, {|} means the cursor position. |
|---|
| 1114 | |
|---|
| 1115 | " Insert the end tag after the cursor. |
|---|
| 1116 | " Before: <code{|} |
|---|
| 1117 | " After: <code>{|}</code> |
|---|
| 1118 | inoremap <buffer> <LT><LT> ><LT>/<C-x><C-o><C-r>= |
|---|
| 1119 | \ <SID>KeysToStopInsertModeCompletion() |
|---|
| 1120 | \ <Return><C-o>F<LT> |
|---|
| 1121 | |
|---|
| 1122 | " Wrap the cursor with the tag. |
|---|
| 1123 | " Before: <code{|} |
|---|
| 1124 | " After: <code> |
|---|
| 1125 | " {|} |
|---|
| 1126 | " </code> |
|---|
| 1127 | inoremap <buffer> >> ><Return>X<Return><LT>/<C-x><C-o><C-r>= |
|---|
| 1128 | \ <SID>KeysToStopInsertModeCompletion() |
|---|
| 1129 | \ <Return><C-o><Up><BS> |
|---|
| 1130 | endfunction |
|---|
| 1131 | |
|---|
| 1132 | |
|---|
| 1133 | function! s:FileType_xml_comment_dispatch() |
|---|
| 1134 | let c = nr2char(getchar()) |
|---|
| 1135 | return get(s:FileType_xml_comment_data, c, c) |
|---|
| 1136 | endfunction |
|---|
| 1137 | let s:FileType_xml_comment_data = { |
|---|
| 1138 | \ "\<Space>": "\<Space>\<Space>\<Left>", |
|---|
| 1139 | \ "\<Return>": "\<Return>X\<Return>\<Up>\<End>\<BS>", |
|---|
| 1140 | \ '_': '', |
|---|
| 1141 | \ '-': '', |
|---|
| 1142 | \ '{': '{{'. "{\<Esc>", |
|---|
| 1143 | \ '}': '}}'. "}\<Esc>", |
|---|
| 1144 | \ '1': '{{'."{1\<Esc>", |
|---|
| 1145 | \ '2': '{{'."{2\<Esc>", |
|---|
| 1146 | \ '3': '{{'."{3\<Esc>", |
|---|
| 1147 | \ '4': '{{'."{4\<Esc>", |
|---|
| 1148 | \ '5': '{{'."{5\<Esc>", |
|---|
| 1149 | \ '6': '{{'."{6\<Esc>", |
|---|
| 1150 | \ '7': '{{'."{7\<Esc>", |
|---|
| 1151 | \ '8': '{{'."{8\<Esc>", |
|---|
| 1152 | \ '9': '{{'."{9\<Esc>", |
|---|
| 1153 | \ '!': '{{'."{1\<Esc>", |
|---|
| 1154 | \ '@': '{{'."{2\<Esc>", |
|---|
| 1155 | \ '#': '{{'."{3\<Esc>", |
|---|
| 1156 | \ '$': '{{'."{4\<Esc>", |
|---|
| 1157 | \ '%': '{{'."{5\<Esc>", |
|---|
| 1158 | \ '^': '{{'."{6\<Esc>", |
|---|
| 1159 | \ '&': '{{'."{7\<Esc>", |
|---|
| 1160 | \ '*': '{{'."{8\<Esc>", |
|---|
| 1161 | \ '(': '{{'."{9\<Esc>", |
|---|
| 1162 | \ } |
|---|
| 1163 | |
|---|
| 1164 | |
|---|
| 1165 | |
|---|
| 1166 | |
|---|
| 1167 | |
|---|
| 1168 | |
|---|
| 1169 | |
|---|
| 1170 | |
|---|
| 1171 | " Plugins "{{{1 |
|---|
| 1172 | " buffuzzy "{{{2 |
|---|
| 1173 | |
|---|
| 1174 | nmap <Leader>b <Plug>Buffuzzy |
|---|
| 1175 | |
|---|
| 1176 | " retained for the backward compatibility, |
|---|
| 1177 | " but this should be prefixed by <Leader>. |
|---|
| 1178 | nmap [Space]b <Plug>Buffuzzy |
|---|
| 1179 | |
|---|
| 1180 | |
|---|
| 1181 | |
|---|
| 1182 | |
|---|
| 1183 | " cygclip "{{{2 |
|---|
| 1184 | |
|---|
| 1185 | " Because plugins will be loaded after ~/.vimrc. |
|---|
| 1186 | autocmd MyAutoCmd User DelayedSettings |
|---|
| 1187 | \ if exists('g:loaded_cygclip') |
|---|
| 1188 | \ | call Cygclip_DefaultKeymappings() |
|---|
| 1189 | \ | endif |
|---|
| 1190 | |
|---|
| 1191 | |
|---|
| 1192 | |
|---|
| 1193 | |
|---|
| 1194 | " scratch "{{{2 |
|---|
| 1195 | |
|---|
| 1196 | " I already use <C-m> for tag jumping. |
|---|
| 1197 | " But I don't use it in the scratch buffer, so it should be overridden. |
|---|
| 1198 | augroup Scratch |
|---|
| 1199 | au! |
|---|
| 1200 | au User Initialize nmap <buffer> <C-m> <Plug>Scratch_ExecuteLine |
|---|
| 1201 | au User Initialize vmap <buffer> <C-m> <Plug>Scratch_ExecuteSelection |
|---|
| 1202 | augroup END |
|---|
| 1203 | |
|---|
| 1204 | |
|---|
| 1205 | |
|---|
| 1206 | |
|---|
| 1207 | " surround "{{{2 |
|---|
| 1208 | |
|---|
| 1209 | " The default mapping ys for <Plug>Ysurround is not consistent with |
|---|
| 1210 | " the default mappings of vi -- y is for yank. |
|---|
| 1211 | nmap s <Plug>Ysurround |
|---|
| 1212 | nmap ss <Plug>Yssurround |
|---|
| 1213 | |
|---|
| 1214 | autocmd MyAutoCmd User DelayedSettings |
|---|
| 1215 | \ if exists('g:loaded_surround') || exists('*SurroundRegister') |
|---|
| 1216 | \ | call SurroundRegister('g', 'js', "「\r」") |
|---|
| 1217 | \ | call SurroundRegister('g', 'jd', "『\r』") |
|---|
| 1218 | \ | endif |
|---|
| 1219 | |
|---|
| 1220 | |
|---|
| 1221 | |
|---|
| 1222 | |
|---|
| 1223 | " todatetime "{{{2 |
|---|
| 1224 | |
|---|
| 1225 | autocmd MyAutoCmd User DelayedSettings |
|---|
| 1226 | \ if exists('g:loaded_todatetime') |
|---|
| 1227 | \ | call TODateTime_DefaultKeymappings(1) |
|---|
| 1228 | \ | endif |
|---|
| 1229 | |
|---|
| 1230 | |
|---|
| 1231 | |
|---|
| 1232 | |
|---|
| 1233 | " vcscommand "{{{2 |
|---|
| 1234 | |
|---|
| 1235 | let g:VCSCommandDeleteOnHide = 1 |
|---|
| 1236 | |
|---|
| 1237 | nmap <Leader>cR <Plug>VCSDelete |
|---|
| 1238 | |
|---|
| 1239 | |
|---|
| 1240 | |
|---|
| 1241 | |
|---|
| 1242 | " xml_autons "{{{2 |
|---|
| 1243 | |
|---|
| 1244 | let g:AutoXMLns_Dict = {} |
|---|
| 1245 | let g:AutoXMLns_Dict['http://www.w3.org/2000/svg'] = 'svg11' |
|---|
| 1246 | |
|---|
| 1247 | |
|---|
| 1248 | |
|---|
| 1249 | |
|---|
| 1250 | |
|---|
| 1251 | |
|---|
| 1252 | |
|---|
| 1253 | |
|---|
| 1254 | " Fin. "{{{1 |
|---|
| 1255 | |
|---|
| 1256 | if !exists('s:loaded_my_vimrc') |
|---|
| 1257 | let s:loaded_my_vimrc = 1 |
|---|
| 1258 | autocmd MyAutoCmd VimEnter * |
|---|
| 1259 | \ doautocmd MyAutoCmd User DelayedSettings |
|---|
| 1260 | else |
|---|
| 1261 | doautocmd MyAutoCmd User DelayedSettings |
|---|
| 1262 | endif |
|---|
| 1263 | |
|---|
| 1264 | |
|---|
| 1265 | |
|---|
| 1266 | |
|---|
| 1267 | set secure " must be written at the last. see :help 'secure'. |
|---|
| 1268 | |
|---|
| 1269 | |
|---|
| 1270 | |
|---|
| 1271 | |
|---|
| 1272 | |
|---|
| 1273 | |
|---|
| 1274 | |
|---|
| 1275 | |
|---|
| 1276 | " __END__ "{{{1 |
|---|
| 1277 | " vim: fileencoding=utf-8 bomb |
|---|
| 1278 | " vim: expandtab softtabstop=2 shiftwidth=2 |
|---|
| 1279 | " vim: foldmethod=marker |
|---|