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 File sub keymap #3063

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 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,19 @@ 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 collection of file-opening commands.


| 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` |
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about b for this?

| `c` | Open the helix config.toml file | `config_open` |
| `l` | Open the helix log file | `log_open` |

##### Popup

Displays documentation for item under cursor.
Expand Down
23 changes: 23 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ 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.",
code_action, "Perform code action",
buffer_picker, "Open buffer picker",
symbol_picker, "Open symbol picker",
Expand Down Expand Up @@ -2196,6 +2199,26 @@ 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 buffer_picker(cx: &mut Context) {
let current = view!(cx.editor).doc;

Expand Down
8 changes: 7 additions & 1 deletion helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ 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,
},
"b" => buffer_picker,
"s" => symbol_picker,
"S" => workspace_symbol_picker,
Expand Down