With the update from November 2017 of $VIMRUNTIME/ftplugin/python.vim
following ft-specific motions are available for the python language
[[
Jump backwards to begin of current/previous toplevel
[]
Jump backwards to end of previous toplevel
][
Jump forwards to end of current toplevel
]]
Jump forwards to begin of next toplevel
[m
Jump backwards to begin of current/previous method/scope
[M
Jump backwards to end of previous method/scope
]M
Jump forwards to end of current/next method/scope
]m
Jump forwards to begin of next method/scope
Example python file
class previous: # [[[[
def method_first:
pass
# ...
def method_last:
pass # []
class current: # [[ or [m...[m[m
def method_first: # [[]m or [m...[m
pass # [[]M or [M...[M
# ...
def method_previous: # [m[m
pass # [M
def method_current: # [m
# CURSOR <---------------------------
pass # ]M
def method_next: # ]m
pass # ]M]M
# ...
def method_last: # ][[m or ]m...]m
pass # ][ or ]M...]M
class previous: # ]] or ]m...]m]m
def method_first:
pass
# ...
def global_func: # ]]]]
pass
This update should be included if your vim patch level is at least 8.0.1256
.
If you can't update but want to use this functionality, you can install the most recent version into the ~/.vim
directory:
$ curl https://raw.githubusercontent.com/vim/vim/master/runtime/ftplugin/python.vim --create-dirs -o ~/.vim/ftplugin/python.vim
This plugin provides similar motions but slightly modified:
The stock Vim 8.0 "class" motions ("]]
", "[[
", etc.), find blocks that begin at the first column, regardless of whether or not these are class or function blocks, while its method/function motions ("[m
", "]m
", etc.) find all blocks at any indent regardless of whether or not these are class or function blocks. In contrast, "Pythonsense" class motions work on finding all and only class definitions, regardless of their indent level, while its method/function motions work on finding all and only method/function definitions, regardless of their indent level.
All details and examples are given at https://github.com/jeetsukumaran/vim-pythonsense#stock-vim-vs-pythonsense-motions.
[[
and]]
, are provided by the default python ftplugin.[[
,]]
,(
,)
,{
and}
.[[
and]]
are useful in some cases but my main problem is I need[]
and][
or something like that, which provides jumps to end of next/previous method/class.]e
solves most of my problems, however some mappings in this plugin seems to be broken like]v
or]>
I'll try to fix them in a fork and publish it. Though I still wonder what was the plugin that provided][
and[]
it was really useful.