" 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 ff :call Preserve( \ "silent exec '0,$!yapf --style ".g:yapf_style."'") " TODO Add mapping for single line formatting " TODO Add mapping for text block formatting " }}}