Skip to content

Commit bc75e53

Browse files
committed
Initial version
1 parent 6bec736 commit bc75e53

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

.example.png

87.5 KB
Loading

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
# vim-kaizen
2-
Continous improvement in NeoVim
2+
3+
`vim-kaizen` is a NeoVim plugin to encourage continuous improvement in your Vim keybindings.
4+
It reminds you to use alternative and better keys for increased productivity and efficiency.
5+
6+
## Features
7+
8+
- Reminds you to unlearn inefficient commands.
9+
- Provides suggestions for better commands.
10+
11+
![vim-kaizen example in Vim editor](.example.png)
12+
13+
## Installation
14+
15+
#### `vim-plug`
16+
17+
```vim
18+
Plug 'mo42/vim-kaizen'
19+
```

plugin/vim-kaizen.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function VimKaizen(pat, alt)
2+
local txt = string.format('You entered "%s", which is an anti-pattern. Consider using "%s" from now on.', pat, alt)
3+
local buf = vim.api.nvim_create_buf(false, true)
4+
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {txt})
5+
local ui = vim.api.nvim_list_uis()[1] or vim.api.nvim_list_uis()[0]
6+
7+
local width = 50
8+
local height = 10
9+
local opts = {
10+
relative = 'editor',
11+
width = width,
12+
height = height,
13+
col = (ui.width / 2) - (width / 2),
14+
row = (ui.height / 2) - (height / 2),
15+
anchor = 'NW',
16+
style = 'minimal',
17+
border = 'shadow'
18+
}
19+
20+
local win = vim.api.nvim_open_win(buf, true, opts)
21+
vim.api.nvim_set_current_win(win)
22+
vim.api.nvim_buf_set_keymap(buf, 'n', '<Esc>', '<Cmd>bwipeout!<CR>', {noremap = true, silent = true})
23+
vim.api.nvim_buf_set_keymap(buf, 'n', 'q', '<Cmd>bwipeout!<CR>', {noremap = true, silent = true})
24+
end
25+
26+
vim.api.nvim_create_user_command('VimHabits', function(opts) VimHabits(opts.args) end, {nargs=1})
27+
28+
local vimKaizenPatterns = {
29+
{'n', 'd$', 'D'},
30+
{'n', 'y$', 'Y'},
31+
{'n', 'ggVG', 'yG'},
32+
{'n', 'cc', 'S'}
33+
}
34+
35+
for _, tuple in ipairs(vimKaizenPatterns) do
36+
local map, pat, alt = table.unpack(tuple)
37+
vim.keymap.set(map, pat, function() VimKaizen(pat, alt) end, { noremap = true, silent = true })
38+
end

0 commit comments

Comments
 (0)