sorah's vimrc

raw delete

Vim muscle: 466 - Beginner

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
" sorah's vimrc
" Licence: MIT Licence
"   The MIT Licence {{{
"     Permission is hereby granted, free of charge, to any person obtaining a copy
"     of this software and associated documentation files (the "Software"), to deal
"     in the Software without restriction, including without limitation the rights
"     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
"     copies of the Software, and to permit persons to whom the Software is
"     furnished to do so, subject to the following conditions:
"     The above copyright notice and this permission notice shall be included in
"     all copies or substantial portions of the Software.
"     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
"     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
"     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
"     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
"     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
"     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
"     THE SOFTWARE.
"   }}}

" Basic {{{

"set no compatible
set nocompatible

"reset
set runtimepath&

"Absorb vimrc/.vim different OSs {{{
if has('win32') || has ('win64')
    set shellslash
    let $VIMFILES = $VIM."/vimfiles"
else
    let $VIMFILES = $HOME."/.vim"
endif
"}}}

"delete all autocmds {{{
autocmd!
"}}}

"view setting {{{
set number

"- -> >>- --->
set list
set listchars=tab:>-,trail:-,extends:>,precedes:<
" }}}

"encoding settings {{{
set enc=utf-8
set fencs=iso-2022-jp,euc-jp,cp932
set ambiwidth=double
set fileformats=unix,dos,mac 

if !has('gui_running') && (&term == 'win32' || &term == 'win64')
    set termencoding=cp932
endif
"}}}

"path setting {{{
if !exists("s:complete_addpath_vimrc") && (&term != 'win32' || &term != 'win64') && has('gui_running')
    let $PATH=$HOME."/local/bin:".$PATH
    let $RUBYLIB=system("ruby -e 'puts Dir[File.expand_path(\"~/git/ruby/*/lib\")].join(\":\")'")
    let s:complete_addpath_vimrc=1
endif
"}}}

"search settings {{{
set ignorecase
set smartcase
set wrapscan
set incsearch
set hlsearch
hi Search term=reverse ctermbg=LightBlue ctermfg=NONE
"}}}

"indent settings {{{
set autoindent
set cindent
set tabstop=2
set shiftwidth=2
set smarttab
set expandtab
"}}}

"show other file don't save. {{{
set hidden
"}}}

"command-line settings {{{
set showcmd
set cmdheight=2
set laststatus=2
"set statusline=%<%f\ %m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}
set statusline=%<%f\ %m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%{getcwd()}\ [%l,%c]\ %p%%
"}}}

"split {{{
set splitbelow
set splitright
"}}}

"command Tab complement settings {{{
set wildmenu
set wildmode=list:longest
"}}}

"Japanese input etc settings {{{
set noimdisable
set noimcmdline
set iminsert=1
set imsearch=1
"}}}

" Other {{{
set noruler
set nolist
set showmatch
set wrap
set title
set backspace=2
set scrolloff=5
set formatoptions& formatoptions+=mM
set tw=0
let format_join_spaces = 4
let format_allow_over_tw = 1
set nobackup
set history=1000
set mouse=a
set noautochdir
"}}}

"enable filetype plugins {{{
filetype plugin on
filetype plugin indent on
"}}}

"turn on the syntax-highlight {{{
syntax on
" }}}

" search {{{
nmap n nzz
nmap N Nzz
nmap * *zz
nmap # #zz
nmap g* g*zz
nmap g# g#zz
" }}}

"pumheight {{{
set pumheight=6
"}}}

"clipboard {{{
set clipboard=unnamed
"}}}

"printing settings {{{
set printoptions=wrap:y,number:y,header:0
set printfont=Andale\ Mono:h12:cUTF8
"}}}

"fold settings {{{
set foldenable
set foldmethod=marker
set foldcolumn=3
"}}}

"help settings {{{
set helplang=ja
"}}}

lang en_US.UTF-8

"color settings {{{
set t_Co=256
"}}}

"mouse setting {{{
if !has('gui_running')
    set mouse=a
    if exists('$WINDOW')
        set ttymouse=xterm2
    endif
endif
"}}}

"gui {{{
if has('gui_running')
  if has('mac')
    set guifont=Andale\ Mono:h14
    set guifontwide=Menlo:h14
    set columns=131
    set lines=42
    set transparency=15
  endif
  set guioptions-=T
endif
"}}}

" swap is in ~/tmp {{{
set directory-=.
"}}}

" }}}

" autocmd {{{
"Rails etc autocmd {{{
augroup Rails_etc
  autocmd!
  autocmd BufNewFile,BufRead app/*/*.rhtml set ft=mason fenc=utf-8
  autocmd BufNewFile,BufRead app/**/*.rb set ft=ruby fenc=utf-8
  autocmd BufNewFile,BufRead app/**/*.yml set ft=ruby fenc=utf-8
augroup END
"}}}

"input </ to auto close tag on XML {{{
augroup MyXML
  autocmd!
  autocmd Filetype xml inoremap <buffer> </ </<C-x><C-o>
  autocmd Filetype html inoremap <buffer> </ </<C-x><C-o>
  "autocmd Filetype eruby inoremap <buffer> </ </<C-x><C-o>
augroup END
"}}}

"vimrc auto update {{{
augroup MyAutoCmd
  autocmd!
  autocmd BufWritePost .vimrc nested source $MYVIMRC
  autocmd BufWritePost .vimrc RcbVimrc
augroup END
"}}}

"crontab for Vim {{{
augroup CrontabForVim
  autocmd BufReadPre crontab.* setl nowritebackup
augroup END
"}}}
"}}}

"vim muscle scouter
"http://d.hatena.ne.jp/thinca/20091031/1257001194
function! Scouter(file, ...)
  let pat = '^\s*$\|^\s*"'
  let lines = readfile(a:file)
  if !a:0 || !a:1
    let lines = split(substitute(join(lines, "\n"), '\n\s*\\', '', 'g'), "\n")
  endif
  return len(filter(lines,'v:val !~ pat'))
endfunction
command! -bar -bang -nargs=? -complete=file Scouter
\        echo Scouter(empty(<q-args>) ? $MYVIMRC : expand(<q-args>), <bang>0)


"hatena.vim settings
set runtimepath+=$VIMFILES/hatena

"neocomplcache settings
let g:neocomplcache_enable_quick_match = 0
let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_underbar_completion = 1
let g:NeoComplCache_enable_info = 1
let g:neocomplcache_enable_smart_case = 1
let g:neocomplcache_manual_completion_start_length = 2
let g:neocomplcache_enable_at_startup = 1 
nnoremap <silent> <C-s> :NeoComplCacheToggle<Return>
nnoremap <silent> <C-d> :NeoComplCacheDisable<Return>

if !exists('g:neocomplcache_include_paths')
    let g:neocomplcache_include_paths = {}
endif
if has('mac')
    let g:neocomplcache_include_paths['ruby'] = ".,".$HOME."/local/lib/ruby/**,".$HOME."/rubies/trunk/lib/ruby/**"
endif

"push C-a to toggle spell check
nnoremap <silent> <C-a> :setl spell!<Return>

"move to line head
nnoremap ~ <Home>
vnoremap ~ <Home>

"key-mapping for edit vimrc
nnoremap <silent> <Space>ev  :<C-u>tabedit $MYVIMRC<CR>
nnoremap <silent> <Space>ee  :<C-u>edit $MYVIMRC<CR>
nnoremap <silent> <Space>eg  :<C-u>edit $MYGVIMRC<CR>
nnoremap <silent> <Space>ea  :source $MYVIMRC<Return>

"key-mapping for shift-n
nnoremap m N

"markdown.vim setting
if filereadable("/Users/sorah/local/bin/markdown.pl")
    let g:markdownPathToMarkdown = "/Users/sorah/local/bin/markdown.pl"
endif

nnoremap <C-h> :<C-u>vertical help<Space>

"replace shortcut
nnoremap // :<C-u>%s/
vnoremap // :s/

