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

File keymap yank file name #3064

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ This layer is a kludge of mappings, mostly pickers.
| Key | Description | Command |
| ----- | ----------- | ------- |
| `f` | Open file picker | `file_picker` |
| `F` | Enter [File mode](#file-mode) | N/A |
| `b` | Open buffer picker | `buffer_picker` |
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
| `s` | Open document symbol picker (**LSP**) | `symbol_picker` |
Expand All @@ -257,6 +258,20 @@ This layer is a kludge of mappings, mostly pickers.

> TIP: Global search displays results in a fuzzy picker, use `space + '` to bring it back up after opening a file.

#### File mode

This layer is a kludge of mappings, mostly pickers.


| Key | Description | Command |
| ----- | ----------- | ------- |
| `f` | Open file picker | `file_picker` |
| `F` | Open file picker at current working directory | `file_picker_in_current_directory` |
| `d` | Open file picker at current buffer's directory | `file_picker_in_buffer_directory` |
| `c` | Open the helix config.toml file | `config_open` |
| `l` | Open the helix log file | `log_open` |
| `y` | Yank current buffer's file name to clipboard | `yank_file_name_to_clipboard` |

##### Popup

Displays documentation for item under cursor.
Expand Down
38 changes: 38 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ impl MappableCommand {
command_mode, "Enter command mode",
file_picker, "Open file picker",
file_picker_in_current_directory, "Open file picker at current working directory",
file_picker_in_buffer_directory, "Open file picker at buffer's directory",
config_open, "Open the helix config.toml file.",
log_open, "Open the helix log file.",
yank_file_name_to_clipboard, "Yank current buffer's file name to clipboard",
code_action, "Perform code action",
buffer_picker, "Open buffer picker",
symbol_picker, "Open symbol picker",
Expand Down Expand Up @@ -2196,6 +2200,40 @@ fn file_picker_in_current_directory(cx: &mut Context) {
cx.push_layer(Box::new(overlayed(picker)));
}

fn file_picker_in_buffer_directory(cx: &mut Context) {
let (_, doc) = current_ref!(cx.editor);
let cwd = doc.path().and_then(|f| f.parent()).map_or_else(
|| std::env::current_dir().unwrap_or_else(|_| PathBuf::from("./")),
|path| path.into(),
);
let picker = ui::file_picker(cwd, &cx.editor.config());
cx.push_layer(Box::new(overlayed(picker)));
}

fn config_open(cx: &mut Context) {
let _ = cx
.editor
.open(&helix_loader::config_file(), Action::Replace);
}

fn log_open(cx: &mut Context) {
let _ = cx.editor.open(&helix_loader::log_file(), Action::Replace);
}

fn yank_file_name_to_clipboard(cx: &mut Context) {
let editor = &mut cx.editor;
let (_, doc) = current_ref!(editor);
if let Some(path) = doc.path().map(|p| p.to_string_lossy()) {
let _ = editor
.clipboard_provider
.set_contents(path.into_owned(), ClipboardType::Clipboard);

editor.set_status("yanked file name to system clipboard");
} else {
editor.set_status("no file associated with current buffer");
}
}

fn buffer_picker(cx: &mut Context) {
let current = view!(cx.editor).doc;

Expand Down
9 changes: 8 additions & 1 deletion helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,14 @@ pub fn default() -> HashMap<Mode, Keymap> {

"space" => { "Space"
"f" => file_picker,
"F" => file_picker_in_current_directory,
"F" => { "File"
"f" => file_picker,
"F" => file_picker_in_current_directory,
"d" => file_picker_in_buffer_directory,
"c" => config_open,
"l" => log_open,
"y" => yank_file_name_to_clipboard,
},
"b" => buffer_picker,
"s" => symbol_picker,
"S" => workspace_symbol_picker,
Expand Down