GTKでVimのようなコントロールを設定する

Vimテキストエディターは、インタラクティブなテキスト編集に関連するほぼすべてのタスクに使用します。LaTeXレイアウトなどの構成ファイルとソースコード、muttと組み合わせて文字を書くため、さらにはWebブラウザーの外部エディターとしても使用します。



カーソル[hjkl]を制御するための十分に確立されたホットキーは、エディターの外側、たとえばコマンドシェル(修飾子と共に)に移動し始めました。



ただし、グラフィックアプリケーションには通常のホットキーが必要です。 実際には、さらにGTK環境のセットアップについて説明します。



おそらく、多くの人は、/ usr / share / themes / Emacsにあるgtk-emacs-bindersの存在を知っています。これらは、カスタムGTK構成ファイルに埋め込むのに十分です。 Vimの場合、残念ながら「すぐに使える」既製のレシピは提供されません。さらに、マルチモードの実装は簡単なタスクではないため、修飾子を使用して1つのモードを実行する必要があります。



Mod1 + [hjkl]、行Mod1 + [wq]の開始/終了にカーソルキーを掛け、さらに^ H、^ Uおよび^ Wという形式の古典的なバインダーを記述することにしました。



さらに苦労せずに、ファイルの例を示します。



〜/ .gtkrc-2.0
binding "vim-like" { bind "<ctrl>u" { "delete-from-cursor" (paragraph-ends, -1) } bind "<ctrl>h" { "delete-from-cursor" (chars, -1) } bind "<ctrl>w" { "delete-from-cursor" (word-ends, -1) } bind "<alt>j" { "move-cursor" (display-lines, 1, 0) } bind "<alt>k" { "move-cursor" (display-lines, -1, 0) } bind "<alt>l" { "move-cursor" (logical-positions, 1, 0) } bind "<alt>h" { "move-cursor" (logical-positions, -1, 0) } bind "<shift><alt>j" { "move-cursor" (display-lines, 1, 1) } bind "<shift><alt>k" { "move-cursor" (display-lines, -1, 1) } bind "<shift><alt>l" { "move-cursor" (logical-positions, 1, 1) } bind "<shift><alt>h" { "move-cursor" (logical-positions, -1, 1) } bind "<alt>q" { "move-cursor" (paragraph-ends, -1, 0) } bind "<shift><alt>q" { "move-cursor" (paragraph-ends, -1, 1) } bind "<alt>w" { "move-cursor" (paragraph-ends, 1, 0) } bind "<shift><alt>w" { "move-cursor" (paragraph-ends, 1, 1) } } class "GtkEntry" binding "vim-like" class "GtkTextView" binding "vim-like"
      
      







〜/ .config / gtk-3.0 / settings.ini
 gtk-key-theme-name=Vim
      
      







〜/ .themes / Vim / gtk-3.0 / gtk-keys.css
 @binding-set gtk-vi-text-entry { bind "<ctrl>u" { "delete-from-cursor" (paragraph-ends, -1) }; bind "<ctrl>h" { "delete-from-cursor" (chars, -1) }; bind "<ctrl>w" { "delete-from-cursor" (word-ends, -1) }; bind "<alt>j" { "move-cursor" (display-lines, 1, 0) }; bind "<alt>k" { "move-cursor" (display-lines, -1, 0) }; bind "<alt>l" { "move-cursor" (logical-positions, 1, 0) }; bind "<alt>h" { "move-cursor" (logical-positions, -1, 0) }; bind "<shift><alt>j" { "move-cursor" (display-lines, 1, 1) }; bind "<shift><alt>k" { "move-cursor" (display-lines, -1, 1) }; bind "<shift><alt>l" { "move-cursor" (logical-positions, 1, 1) }; bind "<shift><alt>h" { "move-cursor" (logical-positions, -1, 1) }; bind "<alt>q" { "move-cursor" (paragraph-ends, -1, 0) }; bind "<shift><alt>q" { "move-cursor" (paragraph-ends, -1, 1) }; bind "<alt>w" { "move-cursor" (paragraph-ends, 1, 0) }; bind "<shift><alt>w" { "move-cursor" (paragraph-ends, 1, 1) }; } @binding-set gtk-vi-text-view { bind "j" { "move-cursor" (display-lines, 1, 0) }; bind "k" { "move-cursor" (display-lines, -1, 0) }; bind "l" { "move-cursor" (logical-positions, 1, 0) }; bind "h" { "move-cursor" (logical-positions, -1, 0) }; } @binding-set gtk-vi-tree-view { bind "j" { "move-cursor" (display-lines, 1) }; bind "k" { "move-cursor" (display-lines, -1) }; bind "l" { "move-cursor" (logical-positions, 1) }; bind "h" { "move-cursor" (logical-positions, -1) }; } GtkEntry { gtk-key-bindings: gtk-vi-text-entry; } GtkTextView { gtk-key-bindings: gtk-vi-text-entry, gtk-vi-text-view; } GtkTreeView { gtk-key-bindings: gtk-vi-tree-view; }
      
      







gtkのViキーバインディングの記事に基づいており、読み取り専用環境での同様の手順について説明しています。



All Articles