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

Is there any way to add an expanded macro to a map? #586

Closed
programandala-net opened this issue Sep 10, 2020 · 5 comments
Closed

Is there any way to add an expanded macro to a map? #586

programandala-net opened this issue Sep 10, 2020 · 5 comments

Comments

@programandala-net
Copy link

I'd like to define a map to go to a variant of the current directory, edited by the user. Such a map is useful when you need to go to another branch of a parallel identical hierarchy, e.g. from </path/to/AAA/0/1/2/3/4/5/> to </path/to/BBB/0/1/2/3/4/5/>. In those cases it's faster to edit the current path than to navigate all the way up and down.

Say I need the following map, but forcing %d:p to be expanded before building the command, in order to let the path be edited by the user:

:nnoremap C :cd %d:p

I've read the documentation about macros, but found no way to expand a macro that way.

@xaizek
Copy link
Member

xaizek commented Sep 10, 2020

There might be a way, but have you seen :cds command? You should be able to use:

:cds AAA BBB

to get the desired behaviour.

@programandala-net
Copy link
Author

I didn't know the cds command. It's not exactly the same than editing the path by hand, but it will be very useful to me in many cases. Thank you.

Nevertheless, I think a syntax to expand macros explicitily would be useful to build commands and let the user edit them before pressing Enter.

@xaizek
Copy link
Member

xaizek commented Sep 11, 2020

Nevertheless, I think a syntax to expand macros explicitily would be useful to build commands and let the user edit them before pressing Enter.

In Vim one does this via expression register, I guess the same is needed here. Would look like:

:nnoremap C :cd <c-r>=expand('%d:p')<cr>

@programandala-net
Copy link
Author

programandala-net commented Sep 11, 2020 via email

@xaizek xaizek added this to the next release milestone Jun 5, 2022
@xaizek
Copy link
Member

xaizek commented Jun 10, 2022

Added expression register in 5ecaeaa, so the mapping above will work in the next release.

Not sure why I didn't mention this way of doing it earlier:

nnoremap C :cd <c-x><c-x>d

@xaizek xaizek closed this as completed Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants