Skip to content

Instantly share code, notes, and snippets.

@kosei27
Created August 29, 2011 12:45
Show Gist options
  • Save kosei27/1178317 to your computer and use it in GitHub Desktop.
Save kosei27/1178317 to your computer and use it in GitHub Desktop.
Centering text..
" .@:CenteringText {{{1
"
" 例えば、「|」にカーソルがある状態で、
"
" /* ------------------------------
" * | hoge
" * ------------------------------ */
"
" :call CenteringText(30)といった感じで、
" 引数に「-」の数を指定して実行すると、
"
" /* ------------------------------
" * hoge
" * ------------------------------ */
"
" という風にセンタリングされます。。。
function! CenteringText(width)
set expandtab
" カーソル位置から行頭まで削除してビジュアルモードに移行。
silent normal d0v
execute "center".a:width
execute "normal \<Esc>"
" 最初に削除したテキストを行頭に追加して戻す。
silent normal 0P
set noexpandtab
endfunction
nmap <Space>ct :<C-u>call CenteringText()<Left>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment