https://github.com/oxy2dev/oops.nvim
Attempts to fix typos in the last run command
https://github.com/oxy2dev/oops.nvim
Last synced: 12 months ago
JSON representation
Attempts to fix typos in the last run command
- Host: GitHub
- URL: https://github.com/oxy2dev/oops.nvim
- Owner: OXY2DEV
- License: mit
- Created: 2025-03-09T12:37:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-24T12:36:58.000Z (about 1 year ago)
- Last Synced: 2025-06-14T16:45:45.109Z (about 1 year ago)
- Language: Lua
- Size: 1.26 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 😅 oops.nvim
https://github.com/user-attachments/assets/d6b00d77-7442-4ab3-a77e-235234610a01
Attempts to fix typos in the last run command.
## 📖 Table of contents
- [✨ Features](#-features)
- [📚 Requirements](#-requirements)
- [📐 Installation](#-installation)
- [🧭 Configuration](#-configuration)
- [🎇 Commands](#-commands)
- [💡 Rules](#-rules)
## ✨ Features
+ Tiny. ~ 100 lines of code.
+ Fully customisable, allows customizing every rule.
+ Out-of-box support for common typos.
## 📚 Requirement
- `histget()` function.
## 📐 Installation
### 🧩 Vim-plug
Add this to your plugin list.
```vim
Plug "OXY2DEV/oops.nvim"
```
### 💤 Lazy.nvim
```lua
-- For `plugins/oops.lua` users.
return {
"OXY2DEV/oops.nvim",
lazy = false
};
```
```lua
-- For `plugins.lua` users.
{
"OXY2DEV/oops.nvim",
lazy = false
},
```
### 🦠 Mini.deps
```lua
local MiniDeps = require("mini.deps");
MiniDeps.add({
source = "OXY2DEV/oops.nvim"
});
```
### 🌒 Rocks.nvim
>[!WARNING]
> `luarocks package` may sometimes be a bit behind `main`.
```vim
:Rocks install oops.nvim
```
### 📥 GitHub release
Tagged releases can be found in the [release page](https://github.com/OXY2DEV/oops.nvim/releases).
>[!NOTE]
> `Github releases` may sometimes be slightly behind `main`.
## 🧭 Configuration
Configuration table structure is given below,
```lua
--- Command types.
---@alias oops_kind
---| "cmd"
---| "search_up"
---| "search_down"
---| "expr"
---| "input"
--- Oops rule.
---@class oops_rule
---
--- Condition to trigger this rule.
---@field condition fun(kind: oops_kind, command: string): boolean
---
--- Resulting fixed command.
---@field fix fun(kind: oops_kind, command: string): (oops_kind, string)
----------------------------------------------------------------------
--- Configuration table for `oops.nvim`
---@class oops.config
---
--- Apply fix without confirmation?
---@field force? boolean
---
--- Command kinds to ignore.
---@field ignore_kinds? oops_kind[]
---
--- Rules.
---@field rules table
oops.config = {
force = false,
ignore_kinds = { "input", "expr" },
rules = {
q_quote = {
condition = function (prompt, command)
if prompt ~= "cmd" then return; end
return string.match(command, "^q[`'\"]") ~= nil;
end,
fix = function (prompt, command)
return prompt, string.gsub(command, "^q[`'\"]", "q")
end
},
-- ... Other rules
}
};
```
## 🎇 Commands
Oops comes with the `:Oops` command. It will try to fix whatever cmd was run last that isn't `:Oops`.
```txt
USAGE,
:Oops
:Oops [Kind]
:Oops [Kind] [force]
EXAMPLE,
:Oops cmd true
```
Different command kinds are given below,
| Kind | Description |
|-------------|--------------|
| cmd | Command(`:`) |
| search_up | Search(`/`) |
| search_down | Search(`?`) |
| expr | Search(`=`) |
## 💡 Rules
Out of the box, oops comes with the following rules,
- `caps_locked`
Fixes typos like `:W`, `:Q`, `:Wq` and other variations.
- `q_quote`
Fixes `:q'`, `:q"`.
- `reverses_wq`
Fixes `:qw`.
- `accidental_bash`
Fixes `:!w`, `:!q`, `:!e` etc.
- `set_with_S`
Fixes `:Set`.
- `lua_with_b`
Fixes `:luabcommand`(becomes `:lua commands`).
- `moh`
Fixes `:moh`(becomes `:noh`).
- `sub_wo_slash`
Fixes `:sfoo/bar`(becomes `:s/foo/bar`).
- `vsub_wo_slash`
Fixes `:'<,'>sfoo/bar`(becomes `:'<,'>s/foo/bar`).