From 45abb66c0a8befddc09a2431188b3e5a92ba1bf1 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 26 Jul 2026 10:37:50 -0500 Subject: [PATCH] Add Jump From Section To Section as a Zed TIL --- README.md | 3 ++- zed/jump-from-section-to-section.md | 30 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 zed/jump-from-section-to-section.md diff --git a/README.md b/README.md index 1ef3795..e3f6cbe 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/). For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter). -_1838 TILs and counting..._ +_1839 TILs and counting..._ See some of the other learning resources I work on: @@ -2149,6 +2149,7 @@ If you've learned something here, support my efforts writing daily TILs by ### Zed +- [Jump From Section To Section](zed/jump-from-section-to-section.md) - [Open Picker To Switch Between Projects](zed/open-picker-to-switch-between-projects.md) ### Zod diff --git a/zed/jump-from-section-to-section.md b/zed/jump-from-section-to-section.md new file mode 100644 index 0000000..aa21758 --- /dev/null +++ b/zed/jump-from-section-to-section.md @@ -0,0 +1,30 @@ +# Jump From Section To Section + +[Zed](https://zed.dev/) has some [Vim-mode](https://zed.dev/docs/vim) navigation +capabilities powered by +[`tree-sitter`](https://tree-sitter.github.io/tree-sitter/)'s syntax parsing and +representation (AST). You can perform all the standard Vim motion on _text +objects_ which are defined pieces of syntax that `tree-sitter` exposes. + +While working on a Python file that was made up of many classes recently, I kept +finding myself holding the `k` key to go up to view something in one class and +then the `j` key to go back down. This is not the Vim way. There are much more +effective motions. + +For instance, `[[` and `]]` are motions to the jump the start of the previous +and next _section_, respectively. + +In a Python file, `tree-sitter`'s AST representation marks classes and top-level +methods as _sections_. As I need to jump up to the previous class, I can hit +`[[` and then when I'm ready to return back down to the next class I can hit +`]]`. + +There is also `[]` and `][` to jump to the _end_ of the previous and next +section, respectively. Something about those combinations doesn't mesh well with +my muscle memory though, so I will jump to the previous or next section head and +then hit `k` a couple times to get to that section end. + +This works in all kinds of files regardless of what the _section_ text object +means for that file. A markdown file has headings (`#`, `##`, `###`, ...) which +become section boundaries. I can quickly navigate the body of a markdown file +with these section motions.