Skip to content

find_and_replace

The community/tags/find_and_replace directory contains files that provide generic find and replace functionality for Talon.

The core logic is defined in the find_and_replace.py file. This file defines a Talon module tag user.find_and_replace which can be used to enable the find and replace commands. It also defines a class Actions which provides several actions that can be used to perform find and replace operations. These actions are:

  • find_everywhere(text: str): Finds the given text across the project.
  • find_toggle_match_by_case(): Toggles case sensitivity for find operations.
  • find_toggle_match_by_word(): Toggles whole word matching for find operations.
  • find_toggle_match_by_regex(): Toggles regular expression matching for find operations.
  • replace(text: str): Search and replace for text in the active editor.
  • replace_everywhere(text: str): Search and replace for text across the entire project.
  • replace_confirm(): Confirms replace at the current cursor position.
  • replace_confirm_all(): Confirms replace all.
  • select_previous_occurrence(text: str): Selects the previous occurrence of the text in the editor.
  • select_next_occurrence(text: str): Selects the next occurrence of the text in the editor.

The find_and_replace.talon file provides voice commands that use the actions defined in find_and_replace.py. It enables the commands when the user.find_and_replace tag is active, and also enables the user.find tag. Some of the key commands include:

  • hunt all: Uses find_everywhere action to find text across project.
  • hunt all <user.text>: Finds the specified text across the project.
  • hunt case: Toggles case matching.
  • hunt word: Toggles whole word matching.
  • hunt expression: Toggles regex matching.
  • replace this [<user.text>]: Replaces text in the active editor.
  • replace all: Replaces text in the entire project
  • replace <user.text> all: Replaces the specified text across the entire project
  • replace confirm that: Confirms the replace operation.
  • replace confirm all: Confirms all replace operations.

There are also several "quick replace" commands that mirror functionality in editors like JetBrains products which are built on the select/replace/navigate actions. Some examples of these commands are:

  • clear last <user.text> [over]: Selects the previous occurrence of the text and deletes it.
  • clear next <user.text> [over]: Selects the next occurrence of the text and deletes it.
  • comment last <user.text> [over]: Selects the previous occurrence of the text and toggles comments on that line.
  • comment next <user.text> [over]: Selects the next occurrence of the text and toggles comments on that line.
  • go last <user.text> [over]: Selects the previous occurrence of the text and moves the cursor to the end of it.
  • go next <user.text> [over]: Selects the next occurrence of the text and moves the cursor to the end of it.
  • paste last <user.text> [over]: Selects the previous occurrence of the text and pastes clipboard at the end of the selection.
  • paste next <user.text> [over]: Selects the next occurrence of the text and pastes clipboard at the end of the selection.
  • replace last <user.text> [over]: Selects the previous occurrence of the text and pastes the clipboard to replace it.
  • replace next <user.text> [over]: Selects the next occurrence of the text and pastes the clipboard to replace it.
  • select last <user.text> [over]: Selects the previous occurrence of the text.
  • select next <user.text> [over]: Selects the next occurrence of the text.
  • The same commands with clip instead of <user.text> uses the current clipboard text for the find.

These files work together by defining the actions in Python and then binding them to voice commands in Talon. The tag system allows the commands to be enabled on a per-context basis as needed.