mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 10:56:19 +04:00
adding shorthands
This commit is contained in:
parent
a997f63990
commit
c0666d1219
@ -7,21 +7,21 @@ # Commands
|
|||||||
## 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}` or `%{b}` | The name and extension of the currently focused file. |
|
||||||
| `%{dirname}` | The absolute path of the parent directory of the currently focused file. |
|
| `%{dirname}` or `%{d}` | The absolute path of the parent directory of the currently focused file. |
|
||||||
| `%{cwd}` | The absolute path of the current working directory of Helix. |
|
| `%{cwd}` | The absolute path of the current working directory of Helix. |
|
||||||
| `%{git_repo}` | The absolute path of the git repository helix is opened in. Fallback to `cwd` if not inside a git repository|
|
| `%{git_repo}` | The absolute path of the git repository helix is opened in. Fallback to `cwd` if not inside a git repository|
|
||||||
| `%{filename}` | The absolute path of the currently focused file. |
|
| `%{filename}` or `%{f}` | The absolute path of the currently focused file. |
|
||||||
| `%{filename:rel}` | The relative path of the file according to `cwd` (will give absolute path if the file is not a child of the current working directory) |
|
| `%{filename:rel}` | The relative path of the file according to `cwd` (will give absolute path if the file is not a child of the current working directory) |
|
||||||
| `%{filename:git_rel}` | The relative path of the file according to `git_repo` (will give absolute path if the file is not a child of the git directory or the cwd) |
|
| `%{filename:git_rel}` | The relative path of the file according to `git_repo` (will give absolute path if the file is not a child of the git directory or the cwd) |
|
||||||
| `%{ext}` | The extension of the current file |
|
| `%{ext}` | The extension of the current file |
|
||||||
| `%{lang}` | The language of the current file |
|
| `%{lang}` | The language of the current file |
|
||||||
| `%{linenumber}` | The line number where the primary cursor is positioned. |
|
| `%{linenumber}` | The line number where the primary cursor is positioned. |
|
||||||
| `%{cursorcolumn}` | The position of the primary cursor inside the current line. |
|
| `%{cursorcolumn}` | The position of the primary cursor inside the current line. |
|
||||||
| `%{selection}` | The text selected by the primary cursor. |
|
| `%{selection}` | The text selected by the primary cursor. |
|
||||||
| `%sh{cmd}` | Executes `cmd` with the default shell and returns the command output, if any. |
|
| `%sh{cmd}` | Executes `cmd` with the default shell and returns the command output, if any. |
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
```toml
|
```toml
|
||||||
@ -29,3 +29,4 @@ ### Example
|
|||||||
# Print blame info for the line where the main cursor is.
|
# Print blame info for the line where the main cursor is.
|
||||||
C-b = ":echo %sh{git blame -L %{linenumber} %{filename}}"
|
C-b = ":echo %sh{git blame -L %{linenumber} %{filename}}"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ pub fn expand_variable_in_string<'a>(&self, input: &'a str) -> anyhow::Result<Co
|
|||||||
last_push_end = end + 1;
|
last_push_end = end + 1;
|
||||||
|
|
||||||
let value = match &input[index + 2..end] {
|
let value = match &input[index + 2..end] {
|
||||||
"basename" => doc
|
"basename" | "b" => doc
|
||||||
.path()
|
.path()
|
||||||
.and_then(|it| {
|
.and_then(|it| {
|
||||||
it.file_name().and_then(|it| it.to_str())
|
it.file_name().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" => doc
|
"filename" | "f" => doc
|
||||||
.path()
|
.path()
|
||||||
.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)
|
||||||
@ -74,7 +74,7 @@ pub fn expand_variable_in_string<'a>(&self, input: &'a str) -> anyhow::Result<Co
|
|||||||
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
|
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
|
||||||
.to_owned()
|
.to_owned()
|
||||||
}
|
}
|
||||||
"dirname" => doc
|
"dirname" | "d" => doc
|
||||||
.path()
|
.path()
|
||||||
.and_then(|p| p.parent())
|
.and_then(|p| p.parent())
|
||||||
.and_then(std::path::Path::to_str)
|
.and_then(std::path::Path::to_str)
|
||||||
|
Loading…
Reference in New Issue
Block a user