角かっこのマッピング[[
、]]
、[m
、]m
および同様の
$VIMRUNTIME/ftplugin/python.vim
現在 (2018)は、Python 言語で文書:h ]]
化されているすべての組み込みマッピングを再マップします。:h ]m
マッピングは次のとおりです。
]] Jump forward to begin of next toplevel
[[ Jump backwards to begin of current toplevel (if already there, previous toplevel)
]m Jump forward to begin of next method/scope
[m Jump backwords to begin of previous method/scope
][ Jump forward to end of current toplevel
[] Jump backward to end of previous of toplevel
]M Jump forward to end of current method/scope
[M Jump backward to end of previous method/scope
コメント付きの次のサンプル ソース コードは、さまざまなマッピングを示しています。
class Mapping: # [[[[
def __init__(self, iterable):
pass
def update(self, iterable):
pass
__update = update # []
class Reverse: # [[ or [m[m
def __init__(self, data): # [m
self.data = data
self.index = len(data) # [M
def __iter__(self): # <--- CURSOR
return self # ]M
def __next__(self): # ]m
if self.index == 0:
raise StopIteration
self.index = self.index - 1
return self.data[self.index] # ][
class MappingSubclass(Mapping): # ]] or ]m]m
def update(self, keys, values):
pass
マッピングは、コミットabd468ed0 (2016-09-08)、01164a6546b4 (2017-11-02)、および 7f2e9d7c9cd (2017-11-11)で追加および改善されました。
このファイルの新しいバージョンをまだ持っていない場合は、ダウンロードして に入れることができます~/.vim/ftplugin/python.vim
。このフォルダは よりも優先されます$VIMRUNTIME/ftplugin
。
これらのマッピングが に追加される前に、、、、およびを提供する$VIMRUNTIME
プラグインがありました。さらに、テキスト オブジェクト、、、およびも定義します。python-mode
[[
]]
[M
]M
python-mode
aC
iC
aM
iM
この vim プラグインは、組み込みのものと同様のモーションを提供します。
2.4 Vim motion ~
*pymode-motion*
Support Vim motion (See |operator|) for python objects (such as functions,
class and methods).
`C` — means class
`M` — means method or function
*pymode-motion-keys*
========== ============================
Key Command (modes)
========== ============================
[[ Jump to previous class or function (normal, visual, operator)
]] Jump to next class or function (normal, visual, operator)
[M Jump to previous class or method (normal, visual, operator)
]M Jump to next class or method (normal, visual, operator)
aC Select a class. Ex: vaC, daC, yaC, caC (normal, operator)
iC Select inner class. Ex: viC, diC, yiC, ciC (normal, operator)
aM Select a function or method. Ex: vaM, daM, yaM, caM (normal, operator)
iM Select inner func. or method. Ex: viM, diM, yiM, ciM (normal, operator)
========== ============================
このプラグインは同様のモーションを提供しますが、わずかに変更されています:
標準の Vim 8.0 の「クラス」モーション ("]]"、"[[" など) は、これらがクラス ブロックであるか関数ブロックであるかに関係なく、最初の列から始まるブロックを見つけます。 ("[m"、"]m" など) クラスまたは関数ブロックであるかどうかに関係なく、任意のインデントにあるすべてのブロックを検索します。対照的に、「Pythonsense」クラス モーションは、インデント レベルに関係なく、すべてのクラス定義のみを検索しますが、そのメソッド/関数モーションは、インデント レベルに関係なく、すべてのメソッド/関数定義のみを検索します。
詳細と例はすべてhttps://github.com/jeetsukumaran/vim-pythonsense#stock-vim-vs-pythonsense-motionsにあります。さらに、このプラグインは、テキスト オブジェクトic/ac
(クラス)、if/af
(関数)、id/ad
(docstring) を定義します。
Python のtextobjects に関する議論については、VIM 経由で Python の関数を選択する最速の方法は何ですか? を参照してください。.