Navigate Far with vim-like keys

Here you can discuss any topic concerning Far macro commands.
Post Reply
ImBringingTaxicab
Posts: 5
Joined: Wed 28 Feb, 2018 15:54
Has thanked: 2 times

Navigate Far with vim-like keys

Post by ImBringingTaxicab » Fri 16 Aug, 2019 11:17

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 4 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 1 time
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.).
Last edited by ImBringingTaxicab on Fri 16 Aug, 2019 17:56, edited 1 time in total.

User avatar
HaRT
Moderator
Posts: 8751
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 81 times
Been thanked: 148 times

Navigate Far with vim-like keys

Post by HaRT » Fri 16 Aug, 2019 11:57

ImBringingTaxicab wrote:
Fri 16 Aug, 2019 11:17
Is this the right place to share them?
Yes, thanks for sharing!
Фар есть инструмент, а не нянька. © 2009 DrKnS

Post Reply

Return to “Macro Commands Discussions”