Here is an updated patch with a couple of improvements: 1. Reach BOF/EOF when there are no more class/method text objects remaining.
2. In visual mode select the object up to its beginning/end without matching the first line/char of the next object (I think it's not difficult to implement the omap version from here, but I don't have the time to do it right now). Cheers -- Carlos -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
>From 48aa0fa45b64e87b56d4442c2e1e3257d068ec02 Mon Sep 17 00:00:00 2001 From: memeplex <[email protected]> Date: Fri, 31 Jul 2015 12:31:37 -0300 Subject: [PATCH] Python plugin: movements in visual mode. --- runtime/ftplugin/python.vim | 47 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/runtime/ftplugin/python.vim b/runtime/ftplugin/python.vim index 75c7e87..8563749 100644 --- a/runtime/ftplugin/python.vim +++ b/runtime/ftplugin/python.vim @@ -1,8 +1,8 @@ " Vim filetype plugin file " Language: python " Maintainer: Johannes Zellner <[email protected]> -" Last Change: 2014 Feb 09 " Last Change By Johannes: Wed, 21 Apr 2004 13:13:08 CEST +" Last Change: Fri Jul 31 12:29:55 ART 2015 ([email protected]) if exists("b:did_ftplugin") | finish | endif let b:did_ftplugin = 1 @@ -21,28 +21,35 @@ setlocal omnifunc=pythoncomplete#Complete set wildignore+=*.pyc -nnoremap <silent> <buffer> ]] :call <SID>Python_jump('/^\(class\\|def\)')<cr> -nnoremap <silent> <buffer> [[ :call <SID>Python_jump('?^\(class\\|def\)')<cr> -nnoremap <silent> <buffer> ]m :call <SID>Python_jump('/^\s*\(class\\|def\)')<cr> -nnoremap <silent> <buffer> [m :call <SID>Python_jump('?^\s*\(class\\|def\)')<cr> +nnoremap <silent> <buffer> ]] :<C-U>call <SID>Python_jump(0, 0, '')<CR> +nnoremap <silent> <buffer> [[ :<C-U>call <SID>Python_jump(1, 0, '')<CR> +nnoremap <silent> <buffer> ]m :<C-U>call <SID>Python_jump(0, 0, '\s*')<CR> +nnoremap <silent> <buffer> [m :<C-U>call <SID>Python_jump(1, 0, '\s*')<CR> + +vnoremap <silent> <buffer> ]] :<C-U>call <SID>Python_jump(0, 1, '')<CR> +vnoremap <silent> <buffer> [[ :<C-U>call <SID>Python_jump(1, 1, '')<CR> +vnoremap <silent> <buffer> ]m :<C-U>call <SID>Python_jump(0, 1, '\s*')<CR> +vnoremap <silent> <buffer> [m :<C-U>call <SID>Python_jump(1, 1, '\s*')<CR> if !exists('*<SID>Python_jump') - fun! <SID>Python_jump(motion) range - let cnt = v:count1 - let save = @/ " save last search pattern - mark ' - while cnt > 0 - silent! exe a:motion - let cnt = cnt - 1 - endwhile - call histdel('/', -1) - let @/ = save " restore last search pattern - endfun + fun! <SID>Python_jump(back, visual, ws) + let n = v:count1 + let pattern = '^' . a:ws . '\(class\|def\)' + if a:visual + normal gv + let pattern = '\n' . pattern + endif + let pattern = '\(\%^\|\%$\|' . pattern . '\)' + mark ' + for _ in range(1, n) + call search(pattern, 'W' . (a:back ? 'b' : '')) + endfor + endfun endif if has("browsefilter") && !exists("b:browsefilter") let b:browsefilter = "Python Files (*.py)\t*.py\n" . - \ "All Files (*.*)\t*.*\n" + \ "All Files (*.*)\t*.*\n" endif " As suggested by PEP8. @@ -50,11 +57,7 @@ setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 " First time: try finding "pydoc". if !exists('g:pydoc_executable') - if executable('pydoc') - let g:pydoc_executable = 1 - else - let g:pydoc_executable = 0 - endif + let g:pydoc_executable = executable('pydoc') == 1 endif " If "pydoc" was found use it for keywordprg. if g:pydoc_executable -- 2.4.5
