Hi all,
I've patched the python.vim ftplugin in order it to support [[,]],]m,[m
movements in visual mode also. The patch simplifies the logic of the previous
implementation by using the search() function instead of user-oriented commands.
There are a couple of minor improvements also:
* Explicitly check executable('pydoc') == 1 (to avoid the -1 trap).
* Expand a couple of tabs to spaces to normalize indentation a bit.
Hope you find it useful. I tried to contact the maintainer before but to no
avail so I'm submitting this directly to this list.
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 66783b5ca11f2c4ec6a76cf666dadd48d475b58b 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 | 46 +++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/runtime/ftplugin/python.vim b/runtime/ftplugin/python.vim
index 75c7e87..3c0eb2e 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,34 @@ 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 = (a:back ? '' : '\n') . pattern
+ endif
+ 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 +56,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