adding some other expansions

This commit is contained in:
Théo Daron 2024-08-01 00:07:31 +02:00
parent 0a655d9978
commit b5cae57b1e
2 changed files with 28 additions and 9 deletions

View File

@ -7,15 +7,18 @@ # Commands
## 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:
| Variable | Description |
| --- | --- |
| `%{basename}` | The name and extension of the currently focused file. |
| `%{filename}` | The absolute path of the currently focused file. |
| `%{dirname}` | The absolute path of the parent directory of the currently focused file. |
| `%{cwd}` | The absolute path of the current working directory of Helix. |
| `%{linenumber}` | The line number where the primary cursor is positioned. |
| `%{selection}` | The text selected by the primary cursor. |
| `%sh{cmd}` | Executes `cmd` with the default shell and returns the command output, if any. |
| Variable | Description |
| --- | --- |
| `%{basename}` | The name and extension of the currently focused file. |
| `%{filename}` | The absolute path of the currently focused file. |
| `%{ext}` | The extension of the current file |
| `%{lang}` | The language of the current file |
| `%{dirname}` | The absolute path of the parent directory of the currently focused file. |
| `%{cwd}` | The absolute path of the current working directory of Helix. |
| `%{linenumber}` | The line number where the primary cursor is positioned. |
| `%{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
```toml

View File

@ -67,6 +67,22 @@ pub fn expand_variable_in_string<'a>(&self, input: &'a str) -> anyhow::Result<Co
.cursor_line(doc.text().slice(..))
+ 1)
.to_string(),
"cursorcolumn" => (doc
.selection(view.id)
.primary()
.cursor(doc.text().slice(..))
+ 1)
.to_string(),
"lang" => doc.language_name().unwrap_or("text").to_string(),
"ext" => match doc.relative_path() {
Some(path) => path
.to_string_lossy()
.split(".")
.last()
.unwrap_or("")
.to_string(),
_ => "".to_string(),
},
"selection" => doc
.selection(view.id)
.primary()