adding relative filename expansion

pull/11164/head
Théo Daron 3 months ago
parent e774706440
commit 2f98016038

@ -7,18 +7,20 @@ Command mode can be activated by pressing `:`. The built-in commands are:
## Using variables in typed commands and mapped shortcuts ## Using variables in typed commands and mapped shortcuts
Helix provides several variables that can be used when typing commands or creating custom shortcuts. These variables are listed below: Helix provides several variables that can be used when typing commands or creating custom shortcuts. These variables are listed below:
| Variable | Description | | Variable | Description |
| --- | --- | | --- | --- |
| `%{basename}` | The name and extension of the currently focused file. | | `%{basename}` | The name and extension of the currently focused file. |
| `%{filename}` | The absolute path of the currently focused file. | | `%{filename}` | The absolute path of the currently focused file. |
| `%{ext}` | The extension of the current file | | `%{filename:rel}` | The relative path of the file according to the current working directory (will give absolute path if the file is not a child of the current working directory) |
| `%{lang}` | The language of the current file | | `%{filename:git_rel}` | The relative path of the file according to the git repo, or current working directory if not inside a git repo. (will give absolute path if the file is not a child of the git directory or the cwd) |
| `%{dirname}` | The absolute path of the parent directory of the currently focused file. | | `%{ext}` | The extension of the current file |
| `%{cwd}` | The absolute path of the current working directory of Helix. | | `%{lang}` | The language of the current file |
| `%{linenumber}` | The line number where the primary cursor is positioned. | | `%{dirname}` | The absolute path of the parent directory of the currently focused file. |
| `%{cursorcolumn}`| The position of the primary cursor inside the current line. | | `%{cwd}` | The absolute path of the current working directory of Helix. |
| `%{selection}` | The text selected by the primary cursor. | | `%{linenumber}` | The line number where the primary cursor is positioned. |
| `%sh{cmd}` | Executes `cmd` with the default shell and returns the command output, if any. | | `%{cursorcolumn}` | The position of the primary cursor inside the current line. |
| `%{selection}` | The text selected by the primary cursor. |
| `%sh{cmd}` | Executes `cmd` with the default shell and returns the command output, if any. |
### Example ### Example
```toml ```toml

@ -51,6 +51,27 @@ impl Editor {
.and_then(|it| it.to_str()) .and_then(|it| it.to_str())
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME) .unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
.to_owned(), .to_owned(),
"filename:git_rel" => {
// This will get git repo root or cwd if not inside a git repo.
let workspace_path = helix_loader::find_workspace().0;
doc.path()
.and_then(|p| {
p.strip_prefix(workspace_path)
.unwrap_or(p)
.to_str()
})
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
.to_owned()
}
"filename:rel" => {
let cwd = helix_stdx::env::current_working_dir();
doc.path()
.and_then(|p| {
p.strip_prefix(cwd).unwrap_or(p).to_str()
})
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
.to_owned()
}
"dirname" => doc "dirname" => doc
.path() .path()
.and_then(|p| p.parent()) .and_then(|p| p.parent())

Loading…
Cancel
Save