klen/python-mode — pull request #453 by WayneYe (2014-07-11 10:11:09+00:00)
Title: Revise readme to guide users customize key bindings

This is a humble pull request, to give users a quick customization information, otherwise for people who have key conflicts with `r`, `g`, etc, will be able to quickly customize the shortcuts themselves.

Take me as an example, I used r to do selected string replacement, by having the following contents in my `vimrc`:

function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction

function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"

let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")

if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif

let @/ = l:pattern
let @" = l:saved_reg
endfunction

" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap * :call VisualSelection('f')
vnoremap # :call VisualSelection('b')
" When I press r I can search and replace the selected text
vnoremap r :call VisualSelection('replace')

I read the source code and found default key shortcuts definition is located in: `python-mode/plugin/pymode.vim`, then I managed to override the default key bindings, this is indeed less convenient for users like me, thus I enhanced the readme.rst to include Customization information, please consider approve my pull request, thank you and appreciate your great work for this awesome plugin:)