Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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 a command to copy the filename and cursor line number in the clipboard. #2985

Closed
grv07 opened this issue Jul 6, 2022 · 10 comments
Closed

Comments

@grv07
Copy link
Contributor

grv07 commented Jul 6, 2022

I am not sure If we already have something like that or not.
I like to have a command that will copy the file path from the workspace("workspace/dir1/dir/2/file.rs:567") so we can share it with other team members and they can open it like hx workspace/dir1/dir/2/file.rs:567

Is it too much to ask in the same request to add this feature in the file finder too where we can add the line number after file with : that will preview the file from the line number?

@pppKin
Copy link
Contributor

pppKin commented Jul 6, 2022

Maybe we could first add a command to copy path info into a register.

@archseer
Copy link
Member

archseer commented Jul 6, 2022

Seems a bit niche, I copy the file path straight from the status line. How is this exposed in kakoune/vim?

@archseer
Copy link
Member

archseer commented Jul 6, 2022

We could have a special register that always holds the current file name?

@pppKin
Copy link
Contributor

pppKin commented Jul 6, 2022 via email

@pppKin
Copy link
Contributor

pppKin commented Jul 7, 2022

How is this exposed in kakoune/vim?

I did a quick search on this and vim is using a read-only register % to hold the filename.

@EpocSquadron
Copy link
Contributor

Kakoune has that special register as well, accessible in prompts via Ctrl-r.

@MageJohn
Copy link

I would love to see a % register implemented. While the filename can be copied manually from the statusline, this has two main limitations. First it usually requires switching to the mouse, and second it means you only get the path relative to Helix's current working directory, not an absolute one. Access to the absolute filename would greatly increase the ease of doing work in a different program with a file you've just been editing in Helix.

The use case that drove me to find this issue was wanting to quickly run a git blame on the file I was editing. One day this use case may be covered by an extension, but even then there may be other ad-hoc uses for easy access to the current filename.

@grv07
Copy link
Contributor Author

grv07 commented Oct 25, 2022

Personally, I think it’s too restricted to take up a register for a specific purpose. I mean what if we want to add commands to copy the full path, relative path, filename without extension, etc ;)

After looking into the changes I think it is easy to add a command and map it with keybinding instead of running a function to copy file names on every focus change.

@larsblumberg
Copy link

larsblumberg commented Nov 9, 2022

Helix-editor is great for its consistency.

  • The / register holds the last search text b/c typing / starts a search.
  • The : register holds the last command b/c typing : starts the command input

I'd like to add to above list:

  • The % register holds the current file path b/c typing % selects the entire file. The file path should be relative to the current working directory, no shenanigans here.

With this consistency in place one can easily copy the current buffer's file via:
:sh␣cp␣ + Ctrl+R + % + ␣<file destination> + RETURN

@Boscop
Copy link

Boscop commented Apr 14, 2023

Indeed it would be nice if we had different ways to copy the file name/path in different ways, e.g.:

VS Code has:
image

Sublime Text has:
image

In addition to these, it would also be super useful to have a way to copy the current line number, AND a way to copy both the relative file path + line number in the format <rel_path>:<line_num> (also <rel_path>:<line_num>:<column_num>), for easily sending a colleague this location over Slack (!), and it would also be nice to have a way to easily jump to such a location, like VS Code and Sublime Text have, in case a colleague sends me such a location via chat OR in case I copy this location from a panic stacktrace / log file / compiler error output, which is a very common use case.
It would be best if there was just one keyboard shortcut that we have to remember that opens a sub-menu that lets users choose from all the available options to copy the rel/abs file path/name/dir/remote-url, + line/line:col.
Because line & col can make sense being appended onto rel path, abs path, file name (maybe even remote URL?), it could be a multi-stage menu:

 --- Copy to system clipboard --------
| r   relative file path
| a   absolute file path
| u   remote file URL
| n   file name
| d   file directory
| l   line number only
| c   line:column only
 -------------------------------------

and if the user has chosen either r/a/u, there is a second menu:

 --- Append line/column location? -------
| l   line
| c   line:column
| n   none
 ----------------------------------------

Currently there's no way to navigate to a path:line:column location with Helix though, right?
This touches on a related topic, navigation:
E.g. I like VS Code's design of using the same navigation/command bar for everything, depending on the prefix:
Ctrl+p opens this (at least with my Sublime Text keybindings in VS Code):
image
This bar can be used to navigate by entering either a file name / path / path:line or path:line:col, and in case there are multiple (fuzzy) matches, it displays all and the user can select one to navigate to.
Ctrl+g opens this bar with a : prefix already present, ready to enter a line number or line:col.
Ctrl+Shift+p opens this bar with a > prefix already present, ready to enter commands.
Ctrl+Shift+r opens this bar with a # prefix already present. (Search within all symbols of the current project. If the cursor in the currently opened file is on a symbol identifier, this identifier is copied into the bar's edit field after # and this text is selected, so that if the user starts typing (to search for another symbol), it'll be overwritten.)
image

Ctrl+r opens this bar with a @ prefix already present. (Search within symbols of current file. (By typing : the symbols will be grouped by category, which is also useful.) The name of the function whose body the cursor is currently in, is the symbols that is selected in the list when the bar opens, but the bar's edit field only contains @.)
image

It would be nice if we had a similar unified navigation bar in Helix :)

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
7 participants