"quickrun.vim settings
if !exists('g:quickrun_config')
  let g:quickrun_config = {'*': { 'split': 'vertical rightbelow', 'runmode': 'async:remote:vimproc'}}
  let g:quickrun_config.markdown = {'exec' : 'function __mkd__() { markdown.pl $1 > /tmp/__markdown.html && open /tmp/__markdown.html } && __mkd__'}
  let g:quickrun_config.markdown = {'exec' : ['pandoc -f markdown -t html -o /tmp/markdown.html %s', 'open /tmp/markdown.html']}
  let g:quickrun_config.actionscript = {'exec' : ['mxmlc -output /tmp/__as.swf -default-background-color 0xFFFFFF %s', 'open /tmp/__as.swf']}
  let g:quickrun_default_config.coffee = {'command': 'coffee'}
endif

"split shortcut
nnoremap <silent> <C-w><C-w>l:call <SID>Goodwidth()<Cr>
nnoremap <silent> <C-w><C-w>h:call <SID>Goodwidth()<Cr>

nnoremap sl <C-w>l:call <SID>Goodwidth()<Cr>
nnoremap sh <C-w>h:call <SID>Goodwidth()<Cr>
nnoremap sj <C-w>j:call <SID>Goodwidth()<Cr>
nnoremap sk <C-w>k:call <SID>Goodwidth()<Cr>
nnoremap sL <C-w>L
nnoremap sH <C-w>H
nnoremap sJ <C-w>J
nnoremap sK <C-w>K

"auto adjust a split window width
"http://vim-users.jp/2009/07/hack42/
function! s:Goodwidth()
  if winwidth(0) < 84
    vertical resize 90
  endif
endfunction


"tab shortcut
nnoremap <silent> tn :tabn<Cr>
nnoremap <silent> tp :tabp<Cr>
nnoremap <silent> tb :tabp<Cr>
nnoremap <silent> te :tabe<Cr>

"colorscheme
colorscheme mrkn256


"align.vim
let g:Align_xstrlen=3

"th :tabe ~/
nnoremap th :tabe ~/
nnoremap ts :tabe ~/sandbox/
nnoremap m  :tabe ~/sandbox/
nnoremap tr :tabe ~/sandbox/ruby/
nnoremap tt :tabe ~/git/ruby/termtter/
nnoremap tg :tabe ~/git
nnoremap eh :e ~/
nnoremap es :e ~/sandbox/
nnoremap er :e ~/sandbox/ruby/
nnoremap et :e ~/git/ruby/termtter/
nnoremap eg :e ~/git

"q -> C-o
nnoremap q <C-o>

"super jump
nnoremap H 5h
nnoremap L 5l
nnoremap J <C-f>
nnoremap K <C-b>

"C-r U"
nnoremap U <C-r>

", <$
nnoremap , <$
nnoremap . >$

"; dd
nnoremap ; dd

"- gg=G
nnoremap - gg=G
vnoremap - =

"rb
if has('mac')
  if !exists('g:rb_vimrc_done')
    let $PATH=$HOME."/rubies/bin:".$PATH
  endif
  let g:rb_vimrc_done=1
endif

"vimproc
if has('mac')
  let g:vimproc_dll_path=$VIMFILES."/autoload/proc.osx.so"
endif

" Disable bell.
set visualbell
set vb t_vb=

"vimshell
let g:vimshell_execute_file_list = {}
if has('win32') || has('win64')
  " Display user name on Windows.
  let g:vimshell_prompt = $USERNAME."@".hostname()."% "
elseif has('mac') || has('unix')
  " Display user name on Linux.
  let g:vimshell_prompt = $USER.'@'.hostname()."% "
  let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")'
  call vimshell#set_execute_file('bmp,jpg,png,gif,mp3,m4a,ogg', 'open')
  let g:vimshell_execute_file_list['zip'] = 'zipinfo'
  call vimshell#set_execute_file('tgz,gz', 'gzcat')
  call vimshell#set_execute_file('tbz,bz2', 'bzcat')
endif



" Initialize execute file list.
call vimshell#set_execute_file('txt,vim,c,h,cpp,d,xml,java', 'vim')
let g:vimshell_execute_file_list['rb'] = 'ruby'
let g:vimshell_execute_file_list['pl'] = 'perl'
let g:vimshell_execute_file_list['py'] = 'python'
if has('win32') || has('win64')
  call vimshell#set_execute_file('html,xhtml', 'start')
elseif has('mac')
  call vimshell#set_execute_file('html,xhtml', 'open')
else
  call vimshell#set_execute_file('html,xhtml', 'firefox')
