ã¼ãã®ããããããããããã®vimrc
ãã®è¨äºã¯Vim Advent Calendar 2013ã®171æ¥ç®ã®è¨äºã§ãã
170æ¥ç®ã¯manga_osyoããã«ããvim-operator-alignta ã¤ãã£ãã§ããã
æ¬è¨äºã§ã¯ãã¼ãã®ããããããããããã®vimrcãç´¹ä»ãã¾ãã
ã¯ããã«
ãããããã®vimrcã¨ã¯ï¼
ä½ãä¸äºç ã£ã½ãã¿ã¤ãã«ã§ãããããã¨ã¾ããã«èãã¦ä½ã£ããã®ã§ãã
ã¿ã¤ãã«ãããã¨è¦ã¦ããæå°ï¼æå¼·ã®ã¿ã¤ããããªãã®ï¼ã ã¨æãããæ¹ãããããããã¾ããã ããããæå¼·ã®vimrcã§ã¯ããã¾ããã æå° ã®vimrcã§ãã
ç§ãããã§è¨ã£ã¦ããæå°ã®vimrcã¨ã¯ä»¥ä¸ã®ãããªæå³ã§ãã
Vim pluginãå ¥ãããå¿ è¦æå°éã®è¨å®ã ããã¾ã¨ããvimrc
Vim pluginãå ¥ããã¨ããã®ããã½ã§ãã ã¾ããããã§è¨ã£ã¦ããæå°éã®è¨å®ã¨ã¯ã(å人çã«)ã©ããã¦ã å¿ è¦ãªãªãã·ã§ã³è¨å®ã¨ãã¼ãããã³ã°ãªã©ã®ãã¨ã§ãã
ãããããã®vimrcä½ã£ãçç±
ä»äºä¸ãã¹ãæ©ãªã©ã®å ±ç¨ã§ä½¿ããããªãã·ã³ã§ã ã¡ãã£ã¨è¨å®ãã¡ã¤ã«ãªã©ãç·¨éãããå ´åã«ã åæã«Vimãã©ã°ã¤ã³ãå ¥ãã¥ããã£ããã ããããVimãã©ã°ã¤ã³ããããã¾ã§ããªãã£ããããå ´åãããã¾ãã
ããããæãç§ã¯ä»ã¾ã§ç¹ã«è¨å®ãªãã§Vimã使ã£ã¦ããã®ã§ããã ããªããªã«ã¹ã¿ãã¤ãºããèªåã®vimrcã«æ £ããã£ã¦ããã¨ã æä½ãå¾®å¦ã«ããã¡ãªããªãã¾ãã (ãã¡ããæä½ã§ããªãã¨ãããã¨ã¯ãªãã§ããããã)
ãã¨è¨ã£ã¦ããã¤ã使ã£ã¦ããvimrcããã®ã¾ã¾å ¥ãã㨠ãã©ã°ã¤ã³ã®è¨å®ãããããããããã大éã®ã¨ã©ã¼ã§ ã¾ã¨ãã«åãã¾ããã
ãã®ãããªèæ¯ããããã«ã¹ã¿ãã¤ãºããªããªã®vimrcã¨ã¯å¥ã« ã¡ãã£ã¨ããvimrcãã¤ã¾ãèªåã«ã¨ã£ã¦æå°éã®è¨å®ãè¨è¼ãã vimrcãæ¸ããã¨ã«ãã¾ããã å°ããvimrcã§ããã°ããã£ã¨ã³ãã¼ãã¦ãã£ã¨ä½¿ããã¨ã ã§ã便å©ã§ãã
ãããããã®vimrc
ã¼ãã®ããããããããããã®vimrcã¯ã .minimal_vimrcã«ããã¦ã¾ãã
ä»å¾å¤æ´ãããããããªãã®ã§ç¾æç¹(2014/5/21)ã§ã®ææ°ã«ãªã³ã¯ãã¦ãã¾ãã
ä¸èº«ã«ã¤ãã¦ç°¡åã«ãã£ã¨ãç´¹ä»ãã¾ãã
ãªããä¸è¨è¨å®ã¯å ¨é¨ãèªåã§èãããã®ã§ã¯ãªã ã©ãªããã®vimrcãçä¼¼ããã¦ããã ãããã®ãããã¾ãã ã©ããã©ãªãã®è¨å®ãè¦ãã¦ããªãã®ã§ããã ãã®å ´ãåãã¦å¾¡ç¤¼ç³ãä¸ãã¾ãã
syntax enable
æ§æãã¤ã©ã¤ããæå¹ã«ãã¦ãã¾ãã ããã§ãã¡ã¤ã«ã¿ã¤ãå¥ã«è²ä»ããããããã«ãªãã¾ãã
set number set ruler set list set listchars=tab:>-,trail:-,nbsp:%,extends:>,precedes:<,eol:< set incsearch set hlsearch set nowrap set showmatch set whichwrap=h,l set nowrapscan set ignorecase set smartcase set hidden set history=2000 set autoindent set expandtab set tabstop=2 set shiftwidth=2 set helplang=en
ãªãã·ã§ã³è¨å®ã¯å®å
¨ã«å¥½ã¿ãªã®ã§ãç´°ãã説æã¯ãã¾ããã
å人çã«ã¯ãè¡çªå·è¡¨ç¤º(number
)ããæ¤ç´¢å¨ã(incsearch
,hlsearch
,ignorecase
)ã
è¡é /è¡æ«ã§ã®ã«ã¼ã½ã«ç§»å(whichwrap
)ãé ããããã¡(hidden
)
ãããã¯ãè¨å®ãã¦ãããªãã¨æä½ãã¥ããã§ãã
colorscheme desert
èæ¯è²é»ãã¼ã¹ã®ã«ã©ã¼ã¹ãã¼ãã好ããªã®ã§desert
ã«è¨å®ãã¦ãã¾ãã
nnoremap <Space>w :<C-u>w<CR> nnoremap <Space>q :<C-u>q<CR> nnoremap <Space>Q :<C-u>q!<CR>
ãã¡ã¤ã«ä¿åãã¦ã£ã³ãã¦ã¯ãã¼ãºããã¼ã«ãããã³ã°ãã¦ã¾ãã
ã¿ã¤ãæ°ã¯ãããªã«å¤ãããªãã¨æãããããããã¾ãããã
<Enter>
ãæ¼ããªãã¦ããåãæ軽ã«ã¿ã¤ãåºæ¥ã¾ããã
:w[<Enter>
ãªã©ã®ã¿ã¤ããªã©ãæ°ã«ããªãã¦ãããªãã¾ãã
<Space>
ãé常ã«ã¿ã¤ããããããã¬ãã£ã¯ã¹ãã¼ã«ãå§ãã§ãã
nnoremap ; : nnoremap : ; vnoremap ; : vnoremap : ;
ãã使ãã³ãã³ãã©ã¤ã³ã¢ã¼ãã«å
¥ãããã®:
ã¨ã
ããã¿ã¤ããããã;
ãå
¥ãæ¿ãã¦ãã¾ãã
ç¹ã«ASCIIé
åãã¼ãã¼ãã ã¨ã:
ã¯ã¿ã¤ã
ãã¥ããã®ã§ãå人çã«å¿
é ã§ãã
nnoremap <Space>h ^ nnoremap <Space>l $
è¡é /è¡æ«ç§»åã®ãã¼ãããããã³ã°ãã¦ãã¾ãã
ã¿ã¤ãæ°ãå¤ããªã£ã¦æ¼ãã¥ãããªã£ã¦ããããªããã¨
æããããããã¾ããããããã©ã«ãã®^
ã$
ã¯ã
<Shift>
ã¨ä¸ç·ã«ãã¼ã ãã¸ã·ã§ã³ããé ããã¼ãæ¼ãå¿
è¦ãããããã
æ¼ãã¥ããå°æãç²å¼ãã¦ãã¾ãã¾ãã
ãããã³ã°ãã¦ãã<Space>h
ã<Space>l
ã¯çæã§ã¿ã¤ã
ã§ãã¦ãå§ãã§ãã
<Space>
ã¯æ¼ããããã®ã§ãVimã§ãã¼ããããã³ã°ããéã
<Space>
ããã¬ãã£ã¯ã¹ãã¼ã¨ãã¦ä½¿ãã¨ä¾¿å©ã§ãã
nnoremap k gk nnoremap j gj vnoremap k gk vnoremap j gj nnoremap gk k nnoremap gj j vnoremap gk k vnoremap gj j
表示è¡ç§»åã§ããgj
ãgk
ã¨ãå®éã®è¡ç§»åã§ããj
ãk
ã
å
¥ãæ¿ãã¦ãã¾ãã
set wrap
ã®è¨å®ããã¦ã1è¡ã表示ä¸ã©ãããã¦ããå ´åã«ã
gj
ãgk
ã¯ã表示ä¸ã®è¡ã§ã®ç§»åãªã®ã§j
ãk
ãã
便å©ãªã¨ããããããå
¥ãæ¿ãã¦ãã¾ãã
nnoremap <Space>/ *<C-o> nnoremap g<Space>/ g*<C-o>
*
ã¯ãã«ã¼ã½ã«ä½ç½®ã®åèªã§åæ¹æ¤ç´¢ãã¾ãã
ããã¯é常ã«ä¾¿å©ãªã³ãã³ãã§ããã使ãã®ã§ããã
*
ã¯ASCIIé
åãã¼ãã¼ãã ã¨ã<Shift>
ãæ¼ããªãã
ãã¼ã ãã¸ã·ã§ã³ããé ããã¼ãã¿ã¤ãããå¿
è¦ãããã®ã§
ã¡ãã£ã¨æ¼ãã¥ããã§ãã
ããã§ã<Space>/
ã«ãããã³ã°ãã¦ãã¾ãã
çæã§ã¿ã¤ãã§ãã¦ãå§ãã§ãã
g*
ã¯ã*
ã¨éããåèªã®ä¸é¨ã«ãããããã¾ãã
ãã¡ããåæ§ã«ãããã³ã°ãã¦ãã¾ãã
nnoremap <expr> n <SID>search_forward_p() ? 'nzv' : 'Nzv' nnoremap <expr> N <SID>search_forward_p() ? 'Nzv' : 'nzv' vnoremap <expr> n <SID>search_forward_p() ? 'nzv' : 'Nzv' vnoremap <expr> N <SID>search_forward_p() ? 'Nzv' : 'nzv' function! s:search_forward_p() return exists('v:searchforward') ? v:searchforward : 1 endfunction
n
ãN
ã¯ãæå¾ã®/
ã?
ãç¹°ãè¿ãã¾ãã
/
ã§æ¤ç´¢ããå ´åã¨ã?
ã§æ¤ç´¢ããå ´åã§ã
n
ã¨N
ã§ç§»åããæ¹åãç°ãªãã®ãä¸ä¾¿ã§ããã
ãã®ããã/
�
ã®ã©ã¡ãã§æ¤ç´¢ããå ´åã§ããn
ã§åæ¹æ¤ç´¢
N
ã§å¾æ¹æ¤ç´¢ããããè¨å®ãã¦ãã¾ãã
nnoremap <Space>o :<C-u>for i in range(v:count1) \| call append(line('.'), '') \| endfor<CR> nnoremap <Space>O :<C-u>for i in range(v:count1) \| call append(line('.')-1, '') \| endfor<CR>
ã¤ã³ãµã¼ãã¢ã¼ãã«å
¥ããã«ãã«ã¼ã½ã«è¡ã®ä¸ãããã¯ä¸ã«ç©ºè¡ãæ¿å
¥ãã¾ãã
count
ã«ã対å¿ãã¦ããã®ã§ã10<Space>o
ã§10è¡æ¿å
¥ã§ãã¾ãã
空è¡ãæ¿å ¥ãã+αãåèãã ããã
nnoremap <silent> tt :<C-u>tabe<CR> nnoremap <C-p> gT nnoremap <C-n> gt
ã¿ãé¢é£ã®ãã¼ãããã³ã°ã§ãã
ç§ã¯ã¿ããå¤ç¨ããã®ã§ãæ°è¦ã¿ãã®ä½æãã¿ã¤ãããããtt
ã«å²ãå½ã¦ã¦ãã¾ãã
ã¾ããã¿ã移åã¯ãè¤æ°ã¿ãã確èªããªãã移åããå ´åã«ã
gtgtgtgt
ã¨ã¿ã¤ãããããã®ãã¿ã¤ããã¥ããã£ããã
<C-p>
ã<C-n>
ã«ãããã³ã°ãã¦ãã¾ãã
nnoremap <silent> <Esc><Esc> :<C-u>nohlsearch<CR>
set hlsearch
ã§ãæ¤ç´¢æã«ãããããããã¹ãã強調表示ããã¾ãã
æ¤ç´¢ããã¹ãã®å¼·èª¿è¡¨ç¤ºã¯ä¾¿å©ãªã®ã§ãããæ¤ç´¢ãçµãã£ãå¾ã¯
強調表示ããªãã«ãããã®ã§ãnohlsearch
ã³ãã³ãã使ãã¾ãã
nohlsearch
ã³ãã³ãã¯ã¡ããã¡ãã使ãããã<Esc><Esc>
ã«ãããã³ã°ãã¦ãã¾ãã
nnoremap ZZ <Nop> nnoremap ZQ <Nop> nnoremap Q gq
å±éºãªãã¼ãç¡å¹ or å¥ã®ãã¼ã«ãããã³ã°ãã¦ãã¾ãã
ZZ
ãZQ
ã¯ãããããããã¡ã¤ã«ãä¿åãã¦çµäºãã
ããã¡ã¤ã«ãä¿åããã«çµäºãã§ãã
ã¿ã¤ãããããã¦ä¾¿å©ã ã£ããããã®ã§ããããã¾ãã«
ã¿ã¤ããããããZZ
ãã¿ã¤ãããã¤ããã誤ã£ã¦ZQ
ã
ã¿ã¤ããã¦æ²ããæ°æã¡ã«ãªããã¨ãå¤ã
ããã¾ãã
ãã®ããã使ããªããã空ããã<Nop>
ã«æå®ãã¦ã¾ãã
ã¾ããQ
ã¯Exã¢ã¼ãã«åãæ¿ãã¾ãã
é常ã®ä½¿ç¨ã§Exã¢ã¼ãã使ããã¨ã¯ã»ã¨ãã©ãªããã
ããã¹ããæ´å½¢ããgq
ã«ãããã³ã°ãã¦ãã¾ãã
onoremap aa a> onoremap ia i> onoremap ar a] onoremap ir i] onoremap ad a" onoremap id i"
ããã¹ããªãã¸ã§ã¯ãã§ãi)
ãi}
ãªã©ã¯ã
ib
ãiB
ã«å²ãå½ã¦ããã¦ãã¦ãi)
ãi}
ã¨ã¿ã¤ãããã®ã¨
æ¯è¼ãã¦ã¿ã¤ãããããã®ã§ããã
i>
ãi]
ãi"
ã¯ãã®ã¾ã¾è¨å·ãã¿ã¤ãããå¿
è¦ããã
æ¼ãã¥ãããããä¸è¨ã®ããã«ãããã³ã°ãã¦ãã¾ãã
ãã®ãã¼ãããã³ã°ã®å¯ä½ç¨ã¨ãã¦ãä¸è¨ããã¹ããªãã¸ã§ã¯ã ã¯ãASCIIé åãã¼ãã¼ãã§ãJISé åãã¼ãã¼ãã§ãåããã¼ã§ æä½ããäºãã§ããããã«ãªãã¾ãã
inoremap jk <Esc>
ãã¼ãã«ã¢ã¼ãã«æ»ãããã®<Esc>
ã¯ã¿ã¤ããã¥ããã®ã§ã
jk
ã«ãããã³ã°ãã¦ãã¾ãã
jk
ã§ããã°ãç·¨éã§jkãå
¥åãããã¨ã¯ã»ã¨ãã©ãªãã§ããã
誤ã£ã¦ãã¼ãã«ã¢ã¼ãã§ã¿ã¤ããã¦ãä¸ä¸ç§»åããã ãã§ãã¿ã¾ãã
ä½ãããã¼ã ãã¸ã·ã§ã³ã移åããã«ã¿ã¤ãã§ããã®ã§
é常ã«ã¿ã¤ãããããã§ãã
ãã®ãã¼ãããã³ã°ã¯äººãé¸ã¶ã¨æãã¾ãã
nnoremap gs :<C-u>%s///g<Left><Left><Left> vnoremap gs :s///g<Left><Left><Left>
ç½®æã³ãã³ãã¯å¤ç¨ããã®ã§ããããã¡ãã¡ã¿ã¤ãããã®ã
é¢åãªã®ã§ãgs
ãã¼ã«ãããã³ã°ãã¦ãã¾ãã
ããã§ãgs
ã¨ã¿ã¤ããããã¨ã§ãå³åº§ã«ç½®æããæåå
ã®å
¥åã«ç§»ãã¾ãã
cnoremap <C-f> <Right> cnoremap <C-b> <Left> cnoremap <C-a> <C-b> cnoremap <C-e> <C-e> cnoremap <C-u> <C-e><C-u> cnoremap <C-v> <C-f>a
ã³ãã³ãã©ã¤ã³ã¢ã¼ãã§ã®ç§»åãEmacsã©ã¤ã¯ãªãã¼ã«è¨å®ãã¦ãã¾ãã
ã¾ã¨ã
以ä¸ããã¼ãã®ããããããããããã®vimrcã®ãç´¹ä»ã§ããã
çããããèªåã ãã®ãã¼ãã®ããããããããããã®vimrcããä½ã£ã¦ã¿ã¦ã¯ãããã§ããããï¼
æ¬é¡ã¨ã¯ããã¾ãããVimã¬ãã«ãä¸ããã®ã§vimrcèªæ¸ä¼ã«åå ãããã¨ããããããã¾ããæ¯é±åææ¥23æãããã£ã¦ã¾ãã
ããã§ã¯Vim Advent Calendar 2013ã®171æ¥ç®ãçµããã¾ãã