Update 2025-02-24

Update 2025-02-03

Update 2025-02-04

Update 2025-02-09

Update 2025-02-14

Update 2025-02-15

Update 2025-02-22

Update 2025-02-24
This commit is contained in:
2025-02-02 16:12:25 +02:00
parent 73a0cc0977
commit 5f54bb78ad
69 changed files with 5418 additions and 2753 deletions

View File

@@ -6,26 +6,14 @@ https://github.com/dedukun/relative-motions.yazi/assets/25795432/04fb186a-5efe-4
## Requirements
- [Yazi](https://github.com/sxyazi/yazi) v0.3.0+
- [Yazi](https://github.com/sxyazi/yazi) v25.2.7+
## Installation
If you use the latest Yazi from main branch
```sh
ya pack -a dedukun/relative-motions
```
If you are using <= v0.3.3
```sh
# Linux/macOS
git clone --branch 0.3.3 https://github.com/dedukun/relative-motions.yazi.git ~/.config/yazi/plugins/relative-motions.yazi
# Windows
git clone --branch 0.3.3 https://github.com/dedukun/relative-motions.yazi.git %AppData%\yazi\config\plugins\relative-motions.yazi
```
## Configuration
If you want to use the numbers directly to start a motion add this to your `keymap.toml`:
@@ -35,47 +23,47 @@ If you want to use the numbers directly to start a motion add this to your `keym
```toml
[[manager.prepend_keymap]]
on = [ "1" ]
run = "plugin relative-motions --args=1"
run = "plugin relative-motions 1"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "2" ]
run = "plugin relative-motions --args=2"
run = "plugin relative-motions 2"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "3" ]
run = "plugin relative-motions --args=3"
run = "plugin relative-motions 3"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "4" ]
run = "plugin relative-motions --args=4"
run = "plugin relative-motions 4"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "5" ]
run = "plugin relative-motions --args=5"
run = "plugin relative-motions 5"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "6" ]
run = "plugin relative-motions --args=6"
run = "plugin relative-motions 6"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "7" ]
run = "plugin relative-motions --args=7"
run = "plugin relative-motions 7"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "8" ]
run = "plugin relative-motions --args=8"
run = "plugin relative-motions 8"
desc = "Move in relative steps"
[[manager.prepend_keymap]]
on = [ "9" ]
run = "plugin relative-motions --args=9"
run = "plugin relative-motions 9"
desc = "Move in relative steps"
```
@@ -94,18 +82,19 @@ desc = "Trigger a new relative motion"
Additionally there are a couple of initial configurations that can be given to the plugin's `setup` function:
| Configuration | Values | Default | Description |
| -------------- | ----------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `show_numbers` | `relative`, `absolute`, `relative_absolute` or `none` | `none` | Shows relative or absolute numbers before the file icon |
| `show_motion` | `true` or `false` | `false` | Shows current motion in Status bar |
| `only_motions` | `true` or `false` | `false` | If true, only the motion movements will be enabled, i.e., the commands for delete, cut, yank and visual selection will be disabled |
| Configuration | Values | Default | Description |
| -------------- | ----------------------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `show_numbers` | `relative`, `absolute`, `relative_absolute` or `none` | `none` | Shows relative or absolute numbers before the file icon |
| `show_motion` | `true` or `false` | `false` | Shows current motion in Status bar |
| `only_motions` | `true` or `false` | `false` | If true, only the motion movements will be enabled, i.e., the commands for delete, cut, yank and visual selection will be disabled |
| `enter_mode` | `cache`, `first` or `cache_or_first` | `cache_or_first` | The method to enter folders |
If you want, for example, to enable relative numbers as well as to show the motion in the status bar,
add the following to Yazi's `init.lua`, i.e. `~/.config/yazi/init.lua`:
```lua
-- ~/.config/yazi/init.lua
require("relative-motions"):setup({ show_numbers="relative", show_motion = true })
require("relative-motions"):setup({ show_numbers="relative", show_motion = true, enter_mode ="first" })
```
> [!NOTE]
@@ -119,13 +108,15 @@ require("relative-motions"):setup({ show_numbers="relative", show_motion = true
This plugin adds the some basic vim motions like `3k`, `12j`, `10gg`, etc.
The following table show all the available motions:
| Command | Description |
| -------------- | ------------------- |
| `j`/`<Down>` | Move `n` lines down |
| `k`/`<Up>` | Move `n` lines up |
| `gj`/`g<Down>` | Go `n` lines down |
| `gk`/`g<Up>` | Go `n` lines up |
| `gg` | Go to line |
| Command | Description |
| -------------- | --------------------- |
| `j`/`<Down>` | Move `n` lines down |
| `k`/`<Up>` | Move `n` lines up |
| `h`/`<Left>` | Move `n` folders back |
| `l`/`<Right>` | Enter `n` folders |
| `gj`/`g<Down>` | Go `n` lines down |
| `gk`/`g<Up>` | Go `n` lines up |
| `gg` | Go to line |
Furthermore, the following operations were also added:

View File

@@ -1,3 +1,4 @@
--- @since 25.2.7
-- stylua: ignore
local MOTIONS_AND_OP_KEYS = {
{ on = "0" }, { on = "1" }, { on = "2" }, { on = "3" }, { on = "4" },
@@ -8,7 +9,7 @@ local MOTIONS_AND_OP_KEYS = {
{ on = "t" }, { on = "L" }, { on = "H" }, { on = "w" },
{ on = "W" }, { on = "<" }, { on = ">" }, { on = "~" },
-- movement
{ on = "g" }, { on = "j" }, { on = "k" }, { on = "<Down>" }, { on = "<Up>" }
{ on = "g" }, { on = "j" }, { on = "k" }, { on = "h" }, { on = "l" }, { on = "<Down>" }, { on = "<Up>" }, { on = "<Left>" }, { on = "<Right>" }
}
-- stylua: ignore
@@ -16,7 +17,7 @@ local MOTION_KEYS = {
{ on = "0" }, { on = "1" }, { on = "2" }, { on = "3" }, { on = "4" },
{ on = "5" }, { on = "6" }, { on = "7" }, { on = "8" }, { on = "9" },
-- movement
{ on = "g" }, { on = "j" }, { on = "k" }
{ on = "g" }, { on = "j" }, { on = "k" }, { on = "h" }, { on = "l" }, { on = "<Down>" }, { on = "<Up>" }, { on = "<Left>" }, { on = "<Right>" }
}
-- stylua: ignore
@@ -30,6 +31,10 @@ local SHOW_NUMBERS_ABSOLUTE = 0
local SHOW_NUMBERS_RELATIVE = 1
local SHOW_NUMBERS_RELATIVE_ABSOLUTE = 2
local ENTER_MODE_FIRST = 0
local ENTER_MODE_CACHE = 1
local ENTER_MODE_CACHE_OR_FIRST = 2
-----------------------------------------------
----------------- R E N D E R -----------------
-----------------------------------------------
@@ -149,6 +154,10 @@ local function normal_direction(dir)
return "j"
elseif dir == "<Up>" then
return "k"
elseif dir == "<Left>" then
return "h"
elseif dir == "<Right>" then
return "l"
end
return dir
end
@@ -205,6 +214,29 @@ end
local get_active_tab = ya.sync(function(_) return cx.tabs.idx end)
local get_cache_or_first_dir = ya.sync(function(state)
if state._enter_mode == ENTER_MODE_CACHE then
return nil
elseif state._enter_mode == ENTER_MODE_CACHE_OR_FIRST then
local hovered_file = cx.active.current.hovered
if hovered_file ~= nil and hovered_file.cha.is_dir then
return cx.active.current.cursor
end
end
local files = cx.active.current.files
local index = 1
for i = 1, #files do
if files[i].cha.is_dir then
index = i
break
end
end
return index - 1
end)
-----------------------------------------------
---------- E N T R Y / S E T U P ----------
-----------------------------------------------
@@ -231,7 +263,7 @@ return {
if cmd == "g" then
if direction == "g" then
ya.manager_emit("arrow", { -99999999 })
ya.manager_emit("arrow", { "top" })
ya.manager_emit("arrow", { lines - 1 })
render_clear()
return
@@ -254,6 +286,19 @@ return {
ya.manager_emit("arrow", { lines })
elseif cmd == "k" then
ya.manager_emit("arrow", { -lines })
elseif cmd == "h" then
for _ = 1, lines do
ya.manager_emit("leave", {})
end
elseif cmd == "l" then
for _ = 1, lines do
ya.manager_emit("enter", {})
local file_idx = get_cache_or_first_dir()
if file_idx then
ya.manager_emit("arrow", { "top" })
ya.manager_emit("arrow", { file_idx })
end
end
elseif is_tab_command(cmd) then
if cmd == "t" then
for _ = 1, lines do
@@ -315,6 +360,16 @@ return {
render_motion_setup()
end
if args["enter_mode"] == "cache" then
state._enter_mode = ENTER_MODE_CACHE
elseif args["enter_mode"] == "first" then
state._enter_mode = ENTER_MODE_FIRST
elseif args["enter_mode"] == "cache_or_first" then
state._enter_mode = ENTER_MODE_CACHE_OR_FIRST
else
state._enter_mode = ENTER_MODE_CACHE_OR_FIRST
end
if args["show_numbers"] == "absolute" then
render_numbers(SHOW_NUMBERS_ABSOLUTE)
elseif args["show_numbers"] == "relative" then