# A TOML linter such as https://taplo.tamasfe.dev/ can use this schema to validate your config.
# If you encounter any issues, please make an issue at https://github.com/yazi-rs/schemas.
"$schema" = "https://yazi-rs.github.io/schemas/keymap.json"

[mgr]
keymap = [
  {on = [ "<Esc>" ], run = "escape", desc = "Exit visual mode, clear selected, or cancel search"},
  {on = [ "<C-[>" ], run = "escape", desc = "Exit visual mode, clear selected, or cancel search"},
  {on = [ "q" ], run = "quit", desc = "Exit the process"},
  {on = [ "Q" ], run = "quit --no-cwd-file", desc = "Exit the process without writing cwd-file"},
  {on = [ "<C-q>" ], run = "close", desc = "Close the current tab, or quit if it is last tab"},
  {on = [ "<C-z>" ], run = "suspend", desc = "Suspend the process"},

  # Navigation
  {on = [ "k" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "j" ], run = "arrow 1", desc = "Move cursor down"},

  {on = [ "K" ], run = "arrow -5", desc = "Move cursor up 5 lines"},
  {on = [ "J" ], run = "arrow 5", desc = "Move cursor down 5 lines"},

  {on = [ "<S-Up>" ], run = "arrow -5", desc = "Move cursor up 5 lines"},
  {on = [ "<S-Down>" ], run = "arrow 5", desc = "Move cursor down 5 lines"},

  {on = [ "<C-u>" ], run = "arrow -50%", desc = "Move cursor up half page"},
  {on = [ "<C-d>" ], run = "arrow 50%", desc = "Move cursor down half page"},
  {on = [ "<C-b>" ], run = "arrow -100%", desc = "Move cursor up one page"},
  {on = [ "<C-f>" ], run = "arrow 100%", desc = "Move cursor down one page"},

  {on = [ "<C-PageUp>" ], run = "arrow -50%", desc = "Move cursor up half page"},
  {on = [ "<C-PageDown>" ], run = "arrow 50%", desc = "Move cursor down half page"},
  {on = [ "<PageUp>" ], run = "arrow -100%", desc = "Move cursor up one page"},
  {on = [ "<PageDown>" ], run = "arrow 100%", desc = "Move cursor down one page"},

  {on = [ "h" ], run = "leave", desc = "Go back to the parent directory"},
  {on = [ "l" ], run = "enter", desc = "Enter the child directory"},

  {on = [ "H" ], run = "back", desc = "Go back to the previous directory"},
  {on = [ "L" ], run = "forward", desc = "Go forward to the next directory"},

  {on = [ "<A-h>" ], run = "seek -5", desc = "Seek up 5 units in the preview"},
  {on = [ "<A-l>" ], run = "seek 5", desc = "Seek down 5 units in the preview"},

  {on = [ "g", "g" ], run = "arrow top", desc = "Move cursor to the top"},
  {on = [ "G" ], run = "arrow bot", desc = "Move cursor to the bottom"},

  # Selection
  {on = [ "<Space>" ], run = [ "toggle --state=none", "arrow 1" ], desc = "Toggle the current selection state"},
  {on = [ "v" ], run = "visual_mode", desc = "Enter visual mode (selection mode)"},
  {on = [ "V" ], run = "visual_mode --unset", desc = "Enter visual mode (unset mode)"},
  {on = [ "<C-a>" ], run = "toggle_all --state=true", desc = "Select all files"},
  {on = [ "<C-r>" ], run = "toggle_all --state=none", desc = "Inverse selection of all files"},

  # Operation
  {on = [ "e" ], run = "open", desc = "Open the selected files"},
  {on = [ "o" ], run = "open", desc = "Open the selected files"},
  {on = [ "O" ], run = "open --interactive", desc = "Open the selected files interactively"},
  {on = [ "<Enter>" ], run = "open", desc = "Open the selected files"},
  {on = [ "<C-Enter>" ], run = "open --interactive", desc = "Open the selected files interactively"},
  {on = [ "y" ], run = "yank", desc = "Copy the selected files"},
  {on = [ "Y" ], run = "unyank", desc = "Cancel the yank status of files"},
  {on = [ "x" ], run = "yank --cut", desc = "Cut the selected files"},
  {on = [ "X" ], run = "unyank", desc = "Cancel the yank status of files"},
  {on = [ "p" ], run = "paste", desc = "Paste the files"},
  {on = [ "P" ], run = "paste --force", desc = "Paste the files (overwrite if the destination exists)"},
  {on = [ "-" ], run = "link", desc = "Symlink the absolute path of files"},
  {on = [ "_" ], run = "link --relative", desc = "Symlink the relative path of files"},
  {on = [ "d" ], run = "remove", desc = "Move the files to the trash"},
  {on = [ "D" ], run = "remove --permanently", desc = "Permanently delete the files"},
  {on = [ "a" ], run = "create", desc = "Create a file or directory (ends with / for directories)"},
  {on = [ "r" ], run = "rename --cursor=before_ext", desc = "Rename a file or directory"},
  {on = [ ";" ], run = "shell --interactive", desc = "Run a shell command"},
  {on = [ ":" ], run = "shell --block --interactive", desc = "Run a shell command (block the UI until the command finishes)"},
  {on = [ "." ], run = "hidden toggle", desc = "Toggle the visibility of hidden files"},
  {on = [ "s" ], run = "search fd", desc = "Search files by name using fd"},
  {on = [ "S" ], run = "search rg", desc = "Search files by content using ripgrep"},
  {on = [ "<C-c>" ], run = "search none", desc = "Cancel the ongoing search"},
  {on = [ "z" ], run = "plugin zoxide", desc = "Jump to a directory using zoxide"},
  {on = [ "Z" ], run = "plugin fzf", desc = "Jump to a directory, or reveal a file using fzf"},

  # Linemode
  {on = [ "m", "s" ], run = "linemode size", desc = "Set linemode to size"},
  {on = [ "m", "p" ], run = "linemode permissions", desc = "Set linemode to permissions"},
  {on = [ "m", "m" ], run = "linemode mtime", desc = "Set linemode to mtime"},
  {on = [ "m", "n" ], run = "linemode none", desc = "Set linemode to none"},

  # Copy
  {on = [ "c", "c" ], run = "copy path", desc = "Copy the absolute path"},
  {on = [ "c", "d" ], run = "copy dirname", desc = "Copy the path of the parent directory"},
  {on = [ "c", "f" ], run = "copy filename", desc = "Copy the name of the file"},
  {on = [ "c", "n" ], run = "copy name_without_ext", desc = "Copy the name of the file without the extension"},

  # Filter
  {on = [ "f" ], run = "filter --smart", desc = "Filter the files"},

  # Find
  {on = [ "/" ], run = "find --smart", desc = "Find next file"},
  {on = [ "?" ], run = "find --previous --smart", desc = "Find previous file"},
  {on = [ "n" ], run = "find_arrow", desc = "Go to next found file"},
  {on = [ "N" ], run = "find_arrow --previous", desc = "Go to previous found file"},

  # Sorting
  {on = [ ",", "m" ], run = "sort mtime --dir-first", desc = "Sort by modified time"},
  {on = [ ",", "M" ], run = "sort mtime --reverse --dir-first", desc = "Sort by modified time (reverse)"},
  {on = [ ",", "c" ], run = "sort btime --dir-first", desc = "Sort by created time"},
  {on = [ ",", "C" ], run = "sort btime --reverse --dir-first", desc = "Sort by created time (reverse)"},
  {on = [ ",", "e" ], run = "sort extension --dir-first", desc = "Sort by extension"},
  {on = [ ",", "E" ], run = "sort extension --reverse --dir-first", desc = "Sort by extension (reverse)"},
  {on = [ ",", "a" ], run = "sort alphabetical --dir-first", desc = "Sort alphabetically"},
  {on = [ ",", "A" ], run = "sort alphabetical --reverse --dir-first", desc = "Sort alphabetically (reverse)"},
  {on = [ ",", "n" ], run = "sort natural --dir-first", desc = "Sort naturally"},
  {on = [ ",", "N" ], run = "sort natural --reverse --dir-first", desc = "Sort naturally (reverse)"},
  {on = [ ",", "s" ], run = "sort size --dir-first", desc = "Sort by size"},
  {on = [ ",", "S" ], run = "sort size --reverse --dir-first", desc = "Sort by size (reverse)"},

  # Tabs
  {on = [ "t" ], run = "tab_create --current", desc = "Create a new tab using the current path"},

  # {on = [ "1" ], run = "tab_switch 0", desc = "Switch to the first tab"},
  # {on = [ "2" ], run = "tab_switch 1", desc = "Switch to the second tab"},
  # {on = [ "3" ], run = "tab_switch 2", desc = "Switch to the third tab"},
  # {on = [ "4" ], run = "tab_switch 3", desc = "Switch to the fourth tab"},
  # {on = [ "5" ], run = "tab_switch 4", desc = "Switch to the fifth tab"},
  # {on = [ "6" ], run = "tab_switch 5", desc = "Switch to the sixth tab"},
  # {on = [ "7" ], run = "tab_switch 6", desc = "Switch to the seventh tab"},
  # {on = [ "8" ], run = "tab_switch 7", desc = "Switch to the eighth tab"},
  # {on = [ "9" ], run = "tab_switch 8", desc = "Switch to the ninth tab"},

  {on = [ "[" ], run = "tab_switch -1 --relative", desc = "Switch to the previous tab"},
  {on = [ "]" ], run = "tab_switch 1 --relative", desc = "Switch to the next tab"},

  {on = [ "{" ], run = "tab_swap -1", desc = "Swap the current tab with the previous tab"},
  {on = [ "}" ], run = "tab_swap 1", desc = "Swap the current tab with the next tab"},

  # Tasks
  {on = [ "w" ], run = "tasks_show", desc = "Show the tasks manager"},

  # Goto
  {on = [ "g", "h" ], run = "cd ~", desc = "Go to the Home directory"},
  {on = [ "g", "c" ], run = "cd ~/.config", desc = "Go to the .config directory"},
  {on = [ "g", "d" ], run = "cd ~/Downloads", desc = "Go to the Downloads directory"},
  {on = [ "g", "t" ], run = "cd /tmp", desc = "Go to the tmp directory"},
  {on = [ "g", "D" ], run = "cd ~/Documents", desc = "Go to the Documents directory"},
  {on = [ "g", "l" ], run = "cd ~/.local", desc = "Go to the .local directory"},
  {on = [ "g", "n" ], run = "cd ~/Nextcloud", desc = "Go to the Nextcloud directory"},
  {on = [ "g", "p" ], run = "cd ~/Pictures", desc = "Go to the Pictures directory"},
  {on = [ "g", "v" ], run = "cd ~/Videos", desc = "Go to the Videos directory"},
  {on = [ "g", "r" ], run = "cd ~/repos", desc = "Go to the repos directory"},
  {on = [ "g", "<Space>" ], run = "cd --interactive", desc = "Go to a directory interactively"},

  # Help
  {on = [ "~" ], run = "help", desc = "Open help"},
]
prepend_keymap = [
  # Custom
  {on = [ "y" ], run = [ 'shell -- echo "$@" | xclip -selection clipboard', "yank" ], desc = "Yank the selected files"},
  {on = [ "y" ], run = [ 'shell -- for path in "$@"; do echo "file://$path"; done | wl-copy -t text/uri-list', "yank" ], desc = "Yank the selected files"},
  {on = [ "b", "g" ], run = [ ''' shell 'setbg "$1"' --confirm ''' ], desc = "Set the background image"},
  # chmod
  {on = [ "c", "m" ], run = "plugin chmod", desc = "Chmod on selected files"},
  # Archive
  {on = [ "c", "a" ], run = "plugin ouch -- zip", desc = "Compress with ouch"},
  # Augment Command
  {on = [ "l" ], run = "plugin augment-command -- enter", desc = "Enter a directory and skip directories with only a single subdirectory"},
  {on = [ "k" ], run = "plugin augment-command -- arrow -1", desc = "Move cursor up"},
  {on = [ "r" ], run = "plugin augment-command -- rename --cursor=before_ext", desc = "Rename a file or directory"},
  {on = [ "R" ], run = "plugin augment-command -- rename", desc = "Rename a file or directory"},
  {on = [ "D" ], run = "plugin augment-command -- remove --permanently", desc = "Permanently delete the files"},
  # Dragon
  {on = [ "m", "m" ], run = 'shell -- ripdrag -atk "$@"', desc = "Drag and drop all"},
  {on = "<C-n>", run = 'shell -- ripdrag -atk "$@"', desc = "Drag and drop all"},
  # Max Preview
  {on = "T", run = "plugin --sync max-preview", desc = "Maximize or restore preview"},
  # Hide Preview
  {on = "<C-t>", run = "plugin --sync hide-preview", desc = "Hide or show preview"},
  # Relative motions
  {on = [ "1" ], run = "plugin relative-motions 1", desc = "Move in relative steps"},
  {on = [ "2" ], run = "plugin relative-motions 2", desc = "Move in relative steps"},
  {on = [ "3" ], run = "plugin relative-motions 3", desc = "Move in relative steps"},
  {on = [ "4" ], run = "plugin relative-motions 4", desc = "Move in relative steps"},
  {on = [ "5" ], run = "plugin relative-motions 5", desc = "Move in relative steps"},
  {on = [ "6" ], run = "plugin relative-motions 6", desc = "Move in relative steps"},
  {on = [ "7" ], run = "plugin relative-motions 7", desc = "Move in relative steps"},
  {on = [ "8" ], run = "plugin relative-motions 8", desc = "Move in relative steps"},
  {on = [ "9" ], run = "plugin relative-motions 9", desc = "Move in relative steps"},
  {on = [ "c", "s" ], run = "plugin what-size", desc = "Calc size of selection or cwd"},
  {on = "M", run = "plugin mount", desc = "Mount"},
  {on = "F", run = "plugin smart-filter", desc = "Smart filter"},
  {on = "<C-d>", run = "plugin diff", desc = "Diff the selected with the hovered file"},
  {on = [ "<C-e>" ], run = "seek 5"},
  {on = [ "<C-y>" ], run = "seek -5"},
  {on = [ "z", "h" ], run = "plugin time-travel --args=prev", desc = "Go to previous snapshot"},
  {on = [ "z", "l" ], run = "plugin time-travel --args=next", desc = "Go to next snapshot"},
  {on = [ "z", "e" ], run = "plugin time-travel --args=exit", desc = "Exit browsing snapshots"},
]

[tasks]
keymap = [
  {on = [ "<Esc>" ], run = "close", desc = "Hide the task manager"},
  {on = [ "<C-[>" ], run = "close", desc = "Hide the task manager"},
  {on = [ "<C-q>" ], run = "close", desc = "Hide the task manager"},
  {on = [ "w" ], run = "close", desc = "Hide the task manager"},
  {on = [ "k" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "j" ], run = "arrow 1", desc = "Move cursor down"},
  {on = [ "<Up>" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "<Down>" ], run = "arrow 1", desc = "Move cursor down"},
  {on = [ "<Enter>" ], run = "inspect", desc = "Inspect the task"},
  {on = [ "x" ], run = "cancel", desc = "Cancel the task"},
  {on = [ "~" ], run = "help", desc = "Open help"},
]

[select]
keymap = [
  {on = [ "<Esc>" ], run = "close", desc = "Cancel selection"},
  {on = [ "<C-[>" ], run = "close", desc = "Cancel selection"},
  {on = [ "<C-q>" ], run = "close", desc = "Cancel selection"},
  {on = [ "<Enter>" ], run = "close --submit", desc = "Submit the selection"},
  {on = [ "k" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "j" ], run = "arrow 1", desc = "Move cursor down"},
  {on = [ "K" ], run = "arrow -5", desc = "Move cursor up 5 lines"},
  {on = [ "J" ], run = "arrow 5", desc = "Move cursor down 5 lines"},
  {on = [ "<Up>" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "<Down>" ], run = "arrow 1", desc = "Move cursor down"},
  {on = [ "<S-Up>" ], run = "arrow -5", desc = "Move cursor up 5 lines"},
  {on = [ "<S-Down>" ], run = "arrow 5", desc = "Move cursor down 5 lines"},
  {on = [ "~" ], run = "help", desc = "Open help"},
]

[input]
keymap = [
  {on = [ "<C-q>" ], run = "close", desc = "Cancel input"},
  {on = [ "<Enter>" ], run = "close --submit", desc = "Submit the input"},
  {on = [ "<Esc>" ], run = "escape", desc = "Go back the normal mode, or cancel input"},
  {on = [ "<C-[>" ], run = "escape", desc = "Go back the normal mode, or cancel input"},

  # Mode
  {on = [ "i" ], run = "insert", desc = "Enter insert mode"},
  {on = [ "a" ], run = "insert --append", desc = "Enter append mode"},
  {on = [ "I" ], run = [ "move -999", "insert" ], desc = "Move to the BOL, and enter insert mode"},
  {on = [ "A" ], run = [ "move 999", "insert --append" ], desc = "Move to the EOL, and enter append mode"},
  {on = [ "v" ], run = "visual", desc = "Enter visual mode"},
  {on = [ "V" ], run = [ "move -999", "visual", "move 999" ], desc = "Enter visual mode and select all"},

  # Character-wise movement
  {on = [ "h" ], run = "move -1", desc = "Move back a character"},
  {on = [ "l" ], run = "move 1", desc = "Move forward a character"},
  {on = [ "<Left>" ], run = "move -1", desc = "Move back a character"},
  {on = [ "<Right>" ], run = "move 1", desc = "Move forward a character"},
  {on = [ "<C-b>" ], run = "move -1", desc = "Move back a character"},
  {on = [ "<C-f>" ], run = "move 1", desc = "Move forward a character"},

  # Word-wise movement
  {on = [ "b" ], run = "backward", desc = "Move back to the start of the current or previous word"},
  {on = [ "w" ], run = "forward", desc = "Move forward to the start of the next word"},
  {on = [ "e" ], run = "forward --end-of-word", desc = "Move forward to the end of the current or next word"},
  {on = [ "<A-b>" ], run = "backward", desc = "Move back to the start of the current or previous word"},
  {on = [ "<A-f>" ], run = "forward --end-of-word", desc = "Move forward to the end of the current or next word"},

  # Line-wise movement
  {on = [ "0" ], run = "move -999", desc = "Move to the BOL"},
  {on = [ "$" ], run = "move 999", desc = "Move to the EOL"},
  {on = [ "<C-a>" ], run = "move -999", desc = "Move to the BOL"},
  {on = [ "<C-e>" ], run = "move 999", desc = "Move to the EOL"},
  {on = [ "<Home>" ], run = "move -999", desc = "Move to the BOL"},
  {on = [ "<End>" ], run = "move 999", desc = "Move to the EOL"},

  # Delete
  {on = [ "<Backspace>" ], run = "backspace", desc = "Delete the character before the cursor"},
  {on = [ "<Delete>" ], run = "backspace --under", desc = "Delete the character under the cursor"},
  {on = [ "<C-h>" ], run = "backspace", desc = "Delete the character before the cursor"},
  {on = [ "<C-d>" ], run = "backspace --under", desc = "Delete the character under the cursor"},

  # Kill
  {on = [ "<C-u>" ], run = "kill bol", desc = "Kill backwards to the BOL"},
  {on = [ "<C-k>" ], run = "kill eol", desc = "Kill forwards to the EOL"},
  {on = [ "<C-w>" ], run = "kill backward", desc = "Kill backwards to the start of the current word"},
  {on = [ "<A-d>" ], run = "kill forward", desc = "Kill forwards to the end of the current word"},

  # Cut/Yank/Paste
  {on = [ "d" ], run = "delete --cut", desc = "Cut the selected characters"},
  {on = [ "D" ], run = [ "delete --cut", "move 999" ], desc = "Cut until the EOL"},
  {on = [ "c" ], run = "delete --cut --insert", desc = "Cut the selected characters, and enter insert mode"},
  {on = [ "C" ], run = [ "delete --cut --insert", "move 999" ], desc = "Cut until the EOL, and enter insert mode"},
  {on = [ "x" ], run = [ "delete --cut", "move 1 --in-operating" ], desc = "Cut the current character"},
  {on = [ "y" ], run = "yank", desc = "Copy the selected characters"},
  {on = [ "p" ], run = "paste", desc = "Paste the copied characters after the cursor"},
  {on = [ "P" ], run = "paste --before", desc = "Paste the copied characters before the cursor"},

  # Undo/Redo
  {on = [ "u" ], run = "undo", desc = "Undo the last operation"},
  {on = [ "<C-r>" ], run = "redo", desc = "Redo the last operation"},

  # Help
  {on = [ "~" ], run = "help", desc = "Open help"},
]


[completion]
keymap = [
  {on = [ "<C-q>" ], run = "close", desc = "Cancel completion"},
  {on = [ "<Tab>" ], run = "close --submit", desc = "Submit the completion"},
  {on = [ "<Enter>" ], run = [ "close --submit", "close_input --submit" ], desc = "Submit the completion and input"},
  {on = [ "<A-k>" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "<A-j>" ], run = "arrow 1", desc = "Move cursor down"},
  {on = [ "<Up>" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "<Down>" ], run = "arrow 1", desc = "Move cursor down"},
  {on = [ "<C-p>" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "<C-n>" ], run = "arrow 1", desc = "Move cursor down"},
  {on = [ "~" ], run = "help", desc = "Open help"},
]

[help]
keymap = [
  {on = [ "<Esc>" ], run = "escape", desc = "Clear the filter, or hide the help"},
  {on = [ "<C-[>" ], run = "escape", desc = "Clear the filter, or hide the help"},
  {on = [ "q" ], run = "close", desc = "Exit the process"},
  {on = [ "<C-q>" ], run = "close", desc = "Hide the help"},

  # Navigation
  {on = [ "k" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "j" ], run = "arrow 1", desc = "Move cursor down"},

  {on = [ "K" ], run = "arrow -5", desc = "Move cursor up 5 lines"},
  {on = [ "J" ], run = "arrow 5", desc = "Move cursor down 5 lines"},

  {on = [ "<Up>" ], run = "arrow -1", desc = "Move cursor up"},
  {on = [ "<Down>" ], run = "arrow 1", desc = "Move cursor down"},

  {on = [ "<S-Up>" ], run = "arrow -5", desc = "Move cursor up 5 lines"},
  {on = [ "<S-Down>" ], run = "arrow 5", desc = "Move cursor down 5 lines"},

  # Filtering
  {on = [ "/" ], run = "filter", desc = "Apply a filter for the help items"},
]
