" .vimrc " https://github.com/todashuta/profiles " Initialize: "{{{ " if &compatible | set nocompatible | endif " Startup time. " See: https://gist.github.com/thinca/1518874 if has('vim_starting') && has('reltime') let s:startuptime = reltime() augroup vimrc-startuptime autocmd! VimEnter * \ echomsg 'startuptime: ' . reltimestr(reltime(s:startuptime)) \ | unlet s:startuptime augroup END endif if exists('+regexpengine') " Use old regexp engine. "set regexpengine=1 endif let s:is_term = !has('gui_running') let s:is_windows = has('win16') || has('win32') || has('win64') let s:is_cygwin = has('win32unix') let s:is_win_console = s:is_cygwin || (s:is_windows && s:is_term) let s:is_mac = !s:is_windows && !s:is_cygwin \ && (has('mac') || has('macunix') || has('gui_macvim') || \ (!isdirectory('/proc') && executable('/usr/bin/sw_vers'))) " Use English interface. if s:is_windows language message en else language message C endif " Use English menu on MacVim. if has('gui_macvim') set langmenu=none endif " Define , "let g:mapleader = '\' "let g:maplocalleader = ',' " Define alternative key name for Insert mode completion plugin. function! s:define_alternative_key_names() let keys = [ \ ['BS', ''], \ ['C-h', ''], \ ['CR', ''], \ ['C-j', ''], \ ['NL', ''], \ ['Return', ''], \ ] for [name, rhs] in keys execute printf('inoremap (%s) %s', name, rhs) endfor endfunction if has('vim_starting') call s:define_alternative_key_names() endif " Prefix key to show [Space] in the bottom line. nmap [Space] nnoremap [Space] " Reset all autocommands defined in this file. augroup MyAutoCmd autocmd! augroup END " Delete vimrc_example's autocommands. silent! autocmd! vimrcEx " Use a forward slash as a path separator (on Windows). if exists('+shellslash') set shellslash endif if $MYGVIMRC == '' let $MYGVIMRC = expand('~/.gvimrc') endif " Anywhere SID for complicated script. if !exists('s:SID_PREFIX') function! s:_SID() return matchstr(expand(''), '\zs\d\+\ze__SID$') endfunction let s:SID_PREFIX = printf('%d_', s:_SID()) lockvar s:SID_PREFIX delfunction s:_SID endif function! s:print_error(msg) echohl ErrorMsg for m in split(a:msg, "\n") echomsg m endfor echohl None endfunction " Set runtimepath. if has('vim_starting') if s:is_windows set runtimepath^=~/.vim,~/.vim/after endif set runtimepath+=~/.vim/bundle/neobundle.vim endif let g:neobundle#log_filename = expand('~/.neobundle_log') call neobundle#begin(expand('~/.vim/bundle')) if has('lua') && (v:version > 703 || v:version == 703 && has('patch885')) NeoBundleLazy 'Shougo/neocomplete.vim' else NeoBundleLazy 'Shougo/neocomplcache.vim' endif NeoBundleLazy 'Shougo/neosnippet.vim' NeoBundle 'Shougo/neosnippet-snippets' NeoBundle 'honza/vim-snippets' NeoBundleLazy 'Shougo/unite.vim' NeoBundle 'Shougo/neomru.vim' NeoBundleLazy 'Shougo/vimfiler.vim' NeoBundleLazy 'Shougo/unite-outline', { \ 'autoload' : { \ 'unite_sources' : 'outline' \ }} NeoBundleLazy 'ujihisa/unite-colorscheme', { \ 'autoload' : { \ 'unite_sources' : 'colorscheme' \ }} NeoBundleLazy 'ujihisa/unite-font', { \ 'gui' : 1, \ 'autoload' : { \ 'unite_sources' : 'font' \ }} NeoBundleLazy 'Kocha/vim-unite-tig', { \ 'autoload' : { \ 'unite_sources' : 'tig' \ }} NeoBundleLazy 'tacroe/unite-mark', { \ 'autoload' : { \ 'unite_sources' : 'mark' \ }} NeoBundleLazy 'tsukkee/unite-help', { \ 'autoload' : { \ 'unite_sources' : 'help' \ }} NeoBundleLazy 'Shougo/unite-build', { \ 'autoload' : { \ 'unite_sources' : 'build' \ }} NeoBundle 'Shougo/vimproc.vim', { \ 'build': { \ 'windows': 'tools\\update-dll-mingw', \ 'cygwin': 'make -f make_cygwin.mak', \ 'mac': 'make -f make_mac.mak', \ 'linux': 'make', \ 'unix': 'gmake', \ }} NeoBundle 'altercation/vim-colors-solarized' NeoBundleLazy 'othree/eregex.vim' "NeoBundle 'scrooloose/nerdtree' NeoBundleLazy 'thinca/vim-quickrun' NeoBundleLazy 'tyru/open-browser.vim' NeoBundleLazy 'h1mesuke/vim-alignta', { \ 'autoload' : { \ 'commands' : ['Alignta', 'Align'] \ }} NeoBundleLazy 'tpope/vim-surround' "NeoBundle 'troydm/easybuffer.vim' "NeoBundle 'vim-scripts/DirDo.vim' "NeoBundleLazy 'kana/vim-smartchr' NeoBundle 'kana/vim-submode' NeoBundle 'kana/vim-niceblock' NeoBundleLazy 'glidenote/memolist.vim', { \ 'autoload' : { \ 'commands' : ['MemoGrep', 'MemoList', 'MemoNew'] \ }} NeoBundleLazy 'hallison/vim-markdown', { \ 'autoload' : { \ 'filetypes' : ['markdown'] \ }} NeoBundleLazy 'Shougo/vimshell.vim' NeoBundleLazy 'mattn/emmet-vim' NeoBundle 'koron/codic-vim' NeoBundle 'rhysd/unite-codic.vim' NeoBundleLazy 'thinca/vim-ref' NeoBundleLazy 'mattn/calendar-vim', { \ 'autoload' : { \ 'commands' : ['Calendar', 'CalendarH'] \ }} "NeoBundle 'nathanaelkane/vim-indent-guides' NeoBundleLazy 'ap/vim-css-color', { \ 'autoload' : { \ 'filetypes' : ['html', 'css', 'sass'] \ }} NeoBundleLazy 'lilydjwg/colorizer' NeoBundleLazy 'koron/nyancat-vim', { \ 'autoload' : { \ 'commands' : ['Nyancat', 'Nyancat2'] \ }} NeoBundleLazy 'hail2u/vim-css3-syntax', { \ 'autoload' : { \ 'filetypes' : ['html', 'css'] \ }} NeoBundleLazy 'othree/html5.vim', { \ 'autoload' : { \ 'filetypes' : ['html', 'css'] \ }} "NeoBundle 'kien/ctrlp.vim' "NeoBundleLazy 'kana/vim-smartinput' NeoBundleLazy 'basyura/TweetVim', { \ 'depends' : [ \ 'basyura/twibill.vim', 'tyru/open-browser.vim' \ ], \ 'autoload' : { \ 'commands' : ['TweetVimHomeTimeline', 'TweetVimSay'], \ 'unite_sources' : 'tweetvim', \ }} NeoBundle 'bling/vim-airline' "NeoBundle 'itchyny/lightline.vim' NeoBundleLazy 'thinca/vim-painter', { \ 'autoload' : { \ 'commands' : 'PainterStart' \ }} NeoBundleLazy 'thinca/vim-scouter', { \ 'autoload' : { \ 'commands' : [ \ { 'name' : 'Scouter', 'complete' : 'file' } \ ]}} NeoBundleLazy 'thinca/vim-visualstar' "NeoBundle 'vim-scripts/ShowMarks' "NeoBundle 'Lokaltog/vim-easymotion' NeoBundleLazy 'AndrewRadev/switch.vim' NeoBundleLazy 'ujihisa/neco-look', { \ 'autoload' : { \ 'insert' : 1 \ }} NeoBundle 'mhinz/vim-signify' NeoBundleLazy 'kchmck/vim-coffee-script', { \ 'autoload' : { \ 'filetypes' : ['coffee'] \ }} NeoBundleLazy 'vim-scripts/Vim-R-plugin' NeoBundleLazy 'itchyny/thumbnail.vim', { \ 'autoload' : { \ 'commands' : ['Thumbnail'], \ }} NeoBundleLazy 'Shougo/vinarise.vim', { \ 'autoload' : { \ 'commands' : [ \ { 'name' : 'Vinarise', \ 'complete' : 'customlist,vinarise#complete' }, \ ]}} NeoBundleLazy 'mattn/webapi-vim', { \ 'autoload' : { \ 'function_prefix' : 'webapi' \ }} NeoBundleLazy 'todashuta/gcalc.vim', 'develop', { \ 'depends' : 'mattn/webapi-vim', \ 'autoload' : { \ 'commands' : [ \ { 'name' : 'GCalc', \ 'complete' : 'custom,gcalc#complete' }, \ ]}} NeoBundleLazy 'todashuta/unite-transparency', { \ 'autoload' : { \ 'unite_sources' : 'transparency' \ }} if !filereadable($VIMRUNTIME . '/ftplugin/go.vim') NeoBundleLazy 'google/vim-ft-go', { \ 'autoload': { \ 'filetypes': ['go'], \ }} endif NeoBundleLazy 'vim-jp/vim-go-extra', { \ 'autoload': { \ 'filetypes': ['go'], \ }} NeoBundleLazy 'terryma/vim-expand-region' NeoBundleLazy 'mfumi/snake.vim', { \ 'autoload' : { \ 'commands' : 'Snake' \ }} NeoBundleLazy 'deris/vim-duzzle', { \ 'autoload' : { \ 'commands' : 'DuzzleStart' \ }} NeoBundleLazy 'hrsh7th/vim-neco-calc', { \ 'autoload' : { \ 'insert' : 1 \ }} NeoBundleLazy 'thinca/vim-unite-history', { \ 'autoload' : { \ 'unite_sources' : ['history/command', 'history/search'] \ }} NeoBundleLazy 'osyo-manga/unite-filetype', { \ 'autoload' : { \ 'unite_sources' : 'filetype' \ }} NeoBundleLazy 'mattn/habatobi-vim', { \ 'autoload' : { \ 'commands' : 'Habatobi' \ }} NeoBundleLazy 'thinca/vim-editvar', { \ 'autoload' : { \ 'commands' : [ \ { 'name' : 'Editvar', \ 'complete' : 'var' } \ ], \ 'unite_sources' : 'variable' \ }} NeoBundle 'rbtnn/vimconsole.vim' NeoBundle 'tpope/vim-fugitive' NeoBundle 'vim-jp/vital.vim' NeoBundleLazy 'kana/vim-textobj-user', { \ 'autoload' : { \ 'function_prefix' : 'textobj' \ }} NeoBundleLazy 'kana/vim-textobj-indent', { \ 'autoload' : { \ 'mappings' : [ \ ['xo', 'ai'], ['xo', 'ii'], ['xo', 'aI'], ['xo', 'iI'] \ ]}} NeoBundleLazy 'kana/vim-textobj-line', { \ 'autoload' : { \ 'mappings' : [['xo', 'al'], ['xo', 'il']] \ }} NeoBundleLazy 'kana/vim-textobj-entire', { \ 'autoload' : { \ 'mappings' : [['xo', 'ae'], ['xo', 'ie']] \ }} "NeoBundle 'kana/vim-textobj-jabraces' NeoBundleLazy 'thinca/vim-textobj-comment', { \ 'autoload' : { \ 'mappings' : [['xo', 'ac'], ['xo', 'ic']] \ }} NeoBundleLazy 'saihoooooooo/vim-textobj-space', { \ 'autoload' : { \ 'mappings' : [['xo', 'aS'], ['xo', 'iS']] \ }} NeoBundle 'mattn/lisper-vim' NeoBundleLazy 'rbtnn/puyo.vim', { \ 'autoload' : { \ 'commands' : 'Puyo' \ }} NeoBundleLazy 'deris/vim-rengbang', { \ 'autoload' : { \ 'function_prefix' : 'rengbang', \ 'commands' : ['RengBang', 'RengBangUsePrev', 'RengBangConfirm'] \ }} NeoBundle 'thinca/vim-prettyprint' if has('python') NeoBundleLazy 'gregsexton/VimCalc', { \ 'autoload' : { \ 'commands' : 'Calc' \ }} NeoBundleLazy 'vim-scripts/VOoM', { \ 'autoload' : { \ 'commands' : [ \ { 'name' : 'Voom', \ 'complete' : 'custom,voom#Complete' }, \ { 'name' : 'VoomToggle', \ 'complete' : 'custom,voom#Complete' }, \ 'Voomhelp', 'Voomlog', 'Voomexec' \ ]}} endif if executable('ag') NeoBundle 'rking/ag.vim' endif "if executable('/usr/bin/mdfind') " NeoBundle 'choplin/unite-spotlight', " \ { 'depends' : 'Shougo/unite.vim' } "endif if has('conceal') && !s:is_win_console NeoBundle 'Yggdroot/indentLine' endif if s:is_windows NeoBundle 'istepura/vim-toolbar-icons-silk', { \ 'gui' : 1 \ } endif " Local plugins directory like pathogen. (For develop plugins, etc.) "NeoBundleLocal ~/bundle " Disable netrw.vim let g:loaded_netrwPlugin = 1 " Disable vimball.vim let g:loaded_vimballPlugin = 1 " Disable getscript.vim let g:loaded_getscriptPlugin = 1 call neobundle#end() filetype plugin indent on "NeoBundleCheck syntax enable " }}} " Encoding: "{{{ " " Use the UTF-8 encoding inside Vim. set encoding=utf-8 if s:is_cygwin || s:is_windows set termencoding=cp932 endif " Must after set of 'encoding'. scriptencoding utf-8 " fileencodings. if has('iconv') && !has('kaoriya') let s:enc_euc = 'euc-jp' let s:enc_jis = 'iso-2022-jp' " Does iconv support JIS X 0213 ? if iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb" let s:enc_euc = 'euc-jisx0213,euc-jp' let s:enc_jis = 'iso-2022-jp-3' endif " Make fileencodings. let &fileencodings = 'ucs-bom' if &encoding !=# 'utf-8' let &fileencodings = &fileencodings . ',' . 'ucs-2le' let &fileencodings = &fileencodings . ',' . 'ucs-2' endif let &fileencodings = &fileencodings . ',' . s:enc_jis if &encoding ==# 'utf-8' let &fileencodings = &fileencodings . ',' . s:enc_euc let &fileencodings = &fileencodings . ',' . 'cp932' elseif &encoding =~# '^euc-\%(jp\|jisx0213\)$' let &encoding = s:enc_euc let &fileencodings = &fileencodings . ',' . 'utf-8' let &fileencodings = &fileencodings . ',' . 'cp932' else " cp932 let &fileencodings = &fileencodings . ',' . 'utf-8' let &fileencodings = &fileencodings . ',' . s:enc_euc endif let &fileencodings = &fileencodings . ',' . &encoding unlet s:enc_euc unlet s:enc_jis endif if has('guess_encode') && index(split(&fileencodings, ','), 'guess') == -1 set fileencodings^=guess endif " }}} " General: "{{{ " " A history of ":" commands, and a history of previous search patterns. set history=1024 " Enable backspace delete indent and newline. set backspace=indent,eol,start " Allow h, l, and to move to the previous/next line. set whichwrap=b,s,h,l,<,>,[,] " Enable virtualedit in visual block mode. set virtualedit& virtualedit+=block " Splitting a window will put the new window below the current one. set splitbelow " Splitting a window will put the new window right of the current one. set splitright " Use clipboard register. (i.e. Use OS's clipboard.) set clipboard& clipboard+=unnamed " Enable modeline. set modeline " Use a mouse on terminal. if has('mouse') set mouse=a silent! set ttymouse=xterm silent! set ttymouse=xterm2 silent! set ttymouse=sgr endif " Indicates a fast terminal connection. set ttyfast " Don't redraw while macro executing. set lazyredraw " All windows not same size after split or close. set noequalalways " Default end-of-line format. set fileformat=unix set fileformats=unix,dos,mac " }}} " File,Backup: "{{{ " " Display another buffer when current buffer isn't saved. set hidden " Auto reload if file is changed. set autoread set nobackup writebackup backupdir=~/var/vim/backup silent! call mkdir(&backupdir, 'p', 0700) set swapfile directory=~/var/vim/swap silent! call mkdir(&directory, 'p', 0700) " Undo persistence if has('persistent_undo') set undofile undodir=~/var/vim/undo silent! call mkdir(&undodir, 'p', 0700) endif " }}} " Indent,Tab: "{{{ " " Enable smart indent. set autoindent smartindent if has('vim_starting') " Number of spaces that a in the file counts for. set tabstop=4 " Number of spaces to use for each step of (auto)indent. set shiftwidth=4 " See :help softtabstop set softtabstop=4 " Expand tab to spaces. "set expandtab endif " Smart insert tab setting. "set smarttab " Round indent to multiple of 'shiftwidth'('>'and'<'commands). set shiftround " Disable auto wrap. autocmd MyAutoCmd FileType * setlocal textwidth=0 " }}} " Search: "{{{ " " Enable incremental search. set incsearch " Searchs wrap around the end of the file. set wrapscan " Ignore the case of nornal letters. set ignorecase " If the search pattern contains upper case characters, override ignorecase option. set smartcase " Highlight search results. set hlsearch " Don't (re)highlighting the last search pattern on reloading. nohlsearch " Command-line completion operates in an enhanced mode. set wildmenu wildmode=longest,list,full silent! set wildignorecase " These patterns is ignored when completing file or directory names. "set wildignore& wildignore+=.DS_Store "set wildignore+=*~,*.swp,*.tmp "set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png " These extensions get a lower priority when multiple files match a wildcard. set suffixes& suffixes+=.DS_Store "set suffixes+=.tmp,.bmp,.gif,.ico,.jpg,.png if !exists('s:grepprgs') let s:grepprgs = [] " ggrep (GNU grep) is much faster than BSD grep. if executable('ggrep') call add(s:grepprgs, 'ggrep -nrIH --exclude-dir=.git') elseif executable('grep') call add(s:grepprgs, 'grep -nrIH --exclude-dir=.git') endif if executable('pt') call add(s:grepprgs, 'pt --nogroup --nocolor') endif if executable('ag') call add(s:grepprgs, 'ag --nogroup --nocolor') endif if executable('ack') call add(s:grepprgs, 'ack -H --nogroup --nocolor --column') elseif executable('ack-grep') call add(s:grepprgs, 'ack-grep -H --nogroup --nocolor --column') endif "if executable('jvgrep') " call add(s:grepprgs, 'jvgrep -R') "endif if executable('git') call add(s:grepprgs, 'git --no-pager grep -nIH') endif if empty(s:grepprgs) call add(s:grepprgs, 'internal') endif endif if has('vim_starting') let &grepprg = s:grepprgs[0] endif set grepformat& grepformat^=%f:%l:%c:%m nnoremap [toggle]g \ :call toggle_grepprg() function! s:toggle_grepprg() let i = (index(s:grepprgs, &grepprg) + 1) % len(s:grepprgs) let prev_grepprg = &grepprg let &grepprg = s:grepprgs[i] echo printf("'grepprg' = %s (was %s)", &grepprg, prev_grepprg) endfunction nnoremap [toggle]G \ :call print_grepprgs() function! s:print_grepprgs() echo join(['-----| List of grepprgs |-----'] + map(copy(s:grepprgs), \ '(v:val ==# &grepprg ? "[*] " : "[ ] ") . v:val'), "\n") endfunction autocmd MyAutoCmd FileType qf \ call s:on_FileType_quickfix() function! s:on_FileType_quickfix() setlocal nowrap colorcolumn= nnoremap nnoremap :colder nnoremap :cnewer endfunction " See: http://vim.g.hatena.ne.jp/ka-nacht/20090119/1232347709 nnoremap [quickfix]s \ :call toggle_quickfix_window() function! s:toggle_quickfix_window() let _ = winnr('$') cclose if _ == winnr('$') botright cwindow endif endfunction nmap s [quickfix] nnoremap [quickfix] nnoremap [quickfix]r :execute 'crewind ' . v:count1 nnoremap [quickfix]j :cnext nnoremap [quickfix]k :cprevious nnoremap [quickfix]J :cnfile nnoremap [quickfix]K :cpfile nnoremap [quickfix]gg :cfirst nnoremap [quickfix]G :clast nnoremap [quickfix]o :botright copen nnoremap [quickfix]c :cclose nnoremap [quickfix]p :colder nnoremap [quickfix]n :cnewer nnoremap [quickfix]/ :silent grep! nnoremap [quickfix]a :silent grepadd! nnoremap [quickfix]? \ :/j **/* botright cwindownoautocmd \ =(v:count == v:count1 ? v:count : '')vimgrep / nnoremap [quickfix]A \ :/j **/* botright cwindownoautocmd \ =(v:count == v:count1 ? v:count : '')vimgrepadd / autocmd MyAutoCmd QuickFixCmdPost [^l]* botright cwindow | redraw! " }}} " Key Mappings: "{{{ " " timeout. set timeout timeoutlen=2000 ttimeoutlen=50 inoremap `^ inoremap `^ " Paste. inoremap * \ "\:set paste\\" \ . (exists('+clipboard') ? '*' : '"') \ . "\:set nopaste\" " Stop the search highlightings and clear messages on the last line. nnoremap :nohlsearch:echo " Centering search result and open fold. nnoremap n nzzzv nnoremap N Nzzzv " Don't move on * nnoremap * *N " Don't move on # nnoremap # #N " Don't move on g* nnoremap g* g*N " Don't move on g# nnoremap g# g#N " Centering , nnoremap zz nnoremap zz " Insert close tags automatically in editing xml and html. "if exists('&omnifunc') " autocmd MyAutoCmd FileType xml,html,php " \ inoremap "endif " Visual shifting (does not exit Visual mode) "xnoremap < >gv " Shift + Arrow key: Resize split windows. nnoremap :wincmd < nnoremap :wincmd > nnoremap :wincmd + nnoremap :wincmd - " : Make all windows equally high and wide. nnoremap [Space]= :wincmd = " Yank from the cursor to the end of line. nnoremap Y y$ " Command-Line history completion. cnoremap cnoremap "cnoremap "cnoremap " for file complete (or insert glob). cnoremap (getcmdline() =~# '/$') ? \ "\\" : (getcmdline() =~# '\S$' ? ' ' : '')."**/*" " Quick edit and reload .vimrc/.gvimrc nnoremap [Space].. \ :tabedit $MYVIMRC nnoremap [Space].g \ :tabedit $MYGVIMRC nnoremap [Space]R \ :source $MYVIMRC \ if has('gui_running') \ source $MYGVIMRC \ endif " toggle-option prefix key. nmap [Space]t [toggle] nnoremap [toggle] nnoremap [toggle]h \ :call toggle_option('hlsearch') nnoremap [toggle]w \ :call toggle_option('wrap') nnoremap [toggle]- \ :call toggle_option('cursorline') nnoremap [toggle] \ :call toggle_option('cursorcolumn') nnoremap [toggle]l \ :call toggle_option('list') nnoremap [toggle]/ \ :call toggle_option('wrapscan') nnoremap [toggle]n \ :call toggle_line_number() nnoremap [toggle]p \ :call toggle_option('paste'):set mouse= nnoremap [toggle]m \ :let &mouse = (&mouse == 'a' ? '' : 'a'):set mouse? " Lookup help three times more than regular speed. nnoremap :help nnoremap [Space]c :close nnoremap [Space]o :only nnoremap [Space]s :split nnoremap [Space]v :vsplit " buffer operation prefix key. nmap [Space]b [buffer] nnoremap [buffer] nnoremap [buffer]b :b# nnoremap [buffer]p :bprevious nnoremap [buffer]n :bnext nnoremap [buffer]t :Thumbnail -here nnoremap [Space] :bdelete nnoremap Q "nnoremap K " Moving cursor to other windows. nnoremap [Space]h :wincmd h nnoremap [Space]j :wincmd j nnoremap [Space]k :wincmd k nnoremap [Space]l :wincmd l "nmap [Space] [Space2] "nnoremap [Space2] nnoremap [Space]H \ :wincmd h:resize:vertical resize nnoremap [Space]J \ :wincmd j:resize:vertical resize nnoremap [Space]K \ :wincmd k:resize:vertical resize nnoremap [Space]L \ :wincmd l:resize:vertical resize nnoremap [Space]C \ :lcd %:p:h:echo 'lcd ' . expand('%:p:h') nnoremap [Space]B :Unite buffer " (visual mode) p: Paste from the last yank. "xnoremap p "0p " (visual mode) P: Original visual mode 'p' behavior. "xnoremap P p " x, X: Delete into the blackhole register to not clobber the last yank. "nnoremap x "_x "nnoremap X "_X " c: Change into the blackhole register to not clobber the last yank. nnoremap c "_c " (visual mode) v: Rotate wise of visual mode. xnoremap v keys_to_rotate_wise_of_visual_mode() function! s:keys_to_rotate_wise_of_visual_mode() let loop_p = get(g:, 'VisualModeRotation_enable_loop', 0) if mode() ==# 'v' return 'V' elseif mode() ==# 'V' return "\" elseif mode() ==# "\" return loop_p ? 'v' : "\" endif endfunction " Use ':tjump' instead of ':tag'. nnoremap g " }}} " Visual: "{{{ " " Set title of the window to the value of 'titlestring'. set title " Enable 256 color terminal. set t_Co=256 " Color scheme (Don't override colorscheme.) "if s:is_term && (!exists('g:colors_name') || has('vim_starting')) " colorscheme solarized "endif " Number of screen lines to use for the command-line. set cmdheight=2 " Show (partial) command in the last line of the screen. set showcmd " Minimal number of screen lines to keep above and below the cursor. set scrolloff=2 " Disable bell. set visualbell t_vb= " A fullwidth character is displayed in vim properly. if s:is_windows && has('kaoriya') && has('gui_running') set ambiwidth=auto else set ambiwidth=double endif if has('conceal') set conceallevel=2 concealcursor=ni endif " Show the line and column number of the cursor position. "set ruler " When a bracket is inserted, briefly jump to the matching one. set showmatch matchtime=3 " Highlight a pair of <>. set matchpairs& matchpairs+=<:> " When a last line is long, do not omit it in @. set display& display+=lastline " The height of popup menu. set pumheight=15 " colorcolumn. " http://hanschen.org/2012/10/24/ " http://stackoverflow.com/questions/2447109/showing-a-different-background-colour-in-vim-past-80-characters if exists('+colorcolumn') command! -bang -nargs=? Colorcolumn \ call s:cmd_Colorcolumn(0, ) function! s:cmd_Colorcolumn(bang, col) if a:col == '' setlocal colorcolumn= return endif if a:bang let &l:colorcolumn = join(range(a:col, a:col+255), ',') else let &l:colorcolumn = a:col endif endfunction if has('vim_starting') Colorcolumn! 79 endif " Toggle colorcolumns. nnoremap [toggle]cc \ :execute 'Colorcolumn!' (&l:colorcolumn == '' ? '79' : '') endif let s:listchars = { \ 'classic' : 'tab:>-,trail:-,eol:$,extends:>,precedes:<,nbsp:%', \ 'modern' : 'tab:▸ ,trail:›,precedes:«,extends:»,nbsp:␣' \ } if has('vim_starting') set list let &listchars = s:listchars[(s:is_win_console ? 'classic' : 'modern')] silent! set norelativenumber set nonumber set nowrap set nocursorline endif " Highlight cursor line sensibly only current window. autocmd MyAutoCmd WinEnter * \ let &l:cursorline = get(w:, 'save_cursorline', &cursorline) autocmd MyAutoCmd WinLeave * \ let [w:save_cursorline, &l:cursorline] = [&l:cursorline, 0] " Highlight cursor column sensibly only current window. autocmd MyAutoCmd WinEnter * \ let &l:cursorcolumn = get(w:, 'save_cursorcolumn', &cursorcolumn) autocmd MyAutoCmd WinLeave * \ let [w:save_cursorcolumn, &l:cursorcolumn] = [&l:cursorcolumn, 0] " Current window colorcolumn. autocmd MyAutoCmd WinEnter * \ let &l:colorcolumn = get(w:, 'save_colorcolumn', &colorcolumn) autocmd MyAutoCmd WinLeave * \ let [w:save_colorcolumn, &l:colorcolumn] = [&l:colorcolumn, 0] " }}} " Status Line: "{{{ " " Show statusline always. set laststatus=2 " Set statusline. "function! s:my_statusline() " let is_wide = (&columns >= 80) " " let _ = [] " " Paste mode Indicator. " let _ += [&paste ? (is_wide ? '[PASTE] ' : '[P]') : ''] " " Buffer number. " let _ += ['[%2n]'] " " File path / File name. " let _ += [is_wide ? ' %<%F' : '%<%t'] " " Modified flag, Readonly flag, Help flag, Preview flag. " let _ += ['%m%r%h%w'] " " Separation point between left and right, and Space. " let _ += ['%= '] " " Filetype, Fileencoding, Fileformat. " let _ += [is_wide " \ ? printf('[%s][%s][%s]', " \ (strlen(&filetype) ? &filetype : 'no ft'), " \ (empty(&fileencoding) ? &encoding : &fileencoding), " \ &fileformat " \ ) " \ : printf('[%s:%s:%s]', &filetype, &fileencoding, &fileformat)] " " Cursor position. (Numbers of lines in buffer) " let _ += [is_wide ? ' [%4l/%L:%3v]' : '[%3l:%2v]'] " " Percentage through file in lines as in |CTRL-G|. " let _ += [' %3p%% '] " " return join(_, '') "endfunction " "let &statusline = '%!' . s:SID_PREFIX . 'my_statusline()' " }}} " Highlight "{{{ " function! s:additional_highlight() " Highlight ideographic space (japanese zenkaku space) highlight IdeographicSpace term=underline ctermbg=64 guibg=#719e07 execute printf('match IdeographicSpace /%s/', \ (has('iconv') ? iconv("\x81\x40", 'cp932', &encoding) : '')) " Silent matchparen highlight MatchParen \ guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE \ term=underline cterm=underline gui=underline " Change cursor color when IME is on. highlight CursorIM guifg=#fdf6e3 guibg=#dc322f endfunction autocmd MyAutoCmd VimEnter,WinEnter,ColorScheme * \ call s:additional_highlight() autocmd MyAutoCmd User VimrcReloaded \ call s:additional_highlight() " }}} " Encoding commands: "{{{ " " Reopen as each encodings command! -bang -bar -complete=file -nargs=? Utf8 \ edit ++enc=utf-8 command! -bang -bar -complete=file -nargs=? Iso2022jp \ edit ++enc=iso-2022-jp command! -bang -bar -complete=file -nargs=? Cp932 \ edit ++enc=cp932 command! -bang -bar -complete=file -nargs=? Eucjp \ edit ++enc=euc-jp command! -bang -bar -complete=file -nargs=? Utf16 \ edit ++enc=ucs-2le command! -bang -bar -complete=file -nargs=? Utf16be \ edit ++enc=ucs-2 " Change encoding command command! -bar -nargs=? -complete=customlist,s:cmd_Fenc_complete Fenc \ setlocal fileencoding= function! s:cmd_Fenc_complete(ArgLead, CmdLine, CursorPos) let fencs = ['utf-8', 'sjis', 'euc-jp', 'iso-2022-jp', 'cp932'] return filter(fencs, 'v:val =~? "^" . a:ArgLead') endfunction " Change fileformat command command! -bar -nargs=1 -complete=customlist,s:cmd_Ff_complete Ff \ call s:cmd_Ff() let s:fileformats = { \ 'CR': 'mac', \ 'CR+LF': 'dos', \ 'LF': 'unix', \ 'dos': 'dos', \ 'mac': 'mac', \ 'unix': 'unix', \ } function! s:cmd_Ff_complete(ArgLead, CmdLine, CursorPos) return filter(keys(s:fileformats), 'v:val =~? "^" . a:ArgLead') endfunction function! s:cmd_Ff(arg) if !has_key(s:fileformats, a:arg) call s:print_error(printf('Ff: Invalid end-of-line name: %s', a:arg)) return endif execute 'setlocal fileformat=' . s:fileformats[a:arg] endfunction " }}} " While entering insert mode, disable hlsearch temporary. {{{ " "autocmd MyAutoCmd InsertEnter * setlocal nohlsearch "autocmd MyAutoCmd InsertLeave * setlocal hlsearch " }}} " On diff mode, diffupdate automatically when insert leave. {{{ " autocmd MyAutoCmd InsertLeave * \ if &diff | diffupdate | echo 'diffupdated' | endif " }}} " Automatic paste disable. {{{ " autocmd MyAutoCmd InsertLeave * \ if &paste | set nopaste mouse=a | echo 'nopaste' | endif " }}} " Restore cursor position. {{{ " autocmd MyAutoCmd BufReadPost * \ call s:restore_cursor_position() function! s:restore_cursor_position() let ignore_filetypes = ['gitcommit'] if index(ignore_filetypes, &l:filetype) >= 0 return endif if line("'\"") > 1 && line("'\"") <= line("$") execute 'normal! g`"' endif endfunction " }}} " Plugin: "{{{ " " neocomplete.vim {{{ if neobundle#tap('neocomplete.vim') call neobundle#config({ \ 'autoload' : { \ 'insert' : 1, \ }}) function! neobundle#tapped.hooks.on_source(bundle) let g:neocomplete#enable_at_startup = 1 let g:neocomplete#enable_smart_case = 1 let g:neocomplete#enable_fuzzy_completion = 1 let g:neocomplete#sources#syntax#min_keyword_length = 3 let g:neocomplete#force_overwrite_completefunc = 1 "let g:neocomplete#skip_auto_completion_time = '0.3' "let g:neocomplete#disable_auto_complete = 1 let g:neocomplete#sources#dictionary#dictionaries = get(g:, \ 'neocomplete#sources#dictionary#dictionaries', {}) call extend(g:neocomplete#sources#dictionary#dictionaries, { \ 'default': '', \ 'vimshell': expand('~/.vimshell/command-history'), \ }) let g:neocomplete#sources#vim#complete_functions = get(g:, \ 'neocomplete#sources#vim#complete_functions', {}) call extend(g:neocomplete#sources#vim#complete_functions, { \ 'Ref': 'ref#complete', \ 'Unite': 'unite#complete#source', \ 'VimShell': 'vimshell#complete', \ }) let g:neocomplete#sources#omni#functions = get(g:, \ 'neocomplete#sources#omni#functions', {}) call extend(g:neocomplete#sources#omni#functions, { \ 'clojure': 'clojurecomplete#Complete', \ }) let g:neocomplete#force_omni_input_patterns = get(g:, \ 'neocomplete#force_omni_input_patterns', {}) call extend(g:neocomplete#force_omni_input_patterns, { \ 'cpp': '[^.[:digit:] *\t]\%(\.\|->\)\w*\|\h\w*::\w*', \ 'html': '<\/\w*', \ 'php': '<\/\w*', \ 'ruby': '[^. *\t]\.\w*\|\h\w*::', \ 'xml': '<\/\w*', \ }) "let g:neocomplete#sources#omni#input_patterns = get(g:, " \ 'neocomplete#sources#omni#input_patterns', {}) "call extend(g:neocomplete#sources#omni#input_patterns, { " \ 'html': '<\/\w*', " \ 'php': '<\/\w*', " \ }) " mappings {{{ " : Close popup and save indent. inoremap