Windows コマンドプロンプト cmd.exe の代表的な機能キーの説明は以下の通り(AIまとめ):

機能キー 機能説明 使用例
F1 前回のコマンドを一文字ずつ複製する。押すたびに1文字入力される 前回のコマンドが dir の場合、F1を3回押す → dir が入力される
F2 前回のコマンドから指定した文字までを複製する 前回のコマンドが dir の場合、F2を押し r を入力 → di が入力される
F3 前回のコマンド全体を繰り返し入力する 前回のコマンドが ipconfig の場合、F3を押す → 自動的に ipconfig が入力される
F4 カーソル位置から指定文字までの内容を削除する cd Program Files を入力中、カーソルが d にある状態でF4を押し a を入力 → cam Files になる
F5 履歴コマンドを循環表示(古いコマンドから順に表示) F5を連続して押す → 古い履歴コマンドが順に表示される
F6 ^Z(EOF, End Of File)を挿入 入力中にF6を押す → ^Z が挿入され、入力終了
F7 コマンド履歴リストを表示し、矢印キーで選択可能 F7を押す → 履歴リストが表示され、ping google.com を選択
F8 現在の入力に一致する履歴コマンドを循環表示 d を入力しF8を押す → d で始まるコマンド(例: dir)が表示される
F9 番号指定で履歴コマンドを実行 F7で履歴リストを表示し、ipconfig が3番の場合 → F9を押して 3 を入力 → 実行される

以下は、Luaスクリプトで上記の機能を再実装したものです。F5は上下キーで履歴表示、F6は未使用、F7は history | fzf で対応、F9は現在のディレクトリで最新のファイル名を返すよう変更しています。

-- F2:前回のコマンドから指定文字までを複製
nyagos.key.f2 = function(this)
  local _sCmdLine = this.text;
  if (this.pos > 1) then
    this:call("BEGINNING_OF_LINE")
  end      
  nyagos.write("\nコピーする文字までを入力してください: ")
  local _sKey=nyagos.getkeys()
  nyagos.write("\r\027[K\027[A")
  this:repaint()
  local _iPos = string.find(_sCmdLine, _sKey, 1, true)
  if _iPos then
    for i = 1, _iPos-1 do
      this:call("FORWARD_CHAR")
    end
  end
end

-- F1:前回のコマンドを一文字ずつ複製
nyagos.key.f1 = function(this)
  local _sCmdLine = nyagos.history[#nyagos.history-1]
  local _iPos = this.pos
  _sNewCmdLine = string.sub(_sCmdLine, 1, _iPos)
  this:replacefrom(1,_sNewCmdLine)
end

-- F3:前回のコマンド全体を複製
nyagos.key.f3 = function(this)
  local _sCmdLine = nyagos.history[#nyagos.history-1]
  _sNewCmdLine = string.sub(_sCmdLine, 1, _iPos)
  this:replacefrom(1,_sCmdLine)
  this:call("BEGINNING_OF_LINE")
end

-- F4:カーソル位置から指定文字までを削除
nyagos.key.f4 = function(this)
  local _sCmdLine = this.text
  local _iCurrentPos = this.pos
  nyagos.write("\n削除する文字までを入力してください: ")
  local _sKey = nyagos.getkeys()
  nyagos.write("\r\027[K\027[A")
  this:repaint()
  local _iPos = string.find(_sCmdLine, _sKey, 1, true)
  if _iPos then
    local _sNewCmdLine = string.sub(_sCmdLine, 1, _iCurrentPos) .. string.sub(_sCmdLine, _iPos)
    this:call("KILL_LINE")
    this:replacefrom(1,_sNewCmdLine)
    this:call("BEGINNING_OF_LINE")
    for i = 1, _iCurrentPos do
      this:call("FORWARD_CHAR")
    end
  end
end

-- F7:履歴リストを表示
nyagos.key.f7 = function(this)
  this:call("REPAINT_ON_NEWLINE")
  result = nyagos.box(share.__dump_history())
  this:call("REPAINT_ON_NEWLINE")
  return result
end

nyagos.key.END = function(this)
  this:call("END_OF_LINE")
end

-- F9:最新のファイル名を返す
nyagos.key.F9 = function(this)
  local _sFilename = nyagos.eval("ls -t *.* | head -n 1")
  if string.sub(_sFilename, -1) == "*" then
    _sFilename = _sFilename:sub(1, -2)
  end
  this:replacefrom(1,_sFilename)
  this:call("BEGINNING_OF_LINE")
end

1. 💡 関連リンク

✅ 解説記事(繁体字中国語): https://jdev.tw/blog/9150/
Explanation article (English)
解説記事(日本語)

GitHub my_init.lua