Vifm

提供: ArchWiki
2017年10月12日 (木) 23:15時点におけるKusakata.bot (トーク | 投稿記録)による版 (文字列「Tips and tricks」を「ヒントとテクニック」に置換)
ナビゲーションに移動 検索に移動

関連記事

Vifm のホームページより:

Vifm は ncurses ベースのファイルマネージャで、vi のようなキーバインディング/モード/オプション/コマンド/設定を備えています。また、mutt からもアイデアを頂戴しています。vi を使っているのであれば、Vifm では新しいコマンドセットを覚えなくても完全にファイルをキーボードで制御できるでしょう。

インストール

公式リポジトリから vifmインストールしてください。

ヘルプファイル

vifm の基本的な情報はヘルプファイルに書かれています。vifm を開いて次を入力することでヘルプファイルを見ることができます:

:h

他の情報は man ページを見てください。

Vifm のカスタマイズ

Vifm はホームディレクトリに .vifm フォルダを作成し、以下のファイルが保存されます:

  • vifmrc - 作業スタイルにあわせて編集できるコメント豊富な設定ファイル。
  • vifm-help.txt - ヘルプテキスト。
  • vifminfo - ブックマークおよびゴミ箱の中身。手動で編集することは推奨されていません。
  • Trash/ ディレクトリ - ゴミ箱。
  • colors/ ディレクトリ - カラースキーム。
    • Default - コメントが豊富についているデフォルトのカラースキーム。コピーして自分でカラースキームを作成できます。

最初に以下のドキュメントを読んでください:

  • /usr/share/vifm/vifm.txt
  • /usr/share/vifm/vifm-help.txt

カラースキーム

~/.vifm/colors ディレクトリにはカラースキームを保存します。フォーマットはフ vi/vim のシンタックスハイライトのフォーマットに従っています:

highlight group cterm=attribute ctermfg=color ctermbg=color

例えばカラースキームは以下のようになります:

highlight Win cterm=none ctermfg=white ctermbg=black
highlight Directory cterm=bold ctermfg=cyan ctermbg=none
highlight Link cterm=bold ctermfg=yellow ctermbg=none
highlight BrokenLink cterm=bold ctermfg=red ctermbg=none
highlight Socket cterm=bold ctermfg=magenta ctermbg=none
highlight Device cterm=bold ctermfg=red ctermbg=none
highlight Fifo cterm=bold ctermfg=cyan ctermbg=none
highlight Executable cterm=bold ctermfg=green ctermbg=none
highlight Selected cterm=bold ctermfg=magenta ctermbg=none
highlight CurrLine cterm=bold ctermfg=none ctermbg=blue
highlight TopLine cterm=none ctermfg=black ctermbg=white
highlight TopLineSel cterm=bold ctermfg=black ctermbg=none
highlight StatusLine cterm=bold ctermfg=black ctermbg=white
highlight WildMenu cterm=underline,reverse ctermfg=white ctermbg=black
highlight CmdLine cterm=none ctermfg=white ctermbg=black
highlight ErrorMsg cterm=none ctermfg=red ctermbg=black
highlight Border cterm=none ctermfg=black ctermbg=white

正規表現を使ってファイルタイプをハイライトすることもできます:

highlight /^.*\.(mp3|ogg|oga|flac|m4a)$/ ctermfg=magenta
highlight /^.*\.(jpg|jpeg|png|gif|tiff|webp|bmp|svg|svgz)$/ ctermfg=yellow
highlight /^.*\.(zip|gz|bz2|xz|tar|tgz|tbz2|7z|rar|iso|rpm|deb)$/ ctermfg=red

キーマッピング

0.6.2 現在、Vifm ではキーバインドをカスタマイズできます。以下のように map コマンドを使ってコマンドモードから設定できます:

:map ] :s

ただし、マッピングはセッションを再起動すると消えてしまいます。キーを永続的にマッピングするには ~/vifm/vifmrc にマッピングを記述してください。ファイルの末尾にサンプルマッピングが書かれています。

vifm で開くファイルタイプ

vifmrc を使って以下のようにファイルタイプに対してアプリケーションを指定できます:

filetype *.jpg,*.jpeg,*.png,*.gif feh %f 2>/dev/null &
filetype *.md5 md5sum -c %f

vifmrc には複数のデフォルト設定が存在します。同じフォーマットに従って編集・追加できます。

Feh でカレントディレクトリの画像を表示

filextype *.jpg,*.jpeg,*.png,*.gif
       \ {View in feh}
       \ feh -FZ %d --start-at %d/%c 2>/dev/null

It will display your selected image in feh, but it will enable you to browse all other images in the directory as well, in their default order.

ユーザーコマンド

You can also create custom commands in vifmrc, eg.

command df df -h %m 2> /dev/null
command diff vim -d %f %F

シンボリックリンクの作成

command link ln -s %d/%f %D

When you call

:link

a link of the selected file is made in the other directory (if you are in split view). It even works with multiple files selected with visual (v) or tag (t).

Torrent の作成

make a .torrent of the current file in the other tab's dir

command mkt mktorrent -p -a [your announce url here] -o %D/%f.torrent %d/%f

マーク

Marks can be set same as in vi. To set a mark for current file:

m[a-z][A-Z][0-9]

Go to a file set for mark:

'[a-z][A-Z][0-9]

Vifm will remember the marks between the sessions.

プレビュー

Provided poppler is installed, putting

fileviewer *.pdf
  \ pdftotext %c -

into vifmrc enables pdf-previewing using pdftotext. The %c is a vifm macro for the current file under the cursor. The preview is activated with

:view

Neat image previewing can be achieved using img2txt from libcaca

fileviewer *.png,*.jpeg,*.jpg
 \ img2txt %c 

Previewing the contents of tar-archives:

fileviewer *.tar,*.tar.gz
 \ tar -tvf %c

For previewing html documents suitable programs are text based browsers including lynx, links or w3m

fileviewer *.html
 \ w3m %c

プレビューに役立つプログラム:

  • tree - ディレクトリのプレビュー
  • mp3info - mp3 ファイルの情報を表示
  • libmediainfo - メディア (音声・動画) の情報を表示

ヒントとテクニック

便利なキーマッピング

Single stroke to access command line

nmap ; :

vim を使っていない場合

vifmvim が見つからないとエラーを表示します。vi または nvim (Neovim) を使用する場合、~/.vifm/vifmrc ファイルを編集してください。set vicmd=vim という行をコメントアウトして set vicmd=vi あるいは set vicmd=nvim に置き換えてください。.exrc と同じようにコメント行はダブルクォートを行頭にします。

選択したファイルの合計容量

選択したファイルの合計サイズを表示するには ~/.vifm/vifmrc の %s を以下のように %E に変更してください:

set statusline="  %t%= %A %10u:%-7g %15E %20d  "