viを使う 6

環境を新しく作成したとき、とりあえず使える.vimrcとして、今までの.vimrcをまとめます。
.vimrcの最後の方に記述しないと期待の動作にならないものもあります。ここでは、コピーしたらすぐに使えるものを掲載します。

.vimrc

.vimrc


" ------------------------------------------------------------------------------

"" sometime euc-jp setting is needed

" set enc=japan

set encoding=utf-8
" set encoding=euc-jp
" set encoding=sjis
" set encoding=iso-2022-jp

set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8
set fileformats=unix,dos,mac

" ------------------------------------------------------------------------------

"" show line number

set number

" ------------------------------------------------------------------------------

if &compatible | set nocompatible | endif

" ------------------------------------------------------------------------------

"" use space substitute for tab

set expandtab

"" tab width

set tabstop=4
set shiftwidth=4

" ------------------------------------------------------------------------------

"" reflesh screen while typing

set redraw

" ------------------------------------------------------------------------------

"" syntax highlighting

syntax on

" ------------------------------------------------------------------------------

"" highlight corsor line

set cursorline

" ------------------------------------------------------------------------------

"" always show status line

set laststatus=2

set showmode
set showcmd
set ruler

" ------------------------------------------------------------------------------

"" command completion

set wildmenu

set history=2048

" ------------------------------------------------------------------------------

"" highlight all search pattern matches

set hlsearch

"" incremental search

set incsearch

"" set ic!

set ignorecase
set smartcase

" ------------------------------------------------------------------------------

"" moving to matching braces

set showmatch
" set noshowmatch

"" N x 0.1 second

set matchtime=1

"" do not move cursor
"" variable loaded_matchparen = 1 -> avoid loading matchparen plugin

let loaded_matchparen=1

" ------------------------------------------------------------------------------

""

set scrolloff=10

" ------------------------------------------------------------------------------

""

set display=lastline

" ------------------------------------------------------------------------------

"" vi -p a b c d e f g h i j k l m n o p q r s t u v w x y z

set tabpagemax=20

" ------------------------------------------------------------------------------

"" :vnew -> new window will be right

set splitright

" ------------------------------------------------------------------------------

"" Ctrl + a / Ctrl + x -> decimal (not octal, not hex)

set nrformats=

" ------------------------------------------------------------------------------

set backspace=indent,eol,start

" ------------------------------------------------------------------------------

"" uses the indent from the previous line

set autoindent

"" recognizes some C syntax to increase/reduce the indent where appropriate

set smartindent

" ------------------------------------------------------------------------------

"" vimdiff option : ignore upper/lower case, ignore white space

set diffopt=icase,iwhite

" ------------------------------------------------------------------------------

"" when reopen file, jump to the last position
"" au : autocmd

augroup jump_to_the_last_position
    au!
    au BufRead * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
augroup END

" ------------------------------------------------------------------------------

"" Arduino

augroup arduino
    au!
    autocmd BufNewFile,BufRead *.ino set filetype=cpp
augroup END

" ------------------------------------------------------------------------------

"" (toggle set paste)
"" type "set paste" everytime

augroup insertleave_nopaste
    au!
    autocmd InsertLeave * set nopaste
augroup END

" ------------------------------------------------------------------------------

"" molokai's comment is too dark for some old display -> a little light
"" too dark  : 232 - 239
"" good      : 240 - 247
"" too light : 248 - 255

"" molokai's cursor line is too dark for some old display -> a little light
"" good      : 232 - 239
"" too light : 240 - 255

"" molokai's single quote in Ruby is too dark -> a little light

augroup color_a_little_light
    au!
    autocmd ColorScheme * highlight Comment ctermfg=245 " defalut : 59
    autocmd ColorScheme * highlight CursorLine ctermbg=237 " default : 235
    autocmd ColorScheme * highlight Visual ctermbg=237 " default : 235

    autocmd BufNewFile,BufRead *.rb highlight Delimiter ctermfg=250 " defalut : 241
augroup END

" ------------------------------------------------------------------------------

"" highlight function (in legacy code)

augroup highlight_function_in_legacy_code
    au!
    autocmd ColorScheme * highlight Function ctermfg=255
    " autocmd ColorScheme * highlight Function ctermfg=161
    " autocmd ColorScheme * highlight Function ctermfg=255 ctermbg=1 cterm=bold
augroup END

" ------------------------------------------------------------------------------

"" enable 256 colors

set t_Co=256

" ------------------------------------------------------------------------------

"" good bye .exrc
"" vim 7.4 -> vim 8.0 >> .exrc -> .vimrc

"" name_have_exrc

" augroup name_have_exrc
"     au!
"     autocmd BufNewFile,BufRead *exrc* set filetype=vim
" augroup END

" ------------------------------------------------------------------------------

"" if you need folding, you should use notepad++.

" set foldmethod=syntax
" set foldlevel=100

" za    toggle current fold open/closed

" zR    open all folds
" zM    close all folds

" zi    switch folding on or off
" zo    opens a fold at the cursor
" zO    opens all folds at the cursor
" zc    close current fold
" zv    expand folds to reveal cursor

" set foldenable
" set foldmethod=manual
" set foldmethod=indent
" set foldmethod=syntax

" set foldmethod=marker
" set foldmarker="{{{,}}}"

" set foldlevelstart=100

" set foldopen=all

" set foldcolumn=0

" let perl_fold=1
" let sh_fold_enabled=1

" ------------------------------------------------------------------------------

"" copy from now position to the end of line -> Y
"" (copy one line -> yy)

nnoremap Y y$

" ------------------------------------------------------------------------------

"" enforce show list on ctags

nnoremap <C-]> g<C-]>

" ------------------------------------------------------------------------------

" nnoremap <silent> <Space><Space> "zyiw:let @/ = '\<' . @z . '\>'<CR>:set hlsearch<CR>
nnoremap * mz*`z
nmap <silent> <Space><Space> *

" ------------------------------------------------------------------------------

"" indent for comment in python

inoremap # X<C-h>#

" ------------------------------------------------------------------------------

nnoremap <C-e> 3j3<C-e>
nnoremap <C-y> 3k3<C-y>

" ------------------------------------------------------------------------------

nnoremap <Space> <Nop>
nnoremap \ <Nop>

" ------------------------------------------------------------------------------

nnoremap <Space>1 :<C-u>windo set filetype=python<CR>

"" highlight function (in legacy code)

"" white
nnoremap <Space>7 :<C-u>highlight Function ctermfg=255 ctermbg=none cterm=none<CR>

"" red
nnoremap <Space>8 :<C-u>highlight Function ctermfg=161 ctermbg=none cterm=none<CR>

"" back ground red
nnoremap <Space>9 :<C-u>highlight Function ctermfg=255 ctermbg=1    cterm=bold<CR>

"" light green (molokai's default)
nnoremap <Space>0 :<C-u>highlight Function ctermfg=118 ctermbg=none cterm=none<CR>

" ------------------------------------------------------------------------------

"" Ctrl-f Ctrl-b (Ctrl-d Ctrl-u)

nnoremap <Space><Up> 20<C-y>
nnoremap <Space><Down> 20<C-e>

"" toggle highlight

nnoremap <Space>h :<C-u>set hlsearch!<CR>

nnoremap <Space>c :<C-u>TComment<CR>
vnoremap <Space>c :<C-u>'<,'>TComment<CR>

" ------------------------------------------------------------------------------

"" vimgrep

nnoremap <Space>n :<C-u>cnext<CR>
nnoremap <Space>p :<C-u>cprevious<CR>
nnoremap <Space>N :<C-u>clast<CR>
nnoremap <Space>P :<C-u>cfirst<CR>

" ------------------------------------------------------------------------------

"" Unite

nnoremap <Space>f :<C-u>Unite file<CR>:<C-u>set number<CR>
nnoremap <Space>r :<C-u>Unite file_rec<CR>
nnoremap <Space>b :<C-u>Unite buffer<CR>
nnoremap <Space>g :<C-u>Unite grep<CR>
nnoremap <Space>a :<C-u>UniteBookmarkAdd<CR>
nnoremap <Space>m :<C-u>Unite bookmark<CR>

" ------------------------------------------------------------------------------

nnoremap \v :<C-u>vnew %<CR>

"" Ctrl-w Ctrl-w : move other split window
"" Ctrl-w Ctrl-h : move left split window
"" Ctrl-w Ctrl-l : move right split window

nnoremap \w <C-w><C-w>

nnoremap \h <C-w><C-h>
nnoremap \l <C-w><C-l>

nnoremap \o :<C-u>only<CR>

nnoremap \<Left> :<C-u>vertical resize -2<CR>
nnoremap \<Right> :<C-u>vertical resize +2<CR>

"" (toggle set scrollbind)

"" win do / buf do
nnoremap \s :<C-u>windo set scrollbind!<CR><C-w><C-w>

" ------------------------------------------------------------------------------

"" like a double click

nnoremap \\ yiw
nnoremap \p ciw<C-r>0<ESC>

" ------------------------------------------------------------------------------

"" NeoBundle

"" git config --global http.proxy http://XXX.XXX.XXX.XXX:8080
"" git config --global https.proxy https://XXX.XXX.XXX.XXX:8080
"" --system                     | --global     | --local
"" /usr/local/git/etc/gitconfig | ~/.gitconfig | .git/config

if has('vim_starting')
    set runtimepath+=~/.vim/bundle/neobundle.vim/

    if !isdirectory(expand("~/.vim/bundle/neobundle.vim/"))
        echo "install NeoBundle..."
        :call system("git clone git://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim")
        " :call system("git clone http://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim")
        " :call system("git clone https://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim")
    endif
endif

call neobundle#begin(expand('~/.vim/bundle/'))

NeoBundleFetch 'Shougo/neobundle.vim'

" ------------------------------------------------------------------------------

"" plugin list

"" colorscheme
NeoBundle 'nanotech/jellybeans.vim'

"" colorscheme
NeoBundle 'w0ng/vim-hybrid'

"" colorscheme
NeoBundle 'tomasr/molokai'

"" boost status line
NeoBundle 'itchyny/lightline.vim'

"" may not need space -> highlight red
"" :FixWhitespace (:F[Tab])
NeoBundle 'bronson/vim-trailing-whitespace'

"" bar
NeoBundle 'majutsushi/tagbar'

"" Unite
NeoBundle 'Shougo/unite.vim'

"" comment
NeoBundle 'tomtom/tcomment_vim'

"" CtrlP
NeoBundle 'ctrlpvim/ctrlp.vim'
NeoBundle 'tacahiroy/ctrlp-funky'
NeoBundle 'suy/vim-ctrlp-commandline'

" ------------------------------------------------------------------------------

call neobundle#end()

filetype plugin indent on

NeoBundleCheck

" ------------------------------------------------------------------------------

"" jellybeans
"" echom : message history
"" :messages

"" hope block comment ...

if 0

if neobundle#is_installed('jellybeans.vim')
    colorscheme jellybeans
else
    echom 'not installed jellybeans.vim'
endif

endif

" ------------------------------------------------------------------------------

"" vim-hybrid

if 0

if neobundle#is_installed('vim-hybrid')
    colorscheme hybrid
else
    echom 'not installed vim-hybrid'
endif

endif

" ------------------------------------------------------------------------------

"" molokai

if 1

if neobundle#is_installed('molokai')
    colorscheme molokai
else
    echom 'not installed molokai'
endif

endif

" ------------------------------------------------------------------------------

"" CtrlP

let g:ctrlp_match_window = 'order:ttb,min:20,max:20,results:100'
let g:ctrlp_show_hidden = 1
let g:ctrlp_types = ['fil']
let g:ctrlp_extensions = ['funky', 'commandline']

"" CtrlP plugin

command! CtrlPCommandLine call ctrlp#init(ctrlp#commandline#id())
let g:ctrlp_funky_matchtype = 'path'

" ------------------------------------------------------------------------------

"" cscope

if has("cscope")

    " ------------------------------------------------------------------------------

    "" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'

    " set cscopetag

    "" check cscope for definition of a symbol before checking ctags: set to 1
    "" if you want the reverse search order.

    " set csto=0

    "" add any cscope database in current directory
    "" else add the database pointed to by environment variable

    " if filereadable("cscope.out")
          cs add cscope.out
    " elseif $CSCOPE_DB != ""
    "     cs add $CSCOPE_DB
    " endif

    "" show msg when any other cscope db added

    " set cscopeverbose

    " ------------------------------------------------------------------------------

    "   's'   symbol: find all references to the token under cursor
    "   'g'   global: find global definition(s) of the token under cursor
    "   'c'   calls:  find all calls to the function name under cursor
    "   't'   text:   find all instances of the text under cursor
    "   'e'   egrep:  egrep search for the word under cursor
    "   'f'   file:   open the filename under cursor
    "   'i'   includes: find files that include the filename under cursor
    "   'd'   called: find functions that function under cursor calls

    nmap <C-\>a :cscope add cscope.out<CR>

    nmap <C-\>s :cscope find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>g :cscope find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>c :cscope find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>t :cscope find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>e :cscope find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>f :cscope find f <C-R>=expand("<cfile>")<CR><CR>
    nmap <C-\>i :cscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-\>d :cscope find d <C-R>=expand("<cword>")<CR><CR>

endif

" ------------------------------------------------------------------------------

"" now comment line -> when go to next line, not change to comment line

augroup not_continue_comment
    au!
    au FileType * setlocal formatoptions-=ro
augroup END

" ------------------------------------------------------------------------------


コメントを残すために、Twitter OAuthを必要としています。ご了承ねがいます。
コメントは、Twitterに影響しません。

Twitter OAuth