A gripe I have with the default goto-file command is that it doesn’t understand syntax like file:line:column which is often outputted by debuggers (including kakoune’s !).
I’ve looked around and found some promising plugins, which I might link if I find again. They were focused on deciphering line and column numbers, and my current need is to quickly navigate rust’s cargo ouput.
So I made the following script file, which does 2 things:
provide a way to quickly navigate from filename to filename (candidates) (mapped to gF)
decipher one very simple format of file:line:column (overriding gf)
## better gf
map -docstring "file[:line[:column]]" global goto f "<esc>: goto-file<ret>"
define-command -docstring "go to the file corresponding to the current selection" goto-file %{
# TODO add something to the effect of -itersel
evaluate-commands edit -existing %sh{ echo "$kak_selection" | sed 's/:/ /g' }
}
alias global gf goto-file
# TODO use @val{count} if provided
define-command -docstring "go to the next filename candidate" -hidden goto-filename-regex %{
evaluate-commands -draft %{
try %{
edit -existing *gf*
} catch %{
edit -scratch *gf*
# turning the result of ls into a regex
execute-keys '! ls -aF<ret><a-s>i|\Q<a-;><a-;>\E<del><esc>'
# inserting absolute paths (root and home)
execute-keys ',I((?<lt>=\s)~?/[\w\.]<esc>'
# allowing suffixe
execute-keys 'A)[^\s]*<esc>'
}
execute-keys -save-regs '' 'ggx_"/y'
}
}
define-command -docstring "go to the next filename candidate" -hidden goto-filename %{
evaluate-commands -save-regs '/' %{
goto-filename-regex
execute-keys '/<ret>'
}
}
alias global gF goto-filename
define-command -docstring "go to the previous filename candidate. Unstable, might get replaced by count goto-filename" -hidden goto-filename-back %{
evaluate-commands -save-regs '/' %{
goto-filename-regex
execute-keys '<a-/><ret>'
}
}
map -docstring "goto filename" global goto F "<esc>: goto-filename<ret>g"
map -docstring "goto filename" global goto <a-F> "<esc>: goto-filename-back<ret>g"
I’m very curious how other people tackle that problem. I’m not entirely satisfied with what I have now, but for me, it’s a huge improvement over selecting filenames manually.
I’ll join the thread bumping party (and this forum… Hello!).
I recently made one that tries not to shell out. I haven’t battle tested this enough to determine how solid it is, but it’s worked well enough for me so far in the use cases I come across. I found that with-hooks is required for filetype rcs to be loaded. And the Z register is required for resetting the selection before trying the next text object.
I suppose my goto file isn’t in the spirit of going to a line and column number. I just like not having to perfectly select the file’s full string each time. Just put your cursor somewhere in the string and hit gf.
This is cool, the reason I even went to shell was for the situation you have : and if the text isn’t surrounded by a pair character (I spent an unnecessary amount of time trying not to use shell)
I came up with a modification that works when the file name borders asymmetric non-word chars. The trick was to modify (and then restore) the extra_word_chars option to include chars typical to filenames. That way you can simply <a-i>w to select valid file paths. I also remembered that Z saves to the ^ register, not Z lol. I’m not sure if there are file name edge cases that these extra word chars don’t cover (outside of whitespaces in the name).
Should be easy to extend this to work within matching pairs like I had before. The hard part now is somehow getting it to go to files whose names have spaces