diff --git a/book/src/commands.md b/book/src/commands.md index e4647535e..6cdcfce2a 100644 --- a/book/src/commands.md +++ b/book/src/commands.md @@ -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 diff --git a/helix-view/src/editor/variable_expansion.rs b/helix-view/src/editor/variable_expansion.rs index 675c9a5a0..fbed254fc 100644 --- a/helix-view/src/editor/variable_expansion.rs +++ b/helix-view/src/editor/variable_expansion.rs @@ -67,6 +67,22 @@ pub fn expand_variable_in_string<'a>(&self, input: &'a str) -> anyhow::Result (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()