mirror of https://github.com/xzeldon/htop.git
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.
This commit is contained in:
parent
28840683cf
commit
12805f61d8
|
@ -190,6 +190,23 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
set_escdelay(25);
|
set_escdelay(25);
|
||||||
ch = getch();
|
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;
|
HandlerResult result = IGNORED;
|
||||||
if (ch == KEY_MOUSE) {
|
if (ch == KEY_MOUSE) {
|
||||||
ch = ERR;
|
ch = ERR;
|
||||||
|
|
|
@ -58,6 +58,7 @@ typedef struct Settings_ {
|
||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
|
bool vimMode;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
|
@ -244,6 +245,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
||||||
} else if (String_eq(option[0], "right_meter_modes")) {
|
} else if (String_eq(option[0], "right_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 1);
|
Settings_readMeterModes(this, option[1], 1);
|
||||||
didReadMeters = true;
|
didReadMeters = true;
|
||||||
|
} else if (String_eq(option[0], "vim_mode")) {
|
||||||
|
this->vimMode = atoi(option[1]);
|
||||||
}
|
}
|
||||||
String_freeArray(option);
|
String_freeArray(option);
|
||||||
}
|
}
|
||||||
|
@ -320,6 +323,7 @@ bool Settings_write(Settings* this) {
|
||||||
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
|
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
|
||||||
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
|
fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
|
||||||
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
|
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
|
||||||
|
fprintf(fd, "vim_mode=%d\n", (int) this->vimMode);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ typedef struct Settings_ {
|
||||||
bool updateProcessNames;
|
bool updateProcessNames;
|
||||||
bool accountGuestInCPUMeter;
|
bool accountGuestInCPUMeter;
|
||||||
bool headerMargin;
|
bool headerMargin;
|
||||||
|
bool vimMode;
|
||||||
|
|
||||||
bool changed;
|
bool changed;
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
Loading…
Reference in New Issue