end

let g:VimShell_enable_interactive = 1
let g:VimShell_enable_smart_case = 1

":cdd => :Cdd
cabbrev cdd Cdd

"Setf
nnoremap <C-s> :<C-u>setf 

"mv editing file
function! g:MvEditingFile(new_file_name)
  call system("mv".expand('%')." ".a:new_file_name)
  e a:new_file_name
endfunction
command! -nargs=1 Rename call g:MvEditingFile(<f-args>)

"chdir to now dir
"http://vim-users.jp/2009/09/hack69/
command! -nargs=? -complete=dir -bang CD  call s:ChangeCurrentDir('<args>', '<bang>') 

function! s:ChangeCurrentDir(directory, bang)
    if a:directory == ''
        lcd %:p:h
    else
        execute 'lcd' . a:directory
    endif

    if a:bang == ''
        pwd
    endif
endfunction

nnoremap <silent> <Space>cd :<C-u>CD!<CR>

"rsense
"http://vinarian.blogspot.com/2010/03/rsenseneocomplcache.html
let g:rsenseHome = $HOME.'/local/opt/rsense'
let g:rsenseUseOmniFunc = 1

"snip
imap <silent><C-a> <Plug>(neocomplcache_snippets_expand)

"gist.vim
if has('mac')
  let g:gist_clip_command = 'pbcopy'
endif

"compl
inoremap <expr> ] searchpair('\[', '', '\]', 'nbW', 'synIDattr(synID(line("."), col("."), 1), "name") =~? "String"') ? ']' : "\<C-n>"

"vimfiler
let g:vimfiler_execute_file_list = {}
let g:vimfiler_execute_file_list['rb'] = 'ruby'
let g:vimfiler_execute_file_list['pl'] = 'perl'
let g:vimfiler_execute_file_list['py'] = 'python'
let g:vimfiler_edit_command = 'tabe'
let g:vimfiler_split_command = ''
if has('mac')
  let g:vimfiler_execute_file_list['html'] = 'open'
  let g:vimfiler_execute_file_list['htm'] = 'open'
  let g:vimfiler_execute_file_list['xhtml'] = 'open'
elseif has('win32') || has('win64')
  let g:vimfiler_execute_file_list['html'] = 'open'
  let g:vimfiler_execute_file_list['htm'] = 'open'
  let g:vimfiler_execute_file_list['xhtml'] = 'open'
endif


"ew
function! g:VimRcWriteEdit()
  write
  edit
endfunction
command! WriteEdit call g:VimRcWriteEdit()
cabbrev we WriteEdit

"open
function! g:CallOpenCmd(...)
  if a:0 > 0
    if has('mac')
      call system("open ".shellescape(a:1))
    else
      call system("gnome-open ".shellescape(a:1))
    endif
  else
    if has('mac')
      call system("open ".shellescape(expand('%:p')))
    else
      call system("gnome-open ".shellescape(expand('%:p')))
    endif
  endif
endfunction
command! -nargs=? -complete=file Open call g:CallOpenCmd('<args>')

"few
function! g:Few(...)
  if a:0 > 0
    call system("few ".shellescape(expand(a:1)))
  else
    echomsg "hi"
    call system("few ".shellescape(expand('%:p')))
  endif
endfunction
command! -nargs=? -complete=file Few call g:Few('<args>')

"notes
let g:notes_dir_path=expand("~")."/sandbox/document/notes"
function! g:OpenNotes(fn)
   execute ":tabe ".expand(g:notes_dir_path."/".a:fn.".mkd")
endfunction
function! OpenNoteHkn(a,b,c)
  return substitute(system("ls -1 ". shellescape(g:notes_dir_path)), ".mkd", "", "g")
endfunction
command! -nargs=1 -complete=custom,OpenNoteHkn Note call g:OpenNotes(<q-args>)
nnoremap <C-e> :<C-u>Note 

"eskk
if has('mac')
  let g:eskk_dictionary = "~/Documents/SKK-JISYO.M"
endif



"read other vimrc files
if filereadable($VIMFILES."/other/private.vim")
    source $VIMFILES/other/private.vim
endif

" ('.v.')

vimrcbox © Shota Fukumori (sora_h) - Top How to use Ranking