Page 1 of 1

Navigate Far with vim-like keys

Posted: Fri 16 Aug, 2019 11:17
by ImBringingTaxicab
I've written some simple macros to move around Far with familiar vim keys like hjkl and Ctrl-N, Ctrl-P.
Is this the right place to share them? I don't know. But here they are anyway, I hope this is useful for somebody.

Move these files into %FARPROFILE%\Macros\scripts\ then reload Far Manager or execute lm: load on the command line.

Panel.move_with_hjkl.lua
(1.17 KiB) Downloaded 12 times
Move the cursor around the active panel with hjkl, like in vim, on the condition that the command line is empty.
Press i to insert something on the command line that begins with hjkl
If the panels are invisible these keys work like normal.

ShellAutoCompletion.CtrlN_and_CtrlP.lua
(484 Bytes) Downloaded 12 times
In Autocompletion Menus (e.g., the suggestions that come up when typing something on the command line), move the cursor down with CtrlN and up with CtrlP, like in vim.


Here's the code, if you want to have a look:

ShellAutoCompletion.CtrlN_and_CtrlP.lua

Code: Select all

--In Autocompletion Menus (e.g., the suggestions that come up when typing something on the command line), move the cursor down with CtrlN and up with CtrlP, like in vim.
Macro {
  description="In AutoCompletion Menus move down with CtrlN";
  area="ShellAutoCompletion DialogAutoCompletion"; key="CtrlN";
  code="Keys('Down')";
}
Macro {
  description="In AutoCompletion Menus move up with CtrlP";
  area="ShellAutoCompletion DialogAutoCompletion"; key="CtrlP";
  code="Keys('Up')";
}


Panel.move_with_hjkl.lua

Code: Select all

--Move the cursor around the active panel with hjkl, like in vim, on the condition that the Command Line is empty.
--Press i to insert something on the command line that begins with hjkl
--If the Panels are invisible these keys work like normal.

Macro {
	description="Move Left";
	area="Shell"; key="h";
	condition=function() return CmdLine.Empty and APanel.Visible end;
	action=function() Keys('Left') end;
}

Macro {
	description="Move Down";
	area="Shell"; key="j";
	condition=function() return CmdLine.Empty and APanel.Visible end;
	action=function() Keys('Down') end;
}

Macro {
	description="Move Up";
	area="Shell"; key="k";
	condition=function() return CmdLine.Empty and APanel.Visible end;
	action=function() Keys('Up') end;
}

Macro {
	description="Move Right";
	area="Shell"; key="l";
	condition=function() return CmdLine.Empty and APanel.Visible end;
	action=function() Keys('Right') end;
}

Macro {
	description="Input on Command Line";
	area="Shell"; key="i";
	condition=function() return CmdLine.Empty and APanel.Visible end;
	action=function() Keys("i ShiftLeft") end;
	--Presses i, then selects it. The next text that is typed replaces the i.
}
Edit: Updated CtrlN/CtrlP script to also work in dialog autocompletions (e.g. Copy, Rename/Move, etc.).

Navigate Far with vim-like keys

Posted: Fri 16 Aug, 2019 11:57
by HaRT
ImBringingTaxicab wrote:
Fri 16 Aug, 2019 11:17
Is this the right place to share them?
Yes, thanks for sharing!