インフラエンジニアのPC環境

インフラエンジニアは常に効率環境を目指している

ユーザ用ツール

サイト用ツール


サイドバー

目次

ホーム

OS


CUIソフト

今はほぼ未使用

操作を覚える必要のあるおすすめソフト

Action unknown: copypageplugin__copy
software:filer:vifm


ターミナルで動くviライクなファイルマネージャーvifmの便利な利用方法

vifmとは

  • Linux, Windows, Mac
  • CUI
  • vimと同じようなキー操作で利用できる。
  • 高速に動きます。



僕の設定は以下に置いてあります。
https://github.com/kuritaka/dotfiles/tree/master/.vifm


vifm関連ファイル
.vifm/colors/ カラースキーム
.vifm/scripts/
.vifm/trush/ ゴミ箱
.vifm/vifm-help.txt ヘルプテキスト
.vifm/vifminfo ブックマークおよびゴミ箱の中身。
手動で編集することは推奨されていません。
.vifm/vifmrc 設定ファイル

インストール

Ubuntu20.04

apt install vifm

CentOS7

yumでインストールできない。Sourceからmakeしないとダメ?

# ./configure
# make
# make install

Windows

Binaryをダウンロード(https://vifm.info/downloads.shtml)

Mac

brewでインストールか公式サイトからダウンロード(https://vifm.info/downloads.shtml)

brew install vifm


vifmキー操作

基本

:q
:x
ZZ
vifmの終了
:h ヘルプの表示
C-c
ESC
動作キャンセル
C-l (エル) 再描画
:restart 設定ファイルの再読込

移動

j 下移動
k 上移動
h 親ディレクトリへ
l
Enter
ディレクトリなら掘る,ファイルなら実行
gg 一番上へ移動
G
:$
一番下へ移動
Space
Tab
他方のペインに移動
:number number行へ移動
C-g ファイル情報
C-b 上へ1ページスクロール
C-f 下へ1ページスクロール
:cd ディレクトリ移動(シェルでのcdと同じ)
補完もできます。
:cd /tmp
:cd /home
:sync 逆ペインを同じディレクトリにする
:pwd 現在のパスを表示
/ 検索の開始
:his(tory) 今まで訪れたディレクトリストのポップアップ

ファイル操作

l
Enter
ディレクトリなら掘る,ファイルなら実行(viで編集)
:file filetypeで設定している一覧を表示して、撰択して開く
:sh シェルの起動
dd ファイルを vifm の trash ディレクトリに入れる
※確認が聞かれます
Trashディレクトリのデフォルトは、~/.local/share/Trash との記載がありましたが、
./.vifm-Trash-0/でした。
DD ファイルを完全に削除する。(trashディレクトリに入れない)
※確認が聞かれます
yy ファイルのヤンク(コピー)
p ファイルのペースト(ddもしくはyyしたものなど)
cw リネーム
cW リネームする (拡張子を除く)
:e ファイルをviで編集
:touch テキスト ファイルを作成
:mkdir ディレクトリ名 ディレクトリ作成
:view 反対のペインでファイルの内容表示
:! command シェルでcommandを起動
:!! command シェルでcommandを実行し、vifmに戻るまえに一度止まる
例 !!df -h
例 !!ls -l
:ch name,owner,group,permissionのどれかをチェンジ(メニューが出る)

trash ディレクトリは、~/.local/share/Trash です。

表示

:sort ソート方法の変更(メニューが出る)
:fil hoge hogeの正規表現の結果をフィルタリング
zo 隠しファイルも表示
※僕は設定で最初から隠しファイルを表示するようにしています
zm 隠しファイルは非表示
:only 1ペインにする
:vsp(lit) 左右2ペインにする
※デフォルトの表示方法
:sp(lit) 上下2ペインにする

タブ

:tabnew タブを作成
設定で、「gn」でタブ作成にしている。
nnoremap gn :tabnew<cr>
gt switch to the next tab (wrapping around).
{n}gt switch to the tab number {n} (wrapping around).
gT switch to the previous tab (wrapping around).
{n}gT switch to {n}-th previous tab.

ブックマーク

:marks ブックマークの表示
m[a-z][A-Z][0-9] 場所をブックマーク
'[a-z][A-Z][0-9] ブックマークへアクセス

ブックマークの情報はvifminfoに保存されます。
僕は、この設定ファイルを、viで編集できないので、この方法を使っていないです。

その他

v ビジュアル選択(j,kで移動しながらまとめて選択できる)
:locate filename filenameでlocateした結果表示
:empty ゴミ箱を空に
:trashes ゴミ箱を確認
:lstrash ゴミ箱を確認
:restore
:jobs バックグラウンドジョブの表示
:sh カレントディレクトリで、シェルスクリプト実行


設定

~/.vifm/vifmrc
Windowsの場合は、C:\Users/XXXXX/.vifm/vifmrc

僕の設定は以下に置いてあります。
https://github.com/kuritaka/dotfiles/tree/master/.vifm

表示関連

サイズの前に常に変更時刻

" show hiddden files in both panes "
windo normal zo

" set confirm -=delete,permdelete  "

set viewcolumns=-45%{name}..,5{ext},10{size},12{perms},21{mtime}
set timefmt=" %Y/%m/%d %H:%M:%S "

set statusline="  %t  [%T]%= %A %10u:%-7g %15s %20d [%a free]"
set sizefmt=units:iec,precision:3


" Ignore case in search patterns unless it contains at least one uppercase  "
" letter "
set ignorecase
set smartcase

" Don't highlight search results automatically "
set nohlsearch

" Use increment searching (search while typing)  "
set incsearch

" set line number  "
set number


" show list of matches on tab complition in command-line mode "
set wildmenu

" use popup window instead of a single line for completion "
set wildstyle=popup

" show suggestions "
set suggestoptions=normal,visual,view,otherpane,keys,marks,registers


set history=100

" What should be saved automatically between vifm runs
" Like in previous versions of vifm
" set vifminfo=options,filetypes,commands,bookmarks,dhistory,state,cs
" Like in vi
set vifminfo=dhistory,savedirs,chistory,state,tui,shistory,
    \phistory,fhistory,dirstack,registers,bookmarks,bmarks


コマンド定義

" Synchronize the opposite pane with the current pane "
nnoremap , :sync!<cr>
nnoremap o :sync!<cr>


" Display sorting dialog
nnoremap s :sort<cr>


" スペースキーを「カレントファイルを選択して、カーソルを1つ下に移動」にする "
nnoremap <space> t<down>

" 選択ファイルを他方のディレクトリに移動 "
:com mv mv %f %D
:com cp cp %f %D

" ブックマーク "
:com cdtmp :cd /tmp
:com cdhome :cd /home/user01


:com cheat vi ~/.vifm/cheart.txt


" Faster renaming
nnoremap I cw<c-a>
nnoremap C cw<c-u>
nnoremap A cw


pecoやfzfで検索して、移動【便利】

多く利用するので、「b」で利用できるようにしています。

"fzf の場合"
command bookmark :execute 'cd "'.term('cat ~/.vifm/bookmark.txt | fzf 2>/dev/tty | sed "s/:.*//" ').'"'
"peco の場合"
command bookmark :execute 'cd "'.term('cat ~/.vifm/bookmark.txt | peco 2>/dev/tty | sed "s/:.*//" ').'"'

nnoremap b :bookmark<cr>
~/.vifm/bookmarkt.txt の例
/home/xxxxxxx
/Volume/GoogleDrive/xxxxxxx/
参考

Using fzf with vifm · Issue #279 · vifm/vifm · GitHub

" Write the current bookmarks to a file (same as EvilDroidMax)
command! fzfreadbmarks :exe "normal! :bmarks\r:write ~/.config/vifm/fzf-read/bookmarks\rq"

" Fzf through bookmarks
if $TMUX
    " Use popup window. Requires tmux 3.2 and up
    command! fzfbmarks :execute 'cd "'.system('cat ~/.config/vifm/fzf-read/bookmarks | fzf-tmux -p 90,30 | sed "s/:.*//" ').'"'
    command! fdcddir :execute 'cd "'.system('fd -HE ''.git'' -t d . | fzf-tmux -p 90,30').'"'
    command! fdeditfiles :execute 'edit "'.system('fd -HE ''.git'' -t f . | fzf-tmux -p 90,30').'"'
else
    " Use full-screen. Works even without tmux
    command! fzfbmarks :execute 'cd "'.term('cat ~/.config/vifm/fzf-read/bookmarks | fzf 2>/dev/tty | sed "s/:.*//" ').'"'
    command! fdcddir :execute 'cd "'.term('fd -HE ''.git'' -t d . | fzf 2>/dev/tty').'"'
    command! fdeditfiles :execute 'edit "'.term('fd -HE ''.git'' -t f . | fzf 2>/dev/tty').'"'
endif

  " Read in latests bookmarks before fzfinding through them
command! fzfmarks :fzfreadbmarks | fzfbmarks

  " fzfind bookmarks
nnoremap <space>r :fzfmarks<cr>
  " cd to child directory
nnoremap <space>e :fdcddir<cr>
  " edit file from child directory in vim
nnoremap <space>f :fdeditfiles<cr>


プログラム

nnoremap F :file<cr>

" -N は --LINE-NUMBERS で行表示 "
set vicmd="less -N"

command! vim vim %f
nnoremap E :vim<cr>

" %f 今のペインの選択ファイルと、反対ペインの選択ファイルをDiff "
command diff vim -d %f %F
vimdiff(vim -d)メモ
  • ウィンドウ間を移動するには Ctrl-W Ctrl-W と入力(Ctrl-Wを2回)
    • または、 Ctrl-W Ctrl-lで右へ。Ctrl-W Ctrl-hで左へ。
  • dp(diff putの略)で、自分の内容をもう一方のファイルに反映
  • do(diff obtainの略)で、もう一方のファイルに内容を自分に反映 (僕はこっちは利用しない)

Mac

"カレントファイルを関連付けられたデフォルトのアプリケーションで開く。"
nnoremap X :!open %f<cr>

" Pdf "
filetype {*.pdf},<application/pdf>
       \ {Open in Preview}
       \ open -a Preview.app,
       \ {Open in Skim}
       \ open -a Skim.app,
fileviewer {*.pdf},<application/pdf> pdftotext -nopgbrk %c -

" Office files  "
filetype *.doc,*.docx open -a 'Microsoft Word.app'
filetype *.xls,*.xlsx open -a 'Microsoft Excel.app'
filetype *.ppt,*.pptx open -a 'Microsoft PowerPoint.app'

" Open .pkg binaries  "
filetype *.pkg open


filetype *.gsheet open
filetype *.gslides open

filetype *.drawio  open

Windows WSL

" Open Default Application
nnoremap X :!explorer.exe %f&<cr>

nnoremap F :file<cr>

filetype *.pdf wslview %c

filetype *.mp4 explorer.exe %c &
filetype *.mp3 explorer.exe %c &

filetype *.drowio explorer.exe %c &

filetype *.doc,*.docx explorer.exe %c &
filetype *.xls,*.xlsx explorer.exe %c &
filetype *.ppt,*.pptx explorer.exe %c &

Windows

" カレントファイルを関連付けられたデフォルトのアプリケーションで開く。 "
" Windows "
" Trying to open files with spaces opens Explorer - Windows OS #41
" https://github.com/vifm/vifm/issues/41
filetype * start %"c, explorer %"c



"set vicmd="C:/msys64/usr/bin/less.exe -N"  "
set vicmd="C:/HashiCorp/Vagrant/embedded/usr/bin/less.exe -N"


command! vim "C:/Program Files/Git/usr/bin/vim.exe" %f
nnoremap E :vim<cr>


filextype *.pdf
        \ {View in AR}
        \ "C:/Program Files/SumatraPDF/SumatraPDF.exe" %"f &,


How to copy path to current file/directory to system clipboard

Mac
"yank current directory path into the clipboard"
nnoremap yd :!echo -n %d | pbcopy %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr>

"yank current file path into the clipboard"
nnoremap yf :!echo -n %c:p | pbcopy %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr>

"yank current filename without path into the clipboard"
nnoremap yn :!echo -n %c | pbcopy %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr>

"yank root of current file's name into the clipboard"
nnoremap yr :!echo -n %c:r | pbcopy %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr>
Windows WSL
" Yank current directory path into the clipboard
nmap yd :!echo %d | clip.exe %i<cr>

" Yank current file path into the clipboard
nmap yf :!echo %c:p | clip.exe %i<cr>
Windows
" yank current directory path to Windows clipboard with forward slashes "
nnoremap yp :!echo %"d:gs!\!/!%i| clip<cr>

" yank current directory path to Windows clipboard with backward slashes "
nnoremap yP :!echo %"d%i| clip<cr>

" yank path to current file to Windows clipboard with forward slashes "
nnoremap yf :!echo %"c:gs!\!/!%i| clip<cr>

" yank path to current directory to Windows clipboard with backward slashes
nnoremap yF :!echo %"c%i| clip<cr>

" yank current filename without path to Windows clipboard "
nnoremap yn :!echo %"c%i| clip<cr>

" yank root of current file's name to Windows clipboard "
nnoremap yr :!echo %"c:r%i| clip<cr>
Linux
" yank current directory path into the clipboard "
nnoremap yd :!echo -n %d | xclip -selection clipboard %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr>

" yank current file path into the clipboard "
nnoremap yf :!echo -n %c:p | xclip -selection clipboard %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr>

" yank current filename without path into the clipboard "
nnoremap yn :!echo -n %c | xclip -selection clipboard %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr>

" yank root of current file's name into the clipboard "
nnoremap yr :!echo -n %c:r | xclip -selection clipboard %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr>
" yank current directory path into primary and selection clipboards "
nnoremap yd :!echo -n %d | xsel --input --primary %i &&
            \ echo -n %d | xsel --clipboard --input %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr>

" yank current file path into primary and selection clipboards "
nnoremap yf :!echo -n %c:p | xsel --input --primary %i &&
            \ echo -n %c:p | xsel --clipboard --input %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr>

" yank current filename without path into primary and selection clipboards "
nnoremap yn :!echo -n %c | xsel --input --primary %i &&
            \ echo -n %c | xsel --clipboard --input %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr>

" yank root of current file's name into primary and selection clipboards "
nnoremap yr :!echo -n %c:r | xsel --input --primary %i &&
            \ echo -n %c:r | xsel --clipboard --input %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr>


FUSE Mount

sshfs

Macでのfuse準備

brew install macfuse
brew install gromgit/fuse/sshfs-mac
セキュリティエラー対応
  1. シャットダウンする
  2. その後電源ボタンを長押しし、Loading startup options(起動オプションを読み込み中)と表示されるのを待つ
  3. オプション(歯車マークの方)を押して「続行」します
  4. 上のツールバーにあるStartup Security Utility(起動セキュリティユーティリティ)を探して選びます。
  5. Security PolicyからAllow user management of kernel extensions from identified developers(特定された開発者のカーネル拡張の管理をユーザーに許可する)というチェックボックスにチェックを入れます
  6. OKボタンを連打して、再度システムを再起動

Linux, WSL2

sudo apt install sshfs

設定

vifmrc
:filetype *.ssh FUSE_MOUNT2|sshfs %PARAM %DESTINATION_DIR
server1.ssh
username@server1:/home/username

使い方

あとは、vifmで、.sshファイルを開くだけ。

ftp with curlftpfs

Linux, WSL2

$ sudo apt install curlftpfs

設定

vifmrc
#### 固まる ######
" FtpMount
filetype *.ftp
       \ {Mount with CurlFtpFS}
       \ FUSE_MOUNT2|curlftpfs -o ftp_port=-,,disable_eprt %PARAM %DESTINATION_DIR %CLEAR,
#### これで動いた ######
" FtpMount
filetype *.ftp
       \ {Mount with CurlFtpFS}
       \ FUSE_MOUNT2|curlftpfs %PARAM %DESTINATION_DIR %CLEAR,
*.ftp
-o user=<user-name> <server-address>:
-o user=username:password   192.168.100.10:7777
ftp.gnu.org


仮想ディレクトリ

zip などのアーカイブも展開せずに中を開くために、 FUSE を利用します。

$ brew cask install osxfuse
$ brew install fuse-zip


アイコンをつける

アイコン用設定

フォント

NERDfont
https://www.nerdfonts.com/font-downloads

例えば、「Caskaydia Cove Nerd Font」をダウンロードし、
Caskaydia Cove Nerd Font Complete Mono Windows Compatible Regular.otf をインストールする。


参考


software/filer/vifm.txt · 最終更新: 2023/03/26 01:36 by kurihara

ページ用ツール