mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
adding some other expansions
This commit is contained in:
parent
0a655d9978
commit
b5cae57b1e
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user