Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Command declarations - [d]eclarations (supported languages only)

Shows declarations/definitions, for supported languages and allows searching by name, as well as parent-level filtering.

  • ::o the “owner” flag can show the declaration it belongs to, for example the class a matched method belongs to.
  • ::b the “body” flag shows the lines that belong to the declaration.

Example: declarations matching init.

rxedit pysample.py d::__init__::

Output:

def do_init(func):
    def __init__(self, name: str):

show the owner and filter only function declarations with wt=f.

rxedit sample.rs d::message::wt=f.o

Output:

fn make_message() -> String {
fn print_message(message: &str) {
mod tests {
    fn always_pass_message(){

same as above, but filter out functions that belong to parents matching test

rxedit sample.rs d::--test/message::wt=f.o

Output:

fn make_message() -> String {
fn print_message(message: &str) {

You could also have a positive parent test using d::test/message::.

Declarations

NameFormatExampleDescription
show_bodybd::::bbody of the definition
show_ownero::oshow “owner” of the line
where_typewt=([a-z]+)(?:.|/|$)::wt=f/ (shows only function) only show some types of declarations
insensitivei::icase-insentive search
afterA(\d+)::A16Show NUM lines after each match.
beforeB(\d+)::B5Show NUM lines before each match.
contextC(\d+)::C5Show NUM lines before and after each match.
fixed_stringF::Ftreat search as regular string, not a regex
use_grep_shortcodesg::gexpands shortcodes (..→.*, ~~s.→ +)
no_use_grep_shortcodesG::Gdoes not expand grep shortcodes
show_ownero::oshow “owner” of the line
set keysk=([a-z]+)(?:.|/|$)::sk=important/set key to a value that can be used with wk=. in later commands
where_keywk=([a-z]+)(?:.|/|$)::wk=mykey/puts an extra criteria to other commands
where_linenumwl=([-0-9A-Ca-chtHT,.]+)::wl=..5,8,-1/limit line number range

Notes:

Declarations are available when the file extension is recognized as a supported language. If not, this will become a noop.

Source parsing is done via tree-sitter which provides contextual knowledge such as:

  • whether a declaration is nested under a parent.
  • which lines of code “belong” to a given declaration, giving the same capabilities as a folding editor.
  • multi-line function signatures are displayed as a block
  • the ability to filter by parent name, using ! or -- for negation and / for level.

Search matching

Note that only the name of the declaration is matched against.

Since names are alphanumeric this means grep shortcodes are limited to OR (using | or ,) and WILDCARD (..). But also that the searching is also clever enough to support both positive and negative matching, so 'd::split--regex,nega' looks for names with split but not regex or nega.

Standard search flags like A2 or sk=mykey. are also supported by declarations.

where type, wt=xyz flag

Each language also supports filtering by declaration type using the wt= flag.
::wt=fs on rust means search only fn and struct names, whereas d::::wt=c would show only Python class definitions.

SEE ALSO

shortcodes, chaining, languages, noop