root/dotfiles/vim/kana/dot.vimrc @ 517

Revision 517, 29.0 kB (checked in by kana, 6 years ago)

dotfiles/vim/kana:
* Sync with my local repository.

  • Property svn:keywords set to Id
Line 
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
65set nocompatible  " to use many extensions of Vim.
66
67
68
69
70" Encoding  "{{{2
71
72" To deal with Japanese language.
73if $ENV_WORKING ==# 'colinux'
74  set encoding=utf-8
75else
76  set encoding=japan
77endif
78if !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
114endif
115
116
117if $ENV_ACCESS ==# 'cygwin'
118  set termencoding=cp932
119elseif $ENV_ACCESS ==# 'linux'
120  set termencoding=euc-jp
121else  " 'colinux'
122  set termencoding=utf-8
123endif
124
125
126
127
128" Options  "{{{2
129
130if 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
137endif
138
139filetype plugin indent on
140
141
142set ambiwidth=double
143set autoindent
144set backspace=indent,eol,start
145set backup
146set backupcopy&
147set backupdir=.,~/tmp
148set backupskip&
149set backupskip+=svn-commit.tmp,svn-commit.[0-9]*.tmp
150set cinoptions=:0,t0,(0,W1s
151set directory=.,~/tmp
152set noequalalways
153set formatoptions=tcroqnlM1
154set history=100
155set hlsearch
156set grepprg=internal
157set incsearch
158set mouse=
159set ruler
160set showcmd
161set showmode
162set smartindent
163set updatetime=60000
164set title
165set titlestring=Vim:\ %f\ %h%r%m
166set wildmenu
167
168set 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
177let mapleader=','
178let maplocalleader='.'
179
180
181" Use this group for any autocmd defined in this file.
182augroup MyAutoCmd
183  autocmd!
184augroup END
185
186
187
188
189
190
191
192
193" Utilities  "{{{1
194" CMapABC: support input for Alternate Built-in Commands "{{{2
195
196let s:CMapABC_Entries = []
197function! s:CMapABC_Add(original_pattern, alternate_name)
198  call add(s:CMapABC_Entries, [a:original_pattern, a:alternate_name])
199endfunction
200
201
202cnoremap <expr> <Space>  <SID>CMapABC()
203function! 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 ' '
211endfunction
212
213
214
215
216" Alternate :cd which uses 'cdpath' for completion  "{{{2
217
218command! -complete=customlist,<SID>CommandComplete_cdpath -nargs=1
219       \ CD  cd <args>
220
221function! s:CommandComplete_cdpath(arglead, cmdline, cursorpos)
222  return split(globpath(&cdpath, a:arglead . '*/'), "\n")
223endfunction
224
225call s:CMapABC_Add('^cd', 'CD')
226
227
228
229
230" Help-related stuffs  "{{{2
231
232function! 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]
242endfunction
243
244function! 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
260endfunction
261
262
263
264
265" High-level key sequences  "{{{2
266
267function! 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
275endfunction
276
277function! s:KeysToStopInsertModeCompletion()
278  if pumvisible()
279    return "\<C-y>"
280  else
281    return "\<Space>\<BS>"
282  endif
283endfunction
284
285
286function! s:KeysToEscapeCommandlineModeIfEmpty(key)
287  if getcmdline() == ''
288    return "\<Esc>"
289  else
290    return a:key
291  end
292endfunction
293
294
295function! s:KeysToInsertOneCharacter()
296  echohl ModeMsg
297  echo '-- INSERT (one char) --'
298  return nr2char(getchar()) . "\<Esc>"
299endfunction
300
301
302
303
304" :edit with specified 'fileencoding'.  "{{{2
305
306com! -nargs=? -complete=file -bang -bar Cp932  edit<bang> ++enc=cp932 <args>
307com! -nargs=? -complete=file -bang -bar Eucjp  edit<bang> ++enc=euc-jp <args>
308com! -nargs=? -complete=file -bang -bar Iso2022jp  Jis<bang> <args>
309com! -nargs=? -complete=file -bang -bar Jis edit<bang> ++enc=iso-2022-jp <args>
310com! -nargs=? -complete=file -bang -bar Sjis  Cp932<bang> <args>
311com! -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'.
319function! 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
340endfunction
341
342
343" for visual mode.  a:motion is '[[', '[]', ']]' or ']['.
344function! 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)
352endfunction
353
354
355" for operator-pending mode.  a:motion is '[[', '[]', ']]' or ']['.
356function! s:JumpSectionO(motion)
357  execute 'normal' v:count1 . a:motion
358endfunction
359
360
361
362
363" Misc.  "{{{2
364
365function! 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
373endfunction
374
375function! s:ToggleOption(option_name)
376  execute 'setlocal' a:option_name.'!'
377  execute 'setlocal' a:option_name.'?'
378endfunction
379
380
381function! 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
401endfunction
402
403
404function! 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`
415endfunction
416
417
418function! 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)
422endfunction
423
424function! 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
446endfunction
447
448
449function! 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
455endfunction
456
457command! -nargs=* -complete=expression -range -count=0 Execute
458       \ call s:Execute(<f-args>)
459function! 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)
468endfunction
469
470
471" like join (J), but move the next line into the cursor position.
472function! 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)
493endfunction
494
495
496function! 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
510endfunction
511
512
513function! 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
523endfunction
524
525function! s:BoringBufferP(bid)  " is the buffer unnamed and not editted?
526  return bufname(a:bid) == '' && getbufvar(a:bid, '&modified') == 0
527endfunction
528
529
530function! s:SetShortIndent()
531  setlocal expandtab softtabstop=2 shiftwidth=2
532endfunction
533
534
535" Are the windows :split'ed and :vsplit'ed?
536function! 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)
570endfunction
571
572
573function! 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
581endfunction
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.
598noremap  t  <Nop>
599noremap  T  <Nop>
600
601" Alternatives for the original actions.
602noremap  [Space]t  t
603noremap  [Space]T  T
604
605
606" Basic  "{{{3
607
608nmap     t<Space>  tt
609vmap     t<Space>  tt
610nnoremap tt  <C-]>
611vnoremap tt  <C-]>
612nnoremap tj  :tag<Return>
613nnoremap tk  :pop<Return>
614nnoremap tl  :tags<Return>
615nnoremap tn  :tnext<Return>
616nnoremap tp  :tprevious<Return>
617nnoremap tP  :tfirst<Return>
618nnoremap tN  :tlast<Return>
619
620" additionals, like Web browsers
621nmap     <C-m>  tt
622vmap     <C-m>  tt
623
624
625" With the preview window  "{{{3
626
627nmap     t'<Space>  t't
628vmap     t'<Space>  t't
629nnoremap t't  <C-w>}
630vnoremap t't  <C-w>}
631nnoremap t'n  :ptnext<Return>
632nnoremap t'p  :ptpevious<Return>
633nnoremap t'P  :ptfirst<Return>
634nnoremap t'N  :ptlast<Return>
635
636" although :pclose is not related to tag.
637nnoremap t'c  :pclose<Return>
638
639
640" With :split  "{{{3
641
642nnoremap tst  <C-w>]
643vnoremap tst  <C-w>]
644nmap     ts<Space>  tst
645vmap     ts<Space>  tst
646nnoremap tsn  :split \| tnext<Return>
647nnoremap tsp  :split \| tpevious<Return>
648nnoremap tsP  :split \| tfirst<Return>
649nnoremap 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>]|.
656nnoremap tvt  <C-]>:vsplit<Return><C-w>p<C-t><C-w>p
657vnoremap tvt  <C-]>:vsplit<Return><C-w>p<C-t><C-w>p
658nmap     tv<Space>  tvt
659vmap     tv<Space>  tvt
660nnoremap tvn  :vsplit \| tnext<Return>
661nnoremap tvp  :vsplit \| tpevious<Return>
662nnoremap tvP  :vsplit \| tfirst<Return>
663nnoremap tvN  :vsplit \| tlast<Return>
664
665
666
667
668" Quickfix  "{{{2
669" Fallback  "{{{3
670
671" the prefix key.
672nnoremap q  <Nop>
673
674" alternative key for the original action.
675" -- Ex-mode will be never used and recordings are rarely used.
676nnoremap Q  q
677
678
679" For quickfix list  "{{{3
680
681nnoremap qj        :Execute cnext [count]<Return>
682nnoremap qk        :Execute cprevious [count]<Return>
683nnoremap qr        :Execute crewind [count]<Return>
684nnoremap qK        :Execute cfirst [count]<Return>
685nnoremap qJ        :Execute clast [count]<Return>
686nnoremap qfj       :Execute cnfile [count]<Return>
687nnoremap qfk       :Execute cpfile [count]<Return>
688nnoremap ql        :clist<Return>
689nnoremap qq        :Execute cc [count]<Return>
690nnoremap qo        :Execute copen [count]<Return>
691nnoremap qc        :cclose<Return>
692nnoremap qp        :Execute colder [count]<Return>
693nnoremap qn        :Execute cnewer [count]<Return>
694nnoremap qm        :make<Return>
695nnoremap qM        :make<Space>
696nnoremap q<Space>  :make<Space>
697nnoremap qg        :grep<Space>
698
699
700" For location list (mnemonic: Quickfix list for the current Window)  "{{{3
701
702nnoremap qwj        :Execute lnext [count]<Return>
703nnoremap qwk        :Execute lprevious [count]<Return>
704nnoremap qwr        :Execute lrewind [count]<Return>
705nnoremap qwK        :Execute lfirst [count]<Return>
706nnoremap qwJ        :Execute llast [count]<Return>
707nnoremap qwfj       :Execute lnfile [count]<Return>
708nnoremap qwfk       :Execute lpfile [count]<Return>
709nnoremap qwl        :llist<Return>
710nnoremap qwq        :Execute ll [count]<Return>
711nnoremap qwo        :Execute lopen [count]<Return>
712nnoremap qwc        :lclose<Return>
713nnoremap qwp        :Execute lolder [count]<Return>
714nnoremap qwn        :Execute lnewer [count]<Return>
715nnoremap qwm        :lmake<Return>
716nnoremap qwM        :lmake<Space>
717nnoremap qw<Space>  :lmake<Space>
718nnoremap 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>.
731nnoremap <C-t>  <Nop>
732
733
734" Basic  "{{{3
735
736nnoremap <C-t>n  :<C-u>tabnew<Return>
737nnoremap <C-t>c  :<C-u>tabclose<Return>
738nnoremap <C-t>o  :<C-u>tabonly<Return>
739nnoremap <C-t>i  :<C-u>tabs<Return>
740
741nmap <C-t><C-n>  <C-t>n
742nmap <C-t><C-c>  <C-t>c
743nmap <C-t><C-o>  <C-t>o
744nmap <C-t><C-i>  <C-t>i
745
746
747" Moving around tabs.  "{{{3
748
749nnoremap <C-t>j  :<C-u>execute 'tabnext'
750                 \ 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$')<Return>
751nnoremap <C-t>k  :Execute tabprevious [count]<Return>
752nnoremap <C-t>K  :<C-u>tabfirst<Return>
753nnoremap <C-t>J  :<C-u>tablast<Return>
754nmap <C-t>t  <C-t>j
755nmap <C-t>T  <C-t>k
756
757nmap <C-t><C-j>  <C-t>j
758nmap <C-t><C-k>  <C-t>k
759nmap <C-t><C-t>  <C-t>t
760
761
762" Moving tabs themselves.  "{{{3
763
764nnoremap <C-t>l  :<C-u>execute 'tabmove'
765                 \ min([tabpagenr() + v:count1 - 1, tabpagenr('$')])<Return>
766nnoremap <C-t>h  :<C-u>execute 'tabmove'
767                 \ max([tabpagenr() - v:count1 - 1, 0])<Return>
768nnoremap <C-t>L  :<C-u>tabmove<Return>
769nnoremap <C-t>H  :<C-u>tabmove 0<Return>
770
771nmap <C-t><C-l>  <C-t>l
772nmap <C-t><C-h>  <C-t>h
773
774
775
776
777" Command-line editting  "{{{2
778
779" pseudo vi-like keys
780cnoremap <Esc>h  <Left>
781cnoremap <Esc>j  <Down>
782cnoremap <Esc>k  <Up>
783cnoremap <Esc>l  <Right>
784cnoremap <Esc>H  <Home>
785cnoremap <Esc>L  <End>
786cnoremap <Esc>w  <S-Right>
787cnoremap <Esc>b  <S-Left>
788cnoremap <Esc>x  <Del>
789
790" escape Command-line mode if the command line is empty (like <C-h>)
791cnoremap <expr> <C-u>  <SID>KeysToEscapeCommandlineModeIfEmpty("\<C-u>")
792cnoremap <expr> <C-w>  <SID>KeysToEscapeCommandlineModeIfEmpty("\<C-w>")
793
794" Search slashes easily (too lazy to prefix backslashes to slashes)
795cnoremap <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
808inoremap <Leader>dF  <C-r>=strftime('%Y-%m-%dT%H:%M:%S+09:00')<Return>
809inoremap <Leader>df  <C-r>=strftime('%Y-%m-%dT%H:%M:%S')<Return>
810inoremap <Leader>dd  <C-r>=strftime('%Y-%m-%d')<Return>
811inoremap <Leader>dT  <C-r>=strftime('%H:%M:%S')<Return>
812inoremap <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
824vnoremap <silent> ]]  :<C-u>call <SID>JumpSectionV(']]')<Return>
825vnoremap <silent> ][  :<C-u>call <SID>JumpSectionV('][')<Return>
826vnoremap <silent> [[  :<C-u>call <SID>JumpSectionV('[[')<Return>
827vnoremap <silent> []  :<C-u>call <SID>JumpSectionV('[]')<Return>
828onoremap <silent> ]]  :<C-u>call <SID>JumpSectionO(']]')<Return>
829onoremap <silent> ][  :<C-u>call <SID>JumpSectionO('][')<Return>
830onoremap <silent> [[  :<C-u>call <SID>JumpSectionO('[[')<Return>
831onoremap <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.
841map      <Space>  [Space]
842
843" fallback
844noremap  [Space]  <Nop>
845
846
847nnoremap [Space]/  :nohlsearch<Return>
848
849nnoremap [Space]?  :call <SID>HelpWindowClose()<Return>
850
851  " append one character
852nnoremap [Space]A  A<C-r>=<SID>KeysToInsertOneCharacter()<Return>
853nnoremap [Space]a  a<C-r>=<SID>KeysToInsertOneCharacter()<Return>
854
855nnoremap [Space]e  :setlocal encoding? termencoding? fenc? fencs?<Return>
856nnoremap [Space]f  :setlocal filetype? fileencoding? fileformat?<Return>
857
858  " insert one character
859nnoremap [Space]I  I<C-r>=<SID>KeysToInsertOneCharacter()<Return>
860nnoremap [Space]i  i<C-r>=<SID>KeysToInsertOneCharacter()<Return>
861
862nnoremap [Space]J  :<C-u>call <SID>JoinHere(1)<Return>
863nnoremap [Space]gJ  :<C-u>call <SID>JoinHere(0)<Return>
864  " unjoin
865nnoremap [Space]j  i<Return><Esc>
866
867nnoremap [Space]ob  :call <SID>ToggleBell()<Return>
868nnoremap [Space]ow  :call <SID>ToggleOption('wrap')<Return>
869
870nnoremap [Space]q  :help quickref<Return>
871
872nnoremap [Space]r  :registers<Return>
873
874nnoremap [Space]s  <Nop>
875nnoremap [Space]s.  :source $HOME/.vimrc<Return>
876nnoremap [Space]ss  :source %<Return>
877
878vnoremap [Space]s  :sort<Return>
879
880  " for backward compatibility
881nmap     [Space]w  [Space]ow
882
883
884
885
886" Windows  "{{{2
887"
888" Synonyms for the default mappings, with single key strokes.
889
890nnoremap <Esc>h  <C-w>h
891nnoremap <Esc>j  <C-w>j
892nnoremap <Esc>k  <C-w>k
893nnoremap <Esc>l  <C-w>l
894
895nnoremap <Esc>H  :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('H')<Return>
896nnoremap <Esc>J  :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('J')<Return>
897nnoremap <Esc>K  :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('K')<Return>
898nnoremap <Esc>L  :<C-u>call <SID>MoveWindowThenEqualizeIfNecessary('L')<Return>
899
900nnoremap <C-i>  <C-w>w
901" <Tab> = <C-i>
902nnoremap <Esc>i  <C-w>W
903nmap <S-Tab>  <Esc>i
904
905
906
907
908" Misc.  "{{{2
909
910nnoremap <C-h>  :h<Space>
911nnoremap <C-o>  :e<Space>
912nnoremap <C-w>.  :e .<Return>
913nnoremap <silent> <Leader>cD  :<C-u>call <SID>SCCSDiffAll()<CR>
914
915
916" Jump list
917nnoremap <C-j>  <C-i>
918nnoremap <C-k>  <C-o>
919
920
921" Switch to the previously edited file (like Vz)
922nnoremap <Esc>2  :e #<Return>
923nmap <F2>  <Esc>2
924
925
926" Too lazy to press Shift key.
927noremap ;  :
928noremap :  ;
929
930
931" Disable some dangerous key.
932nnoremap ZZ  <Nop>
933nnoremap ZQ  <Nop>
934
935
936" Use a backslash (\) to repeat last change.
937" Since a dot (.) is used as <LocalLeader>.
938nnoremap \  .
939
940
941" Complete or indent.
942inoremap <expr> <C-i>  (<SID>ShouldIndentRatherThanCompleteP()
943                      \ ? '<C-i>'
944                      \ : <SID>KeysToComplete())
945
946function! s:ShouldIndentRatherThanCompleteP()
947  let m = match(getline('.'), '\S')
948  return m == -1 || col('.')-1 <= m
949endfunction
950
951
952" Swap ` and ' -- I prefer ` to ' and ` is not easy to type.
953noremap ' `
954noremap ` '
955
956
957" To be able to undo these types of deletion in Insert mode.
958inoremap <C-w>  <C-g>u<C-w>
959inoremap <C-u>  <C-g>u<C-u>
960
961
962" Search the word nearest to the cursor in new window.
963nnoremap <C-w>*  <C-w>s*
964nnoremap <C-w>#  <C-g>s#
965
966
967" Synonyms for <> and [], same as plugin surround.
968vnoremap aa  a>
969vnoremap ia  i>
970
971vnoremap ar  a]
972vnoremap ir  i]
973
974
975
976
977
978
979
980
981" Filetypes  "{{{1
982" All  "{{{2
983
984autocmd MyAutoCmd FileType *
985  \ call <SID>FileType_any()
986
987function! 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>  [[
998endfunction
999
1000
1001" although this is not a filetype settings.
1002autocmd 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', '')
1007doautocmd MyAutoCmd ColorScheme because-colorscheme-has-been-set-above.
1008
1009
1010
1011
1012" dosini (.ini)  "{{{2
1013
1014autocmd MyAutoCmd FileType dosini
1015  \ call <SID>FileType_dosini()
1016
1017function! 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>
1022endfunction
1023
1024
1025
1026
1027" lua  "{{{2
1028
1029autocmd MyAutoCmd FileType lua
1030  \ call <SID>SetShortIndent()
1031
1032
1033
1034
1035" netrw  "{{{2
1036"
1037" Consider these buffers have "another" filetype=netrw.
1038
1039autocmd MyAutoCmd BufReadPost {dav,file,ftp,http,rcp,rsync,scp,sftp}://*
1040  \ setlocal bufhidden=hide
1041
1042
1043
1044
1045" python  "{{{2
1046
1047autocmd 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
1058autocmd MyAutoCmd FileType sh
1059  \ call <SID>SetShortIndent()
1060
1061" FIXME: use $SHELL.
1062let g:is_bash = 1
1063
1064
1065
1066
1067" tex  "{{{2
1068
1069autocmd MyAutoCmd FileType tex
1070  \ call <SID>SetShortIndent()
1071
1072
1073
1074
1075" vim  "{{{2
1076
1077autocmd MyAutoCmd FileType vim
1078  \ call <SID>FileType_vim()
1079
1080function! s:FileType_vim()
1081  call <SID>SetShortIndent()
1082  let vim_indent_cont = &shiftwidth
1083endfunction
1084
1085
1086
1087
1088" XML/SGML and other applications  "{{{2
1089
1090autocmd MyAutoCmd FileType html,xhtml,xml,xslt
1091  \ call <SID>FileType_xml()
1092
1093function! 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>
1130endfunction
1131
1132
1133function! s:FileType_xml_comment_dispatch()
1134  let c = nr2char(getchar())
1135  return get(s:FileType_xml_comment_data, c, c)
1136endfunction
1137let 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
1174nmap <Leader>b  <Plug>Buffuzzy
1175
1176" retained for the backward compatibility,
1177" but this should be prefixed by <Leader>.
1178nmap [Space]b  <Plug>Buffuzzy
1179
1180
1181
1182
1183" cygclip  "{{{2
1184
1185" Because plugins will be loaded after ~/.vimrc.
1186autocmd 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.
1198augroup 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
1202augroup 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.
1211nmap s  <Plug>Ysurround
1212nmap ss  <Plug>Yssurround
1213
1214autocmd 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
1225autocmd MyAutoCmd User DelayedSettings
1226      \   if exists('g:loaded_todatetime')
1227      \ |   call TODateTime_DefaultKeymappings(1)
1228      \ | endif
1229
1230
1231
1232
1233" vcscommand  "{{{2
1234
1235let g:VCSCommandDeleteOnHide = 1
1236
1237nmap <Leader>cR  <Plug>VCSDelete
1238
1239
1240
1241
1242" xml_autons  "{{{2
1243
1244let g:AutoXMLns_Dict = {}
1245let g:AutoXMLns_Dict['http://www.w3.org/2000/svg'] = 'svg11'
1246
1247
1248
1249
1250
1251
1252
1253
1254" Fin.  "{{{1
1255
1256if !exists('s:loaded_my_vimrc')
1257  let s:loaded_my_vimrc = 1
1258  autocmd MyAutoCmd VimEnter *
1259    \ doautocmd MyAutoCmd User DelayedSettings
1260else
1261  doautocmd MyAutoCmd User DelayedSettings
1262endif
1263
1264
1265
1266
1267set 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
Note: See TracBrowser for help on using the browser.