Text objects, as in the iw from ciw (“change inner word”), form an important part of your Vim mentalese . This post details those that I find most useful for Python and Django development.

For brevity, the leading a (neumonic: “a”n) or i (neumonic: “inner”), that you combine with the following commands to form the full text-object, are omitted.

From core Vim:

w → a word

→ a word W → a WORD

→ a WORD t → a HTML/XML tag

→ a HTML/XML tag s → a sentence

→ a sentence p → a paragraph

From the (highly recommended) wellle/targets.vim plugin:

, . ; : + - = ~ _ * # / | \ & $ → an area of text delimited by the given character (super useful).

→ an area of text delimited by the given character (super useful). a → a function argument.

Furthermore wellle/targets.vim overrides the built-in text objects to seek to the next occurence of the text-object if the cursor isn’t already within one. This is useful.

From other language-agnostic, third-party text objects:

l → a line (via kana/vim-textobj-line )

→ a line (via ) e → the entire buffer (via kana/vim-textobj-entire ) so you can, say, indent the entire buffer with =ae .

→ the entire buffer (via ) so you can, say, indent the entire buffer with . i → an indented block (via kana/vim-textobj-indent ). This isn’t quite as useful as it sounds for Python work as it stops at a blank line within an indented block – still worth having to hand.

→ an indented block (via ). This isn’t quite as useful as it sounds for Python work as it stops at a blank line within an indented block – still worth having to hand. c → a comment block (via glts/vim-textobj-comment ).

jeetsukumaran/vim-pythonsense provides some Python text objects:

f → a Python function

→ a Python function c → a Python class

→ a Python class d → a Python docstring

For editing Django templates (via mjbrownie/django-template-textobjects ):

db → a {% block ... %}...{% endblock %} block

→ a block di → a {% if ... %}...{% endif %} conditional block

→ a conditional block df → a {% for ... %}...{% endfor %} for loop block

→ a for loop block dv → a {{ ... }} variable

→ a variable dt → a {% tagname ... %} tag

Several of the above plugins are built using kana/vim-textobj-user , which provides a simple framework for building your own text-objects.

Useful references:

Related articles: