[from now] 2013/06/06 12:28:08

diff --git a/.vimrc b/.vimrc
index 0f3a37f..4c89171 100644
--- a/.vimrc
+++ b/.vimrc
@@ -70,6 +70,7 @@
 "
 "}}}

+
 "========================================
 " Vundle
 "========================================
@@ -116,6 +117,7 @@ filetype plugin indent on

 "}}}

+
 "========================================
 " General
 "========================================
@@ -203,6 +205,7 @@ highlight StatusLineNC   ctermfg=238 ctermbg=253 guifg=#455354 guibg=fg

 "}}}

+
 "========================================
 " Mapping
 "========================================
@@ -223,15 +226,14 @@ nnoremap            <C-k><C-n> :bn<CR>
 nnoremap  <silent>  <C-k><C-d> :call g:wipeout_tlist_buffer()<CR>:bw!<CR>
 nnoremap            <C-k><C-k> @q
 nnoremap            Q          q
-" nnoremap            q          :close<CR>
 nnoremap  <silent>  q          :call g:wipeout_tlist_buffer()<CR>:bw!<CR>
+" nnoremap            q          :close<CR>
 nnoremap            ;          :
 nnoremap            ,          <C-w><C-w>
 nnoremap            -          20<C-w>+
 nnoremap            <Space>q   :q!<CR>
 nnoremap            <Space>,   :e      $MYVIMRC<CR>
 nnoremap            <Space>5   :source $MYVIMRC<CR>
-nnoremap            <Space>l   :w<CR>:!uncrustify --no-backup -c ~/.uncrc %<CR>:e<CR>
 inoremap            <C-b>      <Left>
 inoremap            <C-f>      <Right>
 inoremap            <C-e>      <End>
@@ -248,8 +250,10 @@ cnoremap            <Down>     <C-n>
 " スラッシュの検索を楽にする
 cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/'

+
 "}}}

+
 "========================================
 " Plugins
 "========================================
@@ -363,6 +367,8 @@ function! s:vimfiler_settings()
   nmap <silent><buffer> q             <Plug>(vimfiler_exit)
 endfunction

+
+
 "****************************************
 " neocomplcache
 " http://www.karakaram.com/vim/neocomplcache/
@@ -420,4 +426,49 @@ endfunction
 " complete tags using omnifunc
 " let g:use_zen_complete_tag = 1

+"****************************************
+" uncrustify
+autocmd FileType cpp nnoremap <silent><buffer> <Space>l :call Uncrustify('cpp')<CR>
+
+" http://stackoverflow.com/questions/12374200/using-uncrustify-with-vim/15513829#15513829
+function! Preserve(command)
+  " Save the last search.
+  let search = @/
+
+  " Save the current cursor position.
+  let cursor_position = getpos('.')
+
+  " Save the current window position.
+  normal! H
+  let window_position = getpos('.')
+  call setpos('.', cursor_position)
+
+  " Execute the command.
+  execute a:command
+
+  " Restore the last search.
+  let @/ = search
+
+  " Restore the previous window position.
+  call setpos('.', window_position)
+  normal! zt
+
+  " Restore the previous cursor position.
+  call setpos('.', cursor_position)
+endfunction
+
+" Specify path to your Uncrustify configuration file.
+let g:uncrustify_cfg_file_path =
+    \ shellescape(fnamemodify('~/.uncrc', ':p'))
+
+" Don't forget to add Uncrustify executable to $PATH (on Unix) or %PATH% (on Windows) for this command to work.
+function! Uncrustify(language)
+  call Preserve(':silent %!uncrustify'
+      \ . ' -q '
+      \ . ' -l ' . a:language
+      \ . ' -c ' . g:uncrustify_cfg_file_path)
+endfunction
+
+
+
 "}}}