貧乏ラン💰
低燃費重視で効率よくやってこうぜ、ということ。
ドルフロでよくやってます…
2022/11/22追記
あらゆる便利プラグインをvimrcに押し込んでみました。
https://qiita.com/neras_1215/items/b4090deb7c07f52c6ec7
TL;DR
若干の縛りプレイで脳トレ
最小限のプラグインでわりと快適なviを作ろう
viはプラグインが豊富。というかvimscriptなどでいくらでも拡張できるから終わりがない。
では何があれば満足か?
lsp?ddc?coc?贅沢言わないのうちは貧乏なのよ我慢なさい
キー入力は多いが標準viの機能で実現可能、というプラグインは除き、自作関数でどうにかしてみる。
本来、使えるものは全て使えばよろし。(あれ記事の趣旨は?)
おとうさんこれ買って〜😭😭
1. ファジーファインダーでディスクの海からファイルにたどり着く
参考: https://zenn.dev/yutakatay/articles/vim-fuzzy-finder
正直これがないとまともに仕事にならない。何よりも優先して入れるべき。
fzfコマンド本体と
fzf.vimが必要
2. 開いたファイルを物理演算でぬるぬるスクロールする
参考: https://yuttie.hatenablog.jp/entry/2016/12/21/205320
これはプラグインがないと実現できない機能。パンパン機械的にページ移動してると内容が頭に入ってこない。まぁなくても頑張ればいけるけど、貧乏とはいえゆずれないものはあるのです。
3. ファイル上を2次元に瞬間移動
参考: https://github.com/easymotion/vim-easymotion
vimは移動が速いことが他のエディタ/IDEに勝る点。縦方向に行移動してから横方向に移動しているようじゃぁ遅いんだよ!!
思考(至高)のスピードで操作するには、一撃で目当ての単語に飛ぶコイツが必要
4. 言語パック
※対応言語はまだまだあります
参考: https://github.com/sheerun/vim-polyglot
まぁこれはね... シンタックスハイライト的にしょうがない
5. スニペット
参考: https://github.com/hrsh7th/vim-vsnip
なんでデフォでないのか不思議
VSCodeと同一のJSONで定義できるのが良いなって思ったのでこれ使ってます
ほんとはtab補完も欲しいんだけどCtrl-Pでいいし、高度の補完はむしろスニペットがあればよい。
以上。削りに削ったけどこれだけは外せない。
いつかサンタさんが持ってきてくれるよ…🎅🏻
-
ファイルツリー
NERDtree -
tab補完
supertab -
外観
airline
airline-theme
icon
font
※fontはsh fonts/install.sh
が必要 -
IDE化する系のもろもろ
lsp
lsp-setting
ddc
coc
ctagはこちら -
その他
unite
windowサイズ調整楽に
オレオレ関数😎
自動レジスタ選択 + トグル なマーク
マーク時にわざわざ:marks
して使ってない英単語を探すのが面倒なので
一律mm
で、適当なレジスタに登録して欲しい。
マーク行でもっかい押したらマーク解除してほしい。
って関数がこう
function! Marking() abort
let l:now_marks = []
let l:words = 'abcdefghijklmnopqrstuvwxyz'
let l:warr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for row in split(execute('marks'), '\n')
let l:r = filter(split(row, ' '), {i, v -> v != ''})
if stridx(words, r[0]) != -1 && r[1] == line('.')
call execute('delmarks ' . r[0])
echo 'delete mark'
return
endif
let l:now_marks = add(now_marks, r[0])
endfor
let l:can_use = filter(warr, {i, v -> stridx(join(now_marks, ''), v) == -1})
if len(can_use) != 0
call execute('mark ' . can_use[0])
echo 'marked'
else
echo 'over limit markable char'
endif
endfunction
Grep
定義元ジャンプはctagでのCtrl-]
や、ファイル内ならgd
やただの単語検索の*
#
で十分
呼び出し元検索はgrepをする必要がある。
えっと、この単語yw
して、コマンドコマンド...:!grep
えっと...あ:vimgrep
で...
ってしてると遅いので
カーソル位置の単語で、「今開いてるファイルの拡張子で検索」と「拡張子を指定して検索」を用意。
ex) testというカーソル上の単語を、「javaファイル」の中から探したい(classファイルなどは検索対象外にして高速にしたい)
function! GrepCurrentExtention()
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . expand('%:e'))
endfunction
command! -nargs=1 GrepExtFrom call GrepExtFrom(<f-args>)
function! GrepExtFrom(ext)
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . a:ext)
endfunction
コマンドとして実行
いまのファイルを実行、みたいなプラグインどっかにあったと思うんですけど、あれファイル全体なんですよね。
こまかい、よく使うコマンドをまとめたノートもってたとして
この1行だけコピペしてterminalで実行したい!
ってことが私は多かったので作りました
cdはvim内でつかうこと前提で、最近はNERDtree(かデフォのnetrw)でcdしてるのでなくてもよい分岐...
function! ExecuteThisLineCMD()
if stridx(getline('.'), 'cd') == 0
call execute(getline('.'))
else
echo system('eval "' . getline('.') . '"')
endif
endfunction
気休めファイルあいまい検索
ファジーファインダーには敵わない。
command! -nargs=1 Q call FileSearch(<f-args>)
function! FileSearch(name)
for found in split(glob(a:name), "\n")
echo found
endfor
endfunction
最終的に出来上がったもの🍻
あ、プラグイン管理なんて高級品も夢のまた夢なので全部gitで手動です
# fzf
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install --no-key-bindings --completion --no-bash --no-zsh --no-fish
git clone --depth 1 https://github.com/junegunn/fzf.vim ~/.vim/pack/plugins/start/fzf.vim
# motion
git clone --depth 1 https://github.com/easymotion/vim-easymotion.git ~/.vim/pack/plugins/start/vim-easymotion
git clone --depth 1 https://github.com/yuttie/comfortable-motion.vim ~/.vim/pack/plugins/start/comfortable-motion
# edit
git clone --depth 1 https://github.com/hrsh7th/vim-vsnip ~/.vim/pack/plugins/start/vim-vsnip
git clone --depth 1 https://github.com/sheerun/vim-polyglot ~/.vim/pack/plugins/start/vim-polyglot
" ==================== base ====================
" color
colorscheme torte
syntax on
" code
"set ff=unix
"set fileencoding=utf8
" search
set hlsearch
set incsearch
" edit
set splitright
set noswapfile
set backspace=indent,eol,start
set ambiwidth=double
set clipboard+=unnamed
set tabstop=4
" vimgrep
autocmd QuickFixCmdPost *grep* cwindow
" ==================== view ====================
" status
set number
set ruler
set cursorline
set cursorcolumn
set laststatus=2
" file info
set statusline=%F%m%r%h%w%=[all]_%p%%___[row]_%l/%L___[col]_%02v___[%{&fenc!=''?&fenc:&enc}]
" newline code
let ff_table = {'dos' : 'CRLF', 'unix' : 'LF', 'mac' : 'CR' }
set statusline+=[%{ff_table[&ff]}]
" visible
set list
set listchars=tab:»-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%
" ==================== key, plugins ====================
let g:mapleader = "\<Space>"
" netrw
filetype plugin on
let g:netrw_liststyle = 3
let g:netrw_altv = 1
let g:netrw_winsize = 70
" fzf
set rtp+=~/.fzf
nmap <Leader>f :Files<CR>
" easymotion
nmap <Leader>w <Plug>(easymotion-overwin-f)
nmap <Leader>s <Plug>(easymotion-s2)
" vsnips
let g:vsnip_snippet_dir = '~/snips'
imap <expr> <C-s> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-s>'
" scroll
let g:comfortable_motion_interval = 2400.0 / 60
let g:comfortable_motion_friction = 100.0
let g:comfortable_motion_air_drag = 3.0
" ==================== key, func ====================
" find file
command! -nargs=1 Q call FileSearch(<f-args>)
function! FileSearch(name)
for found in split(glob(a:name), "\n")
echo found
endfor
endfunction
" Grep current word in current extention
nmap <Leader>gg :call GrepCurrentExtention()<CR>
function! GrepCurrentExtention()
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . expand('%:e'))
endfunction
" Grep current word in enterd extention
nmap <Leader>ge :GrepExtFrom
command! -nargs=1 GrepExtFrom call GrepExtFrom(<f-args>)
function! GrepExtFrom(ext)
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . a:ext)
endfunction
" marks
nmap mm :call Marking()<CR>
function! Marking() abort
let l:now_marks = []
let l:words = 'abcdefghijklmnopqrstuvwxyz'
let l:warr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for row in split(execute('marks'), '\n')
let l:r = filter(split(row, ' '), {i, v -> v != ''})
if stridx(words, r[0]) != -1 && r[1] == line('.')
call execute('delmarks ' . r[0])
echo 'delete mark'
return
endif
let l:now_marks = add(now_marks, r[0])
endfor
let l:can_use = filter(warr, {i, v -> stridx(join(now_marks, ''), v) == -1})
if len(can_use) != 0
call execute('mark ' . can_use[0])
echo 'marked'
else
echo 'over limit markable char'
endif
endfunction
" execute currenr line text as shell
nmap <Leader>l :call ExecuteThisLineCMD()<CR>
function! ExecuteThisLineCMD()
if stridx(getline('.'), 'cd') == 0
call execute(getline('.'))
else
echo system('eval "' . getline('.') . '"')
endif
endfunction
" ==================== ini ====================
if has('vim_starting')
cd
endif
大人になったら夢が現実になる🍺😭
こちらが私のよく使っている設定です。まぁ上記に毛が生えたようなものですが。。
https://qiita.com/neras_1215/private/186431b475df547c95e1