Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add % current file register #5577

Closed
wants to merge 2 commits into from

Conversation

pickfire
Copy link
Contributor

@pickfire pickfire commented Jan 18, 2023

Useful to open files relative to current file.

asciicast

The experience is worse especially on files that have huge paths, like python virtual environment, this allows browsing relative files easier, while being a lot easier to implement compared to find file. #2412

To create new file from current file directory.

:o <C-r>%<C-w>new-file<ret>

Compared to previous method (mouse copy-paste or manually type - and I usually manually type 1-7 directories)

:o <mouse select file name><middle click paste><manually type full path if truncated><C-w>new-file<ret>

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Jan 19, 2023
@archseer
Copy link
Member

Duplicate of #3008 was replaced by #3393

@pickfire
Copy link
Contributor Author

pickfire commented Jan 20, 2023

I think #3393 is slightly different and a lot harder to use compared to this scenario, the user has to type %val{dirname} (16 keystrokes) as compared to <C-r>%<C-w> (6 keystrokes).

The one implemented here is slightly similar to what @QiBaobin implemented, except being pull based (when user select registers) rather than push based (when user change view). Now I just realized I should clear the register if user did :new when I saw vim shows an error when there is no %, I think he didn't implement that too.

@the-mikedavis
Copy link
Member

The register could be useful for prompts and pickers where variable substitution might not be done (it might not make sense to replace variables if the prompt is a regex for example).

Kakoune has a special register for this as well: https://github.com/mawww/kakoune/blob/master/doc/pages/registers.asciidoc#special-registers

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kakoune has an interesting way of passing state like the current buffer name to register functions: registers are defined with an anonymous function that takes Context and returns the value of the register. This is helpful for other special registers like 0..9 acting as regex captures. We don't need to emulate that exactly but I'm curious if we can implement this in a way that's easier to add the other special registers later

Useful to open files relative to current file.
}

impl Registers {
pub fn read(&self, doc: &Document, name: char) -> Option<Vec<String>> {
Copy link
Contributor Author

@pickfire pickfire Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@the-mikedavis I did what you mentioned but now I don't like the API to always return an owned value, we need to keep cloning since the readonly function should return an owned value, unless we get it to return &str which will limit what we can do in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants