Skip to content

How to move to function/class name instead of keyword #753

Answered by kiyoon
rbhanot4739 asked this question in Q&A
Discussion options

You must be logged in to vote
  1. Run :InspectTree in a python file.
  2. Press o in the tree to open a query editor
  3. Write a query to select a function name. I'll call it @function.name
  1. Once you have a query ready, put it in your ~/.config/nvim/after/queries/python/textobjects.scm
; extends
(function_definition
  name: (_) @function.name)

This is your custom query.

Note

If you name it to @function.name, it will prefer to select the range within @function.outer. So even inside a function body, if you want to change the function name, you can do it and it will look backwards to find the name.

If you don't like this behaviour, name it to @function_name or something else.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rbhanot4739
Comment options

Answer selected by rbhanot4739
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants