Add vim mappings around yapf python formatter
This commit is contained in:
parent
6363c75535
commit
437476694c
@ -1,2 +1,34 @@
|
||||
" Python convention is to use 4 space tabs.
|
||||
setlocal tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
" Python formatting mappings {{{
|
||||
" Supported yapf styles: pep8, google
|
||||
let g:yapf_style='pep8'
|
||||
" A wrapper function to restore the cursor position, window position,
|
||||
" and last search after running a command.
|
||||
function! Preserve(command)
|
||||
" Save the last search
|
||||
let last_search=@/
|
||||
" Save the current cursor position
|
||||
let save_cursor = getpos(".")
|
||||
" Save the window position
|
||||
normal H
|
||||
let save_window = getpos(".")
|
||||
call setpos('.', save_cursor)
|
||||
|
||||
" Do the business:
|
||||
execute a:command
|
||||
|
||||
" Restore the last_search
|
||||
let @/=last_search
|
||||
" Restore the window position
|
||||
call setpos('.', save_window)
|
||||
normal zt
|
||||
" Restore the cursor position
|
||||
call setpos('.', save_cursor)
|
||||
endfunction
|
||||
nmap <leader>ff :call Preserve(
|
||||
\ "silent exec '0,$!yapf --style ".g:yapf_style."'")<CR>
|
||||
" TODO Add mapping for single line formatting
|
||||
" TODO Add mapping for text block formatting
|
||||
" }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user