helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
32.53k stars 2.4k forks source link

Add a command to copy the filename and cursor line number in the clipboard. #2985

Closed grv07 closed 5 months ago

grv07 commented 2 years ago

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 commented 2 years ago

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

archseer commented 2 years ago

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

archseer commented 2 years ago

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

pppKin commented 2 years ago

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 ;)

pppKin commented 2 years ago

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 commented 2 years ago

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

MageJohn commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Helix-editor is great for its consistency.

I'd like to add to above list:

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

Boscop commented 1 year ago

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 :)