Created
October 6, 2012 05:58
-
-
Save kawakami-o3/3844156 to your computer and use it in GitHub Desktop.
インデント処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 実現したい機能 | |
" * >>, << でインデント調整 | |
" * ^で先頭へ | |
" * リターンで">"を自動挿入 | |
" * 言語用自動インデント機能の挿入 | |
" Ref. | |
" http://www.ibm.com/developerworks/jp/linux/library/l-vim-script-1/ | |
" http://www.ibm.com/developerworks/jp/linux/library/l-vim-script-2/ | |
" http://nanasi.jp/articles/code/screen/cursor.html | |
" | |
let s:code_head = "> " | |
let s:indent = " " | |
function! s:GetIndent() | |
return matchstr(getline('.'), '^' . s:code_head . '\s*') | |
endfunction | |
function! s:MoveHead() | |
call cursor(line('.'), 1+strlen(s:GetIndent())) | |
endfunction | |
function! s:ShiftRight() | |
execute "s/^" . s:code_head . "/" . s:code_head . s:indent . "/" | |
call s:MoveHead() | |
endfunction | |
function! s:ShiftLeft() | |
if strlen(s:GetIndent()) > strlen(s:code_head) | |
execute "s/^" . s:code_head . s:indent . "/" . s:code_head . "/" | |
call s:MoveHead() | |
endif | |
endfunction | |
function! s:RetWithAutoInsert() | |
return match(getline('.'),'^'.s:code_head) == -1 ? "\<CR>" : "\<CR>" . s:code_head | |
endfunction | |
nnoremap <silent> >> :call <SID>ShiftRight()<CR> | |
nnoremap <silent> << :call <SID>ShiftLeft()<CR> | |
nnoremap <silent> ^ :call <SID>MoveHead()<CR> | |
inoremap <silent> <CR> <C-R>=<SID>RetWithAutoInsert()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment