Skip to content

Instantly share code, notes, and snippets.

@nakunaru
Last active March 16, 2017 04:14
Show Gist options
  • Save nakunaru/6246316 to your computer and use it in GitHub Desktop.
Save nakunaru/6246316 to your computer and use it in GitHub Desktop.
vimrc
"" vimrc
" viとの互換性OFF
set nocompatible
" ファイルタイプの検出OFF
"filetype off
"" ウィンドウに関する設定
"
" ウィンドウ幅
set columns=400
" ウィンドウ高さ
set lines=50
" コマンドラインの高さ
set cmdheight=2
" swapファイルを作らない
set noswapfile
set nobackup
"" 表示設定
"
" 構文色分け表示
syntax on
" 行番号表示
set number
" TAB
set expandtab
set tabstop=4 shiftwidth=4
set softtabstop=4
set autoindent=on
set smartindent
" 可視化
set list
set listchars=tab:>-,trail:-,eol:$,extends:>,precedes:<
"" 検索設定
"
" インクリメントサーチ
set incsearch
" 検索ハイライト
set hlsearch
" Esc*2 でハイライトOFF
nnoremap <Esc><Esc> :<C-u>set nohlsearch<Return>
" /, *, ?, # でハイライトon
nnoremap / :<C-u>set hlsearch <Return>/
nnoremap * :<C-u>set hlsearch <Return>*
nnoremap ? :<C-u>set hlsearch <Return>?
nnoremap # :<C-u>set hlsearch <Return>#
"" ステータスバー
" ステータスバーを常に表示
set laststatus=2
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [ENC=%{&fileencoding}]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
""""""""""""""""""""""""""""""
"挿入モード時、ステータスラインの色を変更
""""""""""""""""""""""""""""""
let g:hi_insert = 'highlight StatusLine guifg=darkblue guibg=darkyellow gui=none ctermfg=red ctermbg=black cterm=none'
if has('syntax')
augroup InsertHook
autocmd!
autocmd InsertEnter * call s:StatusLine('Enter')
autocmd InsertLeave * call s:StatusLine('Leave')
augroup END
endif
let s:slhlcmd = ''
function! s:StatusLine(mode)
if a:mode == 'Enter'
silent! let s:slhlcmd = 'highlight ' . s:GetHighlight('StatusLine')
silent exec g:hi_insert
else
highlight clear StatusLine
silent exec s:slhlcmd
endif
endfunction
function! s:GetHighlight(hi)
redir => hl
exec 'highlight '.a:hi
redir END
let hl = substitute(hl, '[\r\n]', '', 'g')
let hl = substitute(hl, 'xxx', '', '')
return hl
endfunction
if has('unix') && !has('gui_running')
" ESC後にすぐ反映されない対策
inoremap <silent> <Esc> <Esc>
endif
" 行カーソル
set cursorline
" ######################
" ### キー設定 ###
" ######################
"Insertモード中にカーソルキーを使用する
imap OA <UP>
imap OB <Down>
imap OC <Right>
imap OD <Left>
" Insertモード中のカーソル移動
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
inoremap <C-a> <Esc>0i
inoremap <C-e> <Esc>$a
" Insertモード中にCtrl+bでバックスペース
inoremap <C-b> <Backspace>
" Insertモード中にCtrl+dでデリート
inoremap <C-d> <Delete>
" 括弧の中へ移動
inoremap () ()<Left>
inoremap () ()<Left>
inoremap <> <><Left>
inoremap [] []<Left>
inoremap {} {}<Left>
inoremap "" ""<Left>
inoremap '' ''<Left>
inoremap 「」 「」<Left>
" ビジュアルモードでカッコを開始したら自動で選択範囲のカッコを閉じる
" 参考:http://d.hatena.ne.jp/spiritloose/20061113/1163401194
vnoremap { "zdi{<C-R>z}<ESC>
vnoremap [ "zdi[<C-R>z]<ESC>
vnoremap ( "zdi(<C-R>z)<ESC>
vnoremap ( "zdi(<C-R>z)<ESC>
vnoremap " "zdi"<C-R>z"<ESC>
vnoremap ' "zdi'<C-R>z'<ESC>
vnoremap % "zdi%<C-R>z<ESC>
set clipboard+=unnamed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment