▲ | christophilus 3 days ago | |
How do you create a new file deep in a nested folder? In Helix, I think I used touch from a new terminal, but that’s a pain with deep folder hierarchies when I’m already in the correct slot in my editor. | ||
▲ | mechanicum 3 days ago | parent [-] | |
The % register contains the path for the current buffer, you can insert that into prompt commands with <C-r>%. <C-w> at the command prompt deletes the last word, which in this case will be the filename of the current buffer, leaving the directory path. So: :o <C-r>%<C-w>new-filename<ret> Would open a new buffer at /path/to/the/previous/buffer/new-filename. The file isn’t created on disk until you explicitly write, so :w! to save the first time. If you literally just wanted to create a new file instead of opening a buffer, you could do that from inside Helix with :run-shell-command (aliases sh or !) instead of another terminal: :sh touch <C-r>%<C-w>new-filename<ret> The :o method has the advantage of LSP integration. For example, when I create a new .clj file that way in a Clojure project, the new buffer is pre-populated with the appropriate (ns) form, preselected for easy deletion if I didn’t want it. |