summarylogtreecommitdiffstats
path: root/vim-keybindings.patch
blob: c23cc7e225eccc679381ef620b691135a37e23e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
diff --git a/Action.c b/Action.c
index 206eb67..99ef96d 100644
--- a/Action.c
+++ b/Action.c
@@ -443,7 +443,7 @@ static const struct {
    const char* key;
    const char* info;
 } helpLeft[] = {
-   { .key = " Arrows: ", .info = "scroll process list" },
+   { .key = "   hjkl: ", .info = "scroll process list" },
    { .key = " Digits: ", .info = "incremental PID search" },
    { .key = "   F3 /: ", .info = "incremental name search" },
    { .key = "   F4 \\: ",.info = "incremental name filtering" },
@@ -469,7 +469,7 @@ static const struct {
    { .key = "  Space: ", .info = "tag process" },
    { .key = "      c: ", .info = "tag process and its children" },
    { .key = "      U: ", .info = "untag all processes" },
-   { .key = "   F9 k: ", .info = "kill process/tagged processes" },
+   { .key = "   F9 x: ", .info = "kill process/tagged processes" },
    { .key = "   F7 ]: ", .info = "higher priority (root only)" },
    { .key = "   F8 [: ", .info = "lower priority (+ nice)" },
 #if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY))
@@ -477,12 +477,12 @@ static const struct {
 #endif
    { .key = "      e: ", .info = "show process environment" },
    { .key = "      i: ", .info = "set IO priority" },
-   { .key = "      l: ", .info = "list open files with lsof" },
-   { .key = "      x: ", .info = "list file locks of process" },
+   { .key = "      L: ", .info = "list open files with lsof" },
+   { .key = "      X: ", .info = "list file locks of process" },
    { .key = "      s: ", .info = "trace syscalls with strace" },
    { .key = "      w: ", .info = "wrap process command in multiple lines" },
    { .key = " F2 C S: ", .info = "setup" },
-   { .key = "   F1 h: ", .info = "show this help screen" },
+   { .key = "   F1 ?: ", .info = "show this help screen" },
    { .key = "  F10 q: ", .info = "quit" },
    { .key = NULL, .info = NULL }
 };
@@ -648,12 +648,14 @@ void Action_setBindings(Htop_Action* keys) {
    keys['H'] = actionToggleUserlandThreads;
    keys['I'] = actionInvertSortOrder;
    keys['K'] = actionToggleKernelThreads;
+   keys['L'] = actionLsof;
    keys['M'] = actionSortByMemory;
    keys['N'] = actionSortByPID;
    keys['P'] = actionSortByCPU;
    keys['S'] = actionSetup;
    keys['T'] = actionSortByTime;
    keys['U'] = actionUntagAll;
+   keys['X'] = actionShowLocks;
    keys['Z'] = actionTogglePauseProcessUpdate;
    keys['['] = actionLowerPriority;
    keys['\014'] = actionRedraw; // Ctrl+L
@@ -663,9 +665,6 @@ void Action_setBindings(Htop_Action* keys) {
    keys['a'] = actionSetAffinity;
    keys['c'] = actionTagAllChildren;
    keys['e'] = actionShowEnvScreen;
-   keys['h'] = actionHelp;
-   keys['k'] = actionKill;
-   keys['l'] = actionLsof;
    keys['m'] = actionToggleMergedCommand;
    keys['p'] = actionToggleProgramPath;
    keys['q'] = actionQuit;
@@ -673,7 +672,7 @@ void Action_setBindings(Htop_Action* keys) {
    keys['t'] = actionToggleTreeView;
    keys['u'] = actionFilterByUser;
    keys['w'] = actionShowCommandScreen;
-   keys['x'] = actionShowLocks;
+   keys['x'] = actionKill;
    keys[KEY_F(1)] = actionHelp;
    keys[KEY_F(2)] = actionSetup;
    keys[KEY_F(3)] = actionIncSearch;
@@ -685,6 +684,7 @@ void Action_setBindings(Htop_Action* keys) {
    keys[KEY_F(9)] = actionKill;
    keys[KEY_F(10)] = actionQuit;
    keys[KEY_F(18)] = actionExpandCollapseOrSortColumn;
+   keys['o'] = actionExpandCollapseOrSortColumn;
    keys[KEY_RECLICK] = actionExpandOrCollapse;
    keys[KEY_RESIZE] = actionResize;
 }
diff --git a/Panel.c b/Panel.c
index 26a0c0e..2ace36a 100644
--- a/Panel.c
+++ b/Panel.c
@@ -343,6 +343,7 @@ bool Panel_onKey(Panel* this, int key) {
 
    switch (key) {
    case KEY_DOWN:
+   case 'j':
    case KEY_CTRL('N'):
    #ifdef KEY_C_DOWN
    case KEY_C_DOWN:
@@ -351,6 +352,7 @@ bool Panel_onKey(Panel* this, int key) {
       break;
 
    case KEY_UP:
+   case 'k':
    case KEY_CTRL('P'):
    #ifdef KEY_C_UP
    case KEY_C_UP:
@@ -359,7 +361,7 @@ bool Panel_onKey(Panel* this, int key) {
       break;
 
    case KEY_LEFT:
-   case KEY_CTRL('B'):
+   case 'h':
       if (this->scrollH > 0) {
          this->scrollH -= MAXIMUM(CRT_scrollHAmount, 0);
          this->needsRedraw = true;
@@ -367,18 +369,29 @@ bool Panel_onKey(Panel* this, int key) {
       break;
 
    case KEY_RIGHT:
-   case KEY_CTRL('F'):
+   case 'l':
       this->scrollH += CRT_scrollHAmount;
       this->needsRedraw = true;
       break;
 
+   case KEY_CTRL('U'):
+      this->selected -= (this->h - 1) / 2;
+      this->needsRedraw = true;
+      break;
+   case KEY_CTRL('D'):
+      this->selected += (this->h - 1) / 2;
+      this->needsRedraw = true;
+      break;
+
    case KEY_PPAGE:
+   case KEY_CTRL('B'):
       this->selected -= (this->h - 1);
       this->scrollV = CLAMP_INDEX(this->scrollV, -(this->h - 1), 0, size - this->h);
       this->needsRedraw = true;
       break;
 
    case KEY_NPAGE:
+   case KEY_CTRL('F'):
       this->selected += (this->h - 1);
       this->scrollV = CLAMP_INDEX(this->scrollV, +(this->h - 1), 0, size - this->h);
       this->needsRedraw = true;
@@ -397,10 +410,12 @@ bool Panel_onKey(Panel* this, int key) {
       break;
 
    case KEY_HOME:
+   case 'g':
       this->selected = 0;
       break;
 
    case KEY_END:
+   case 'G':
       this->selected = size - 1;
       break;
 
diff --git a/README b/README
index 880597d..0c44936 100644
--- a/README
+++ b/README
@@ -19,6 +19,48 @@ The information displayed is configurable through a graphical setup and can be s
 
 Tasks related to processes (e.g. killing and renicing) can be done without entering their PIDs.
 
+Vim keybindings
+----------------
+
+These are the keybindings added in this fork of htop:
+
+```
+    g        to the top (gg in vim)
+
+  <C-b>      up 1 page
+
+  <C-u>      up 1/2 page
+
+    k
+
+h       l    one character
+
+    j
+
+  <C-d>      down 1/2 page
+
+  <C-f>      down 1 page
+
+    G        to the end
+
+--------------------------------------------------
+
+    o        Expand/collapse (like in NERDTree)
+```
+
+In order to accomodate these keybindings, the following changes
+were made to the original keybindings:
+
+* Ctrl+F and Ctrt+B can no longer be used to navigate horizontally
+* 'h' can no longer be used to access the help, leaving Ctrl+F1 & '?'
+* 'k' can no longer be used to kill processes, being replaced with 'x'
+* 'l' can no longer be used to list open files, being replaced with 'L'
+* 'x' can no longer be used to list file locks, being replaced with 'X'
+
+
+Comparison between `htop` and classic `top`
+-------------------------------------------
+
 Running `htop` requires `ncurses` libraries (typically named libncursesw*).
 
 For more information and details on how to contribute to `htop` visit [htop.dev](https://htop.dev).
diff --git a/ScreenManager.c b/ScreenManager.c
index 4c74e47..6fce01f 100644
--- a/ScreenManager.c
+++ b/ScreenManager.c
@@ -251,7 +251,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
          continue;
       }
       case KEY_LEFT:
-      case KEY_CTRL('B'):
+      case 'h':
          if (this->panelCount < 2) {
             goto defaultHandler;
          }
@@ -272,7 +272,7 @@ tryLeft:
 
          break;
       case KEY_RIGHT:
-      case KEY_CTRL('F'):
+      case 'l':
       case 9:
          if (this->panelCount < 2) {
             goto defaultHandler;