That’s the general workflow yeah. Built-in, you have :e
, gf
, :grep
, <c-x>f
and <c-r>%
at your disposal. gf
goes to the file corresponding to your selection (g
is goto and it opens contextual “menu”). Filename are also auto-completed in both insertion and command line mode; when they are not (for example, typing out a local path in insert mode without starting by ./
), you can force kakoune’s completion type to filename using <c-x>f
(<c-x>
is complete and it opens contextual “menu”). Finally, from insertion mode and command mode, you can paste from a register with <c-r>
, with a contextual menu showing up; %
in particular holds the buffer name, which defaults ot the filename.
So for your example, you could have done something along the lines of:
:e <c-r>%<del>h<tab><ret>
to open a new file, paste the name of your current buffer, replace the ‘.c’ with ‘.h’, and open it. The tabulation is for good measure, in case your header file is not right next to your c file, kakoune should still be able to fuzzy find it and tab would select it.
One last built-in way to navigate files is to actually quit kakoune and use the full power of your shell/file explorer/whatever environment. You can start a healdless kakoune server using:
setsid kak -d -s your_session_name
it will persist even with no client attached (you need kill
to end it). So you can :quit
it, do whatever you want, and reopen a client attached to it with:
kak -c your_session_name [file_names_pattern]
That’s particularly helpful to open multiple files at once using a glob pattern or a shell expansion. In your particular case, you could use find
or fdfind
( GitHub - sharkdp/fd: A simple, fast and user-friendly alternative to 'find' ) from the shell.
About filetrees you can literally have one in kakoune piping in (!
) the command tree
. As far as speed is concerned, you can use the full power of a modal text editor to navigate that tree, it beats graphical representation for huge file tree where you at least vaguely know what you’re looking for. You can combine that with mapping shortcuts to make things faster.
Here is how you can make an actionable filetrees in kakoune less than 10 lines of code (excerpt from my kakrc
):
define-command -file-completion -params .. -docstring \
"tree [<arguments>]: execute tree into a scratch buffer, with the following options :
- -f to have full pathnames (easier to gf).
- --charset to have indentation using plain space characters instead of fancy character art (easier to gf, after replacing any fancy character with space).
- whatever arguments provided." \
tree %{
try %{
delete-buffer *tree*
}
edit -scratch *tree*
execute-keys "! tree -f --charset ASCII %arg{@}<ret>%%s^[\h|\-`]+<ret>r<space>gg"
map buffer normal <ret> 'x: goto-file<ret>'
}
Not as pretty as :grep
, but gets the job done. I have something similar with find.