From 12805f61d89f2869352ed83b98986cab730bd6fb Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 31 Oct 2019 11:20:55 -0500 Subject: Add simple vim mode This commit adds a "vim_mode" setting (false/`0` by default) that causes keys to be remapped in the following way by the `ScreenManager`: + h -> LEFT + j -> DOWN + k -> UP + l -> RIGHT + LEFT -> h (toggle help) + DOWN -> j (noop) + UP -> k (open kill menu) + RIGHT -> l (lsof current process) + K (Shift+K) -> k (open kill menu) + J (Shift+J) -> K (toggle show/hide kernel threads) + L (Shift+L) -> l (lsof current process) I couldn't figure out where the manpage documentation is in the repo, though I admittedly did not look particularly hard. I believe this change would be a welcome option for heavy vim users like myself who would like a familiar way to get around in htop. --- ScreenManager.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ScreenManager.c') diff --git a/ScreenManager.c b/ScreenManager.c index 06e90193..81aa2960 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -190,6 +190,23 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { set_escdelay(25); ch = getch(); + if (this->settings->vimMode) { + switch (ch) { + case 'h': ch = KEY_LEFT; break; + case 'j': ch = KEY_DOWN; break; + case 'k': ch = KEY_UP; break; + case 'l': ch = KEY_RIGHT; break; + case KEY_LEFT: ch = 'h'; break; + case KEY_DOWN: ch = 'j'; break; + case KEY_UP: ch = 'k'; break; + case KEY_RIGHT: ch = 'l'; break; + case 'K': ch = 'k'; break; + case 'J': ch = 'K'; break; + case 'L': ch = 'l'; break; + } + } + + HandlerResult result = IGNORED; if (ch == KEY_MOUSE) { ch = ERR; -- cgit v1.2.3