Skip to content

Commit

Permalink
✨feat: Eachを使いやすくした!
Browse files Browse the repository at this point in the history
  • Loading branch information
utubo committed Dec 5, 2024
1 parent d29cfa6 commit 3bafa74
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
34 changes: 18 additions & 16 deletions .vim/autoload/vimrc/lazyload.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
vim9script
g:util_each_nest = 0
def! g:UtilEach(b: string)
const [c, d] = b->split('^\S*\zs')
var [c, d] = b->split('^\S*\zs')
g:util_each_nest += 1
for i in c->split(',')
var a = d->substitute('{0\?}', i, 'g')
var e = c->split(',')
const f = e[0]->split('=')
const k = len(f) ==# 1 ? '{0\?}' : f[0]
e[0] = f[-1]
for i in e
var a = d->substitute(k, i, 'g')
if a ==# d
a = $'{i} {a}'
endif
Expand Down Expand Up @@ -47,8 +51,7 @@ g:vim9skk_mode = ''
nn ;j i<Plug>(vim9skk-enable)
au vimrc ModeChanged [ic]:n au SafeState * ++once vim9skk#Disable()
au vimrc User Vim9skkInitPre vimrc#vim9skk#ApplySettings()
Each onoremap,xnoremap ab <Plug>(textobj-multiblock-a)
Each onoremap,xnoremap ib <Plug>(textobj-multiblock-i)
Each X=a,i Each onoremap,xnoremap Xb <Plug>(textobj-multiblock-X)
g:textobj_multiblock_blocks = [
[ "(", ")" ],
[ "[", "]" ],
Expand Down Expand Up @@ -108,8 +111,7 @@ Each imap,smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : p
g:skipslash_autocomplete = 1
nn <Space>t <ScriptCmd>tabpopupmenu#popup()<CR>
nn <Space>T <ScriptCmd>tablist#Show()<CR>
Each nnoremap,tnoremap <silent> <C-w><C-s> <Plug>(shrink-height)<C-w>w
Each nnoremap,tnoremap <silent> <C-w><C-h> <Plug>(shrink-width)<C-w>w
Each X=s,h Each nnoremap,tnoremap <silent> <C-w><C-X> <Plug>(shrink-height)<C-w>w
no <Space>s <Plug>(jumpcursor-jump)
vimrc#lexima#LazyLoad()
vimrc#lsp#LazyLoad()
Expand All @@ -120,7 +122,7 @@ com! -nargs=* Fern vimrc#fern#LazyLoad(<q-args>)
nn <F1> <Cmd>Fern . -reveal=% -opener=edit<CR>
Enable g:rainbow_active
g:auto_cursorline_wait_ms = &ut
Each w,b,e,ge nnoremap {0} <Plug>(smartword-{0})
Each X=w,b,e,ge nnoremap X <Plug>(smartword-X)
nn [c <Plug>(GitGutterPrevHunk)
nn ]c <Plug>(GitGutterNextHunk)
Each nnoremap,xnoremap <Space>c <Plug>(caw:hatpos:toggle)
Expand All @@ -132,9 +134,9 @@ au vimrc InsertLeave * set nopaste
au vimrc FileReadPost *.log* normal! G
xn * "vy/\V<C-r>=substitute(escape(@v,'\/'),"\n",'\\n','g')<CR><CR>
set mps+=(:),「:」,『:』,【:】,[:],<:>
Each i,a,A nnoremap <expr> {0} !empty(getline('.')) ? '{0}' : '"_cc'
Each +,-,>,< Each nmap,tmap <C-w>{0} <C-w>{0}<SID>ws
Each +,-,>,< Each nnoremap,tnoremap <script> <SID>ws{0} <C-w>{0}<SID>ws
Each X=i,a,A nnoremap <expr> X !empty(getline('.')) ? 'X' : '"_cc'
Each X=+,-,>,< Each nmap,tmap <C-w>X <C-w>X<SID>ws
Each X=+,-,>,< Each nnoremap,tnoremap <script> <SID>wsX <C-w>X<SID>ws
Each nmap,tmap <SID>ws <Nop>
nn <A-J> <Cmd>copy.<CR>
nn <A-K> <Cmd>copy-1<CR>
Expand Down Expand Up @@ -265,14 +267,14 @@ set showtabline=2
exe $'normal! g{a}'
au SafeState * ++once au CursorMoved * ++once set showtabline=0
enddef
Each t,T nmap g{} <SID>(tab){}|nm <SID>(tab){} <ScriptCmd>F('{}')<CR><SID>(tab)
Each X=t,T nmap gX <SID>(tab)X|nm <SID>(tab)X <ScriptCmd>F('X')<CR><SID>(tab)
def G(a: string)
set tabline=%!vimrc#bufline#MyBufline()
set showtabline=2
exe $'b{a}'
au SafeState * ++once au CursorMoved * ++once set showtabline=0
enddef
Each n,p nmap g{} <SID>(buf){}|nm <SID>(buf){} <ScriptCmd>G('{}')<CR><SID>(buf)
Each X=n,p nmap gX <SID>(buf)X|nm <SID>(buf)X <ScriptCmd>G('X')<CR><SID>(buf)
nn <Space>e G?\cErr\\|Exception<CR>
nn <expr> <Space>f $'{(getreg('"') =~ '^\d\+$' ? ':' : '/')}{getreg('"')}<CR>'
nm <Space>. :
Expand Down Expand Up @@ -376,7 +378,7 @@ else
confirm quit
endif
enddef
Each h,j,k,l nnoremap q{0} <ScriptCmd>g:QuitWin('{0}')<CR>
Each X=h,j,k,l nnoremap qX <ScriptCmd>g:QuitWin('X')<CR>
nn q <Nop>
nn Q q
nn <expr> qq $"\<Cmd>confirm {winnr('$') ==# 1 && execute('ls')->split("\n")->len() !=# 1 ? 'bd' : 'q'}\<CR>"
Expand Down Expand Up @@ -504,8 +506,8 @@ padding: [1, 1, 1, 1],
enddef
xn <C-g> <ScriptCmd>BA()<CR>
com! -nargs=1 Brep vimrc#myutil#Brep(<q-args>, <q-mods>)
Each f,b nmap <C-{0}> <C-{0}><SID>(hold-ctrl)
Each f,b nnoremap <script> <SID>(hold-ctrl){0} <C-{0}><SID>(hold-ctrl)
Each $=f,b nmap <C-$> <C-$><SID>(hold-ctrl)
Each $=f,b nnoremap <script> <SID>(hold-ctrl)$ <C-$><SID>(hold-ctrl)
nm <SID>(hold-ctrl) <Nop>
ono A <Plug>(textobj-twochars-a)
ono I <Plug>(textobj-twochars-i)
Expand Down
36 changes: 20 additions & 16 deletions src/.vim/autoload/vimrc/lazyload.src.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ vim9script
# 先頭以外に差し込んだりネストしたい場合はこう
# Each j,k Each nmap,xmap {1} {0} g{0}
# → nmap j gj | xmap j gj | nmap k gk | xmap k gk
# 名前をつけたい場合はこう
# Each X=j,k Each cmd=nmap,xmap cmd X gX
# ※これ使うよりべたで書いたほうが起動は速い
g:util_each_nest = 0
def! g:UtilEach(qargs: string)
const [items, args] = qargs->split('^\S*\zs')
var [items, args] = qargs->split('^\S*\zs')
g:util_each_nest += 1
for i in items->split(',')
var a = args->substitute('{0\?}', i, 'g')
var values = items->split(',')
const kv = values[0]->split('=')
const k = len(kv) ==# 1 ? '{0\?}' : kv[0]
values[0] = kv[-1]
for i in values
var a = args->substitute(k, i, 'g')
if a ==# args
a = $'{i} {a}'
endif
Expand Down Expand Up @@ -84,8 +90,7 @@ au vimrc User Vim9skkInitPre vimrc#vim9skk#ApplySettings()
#}}}

# textobj-user {{{
Each onoremap,xnoremap ab <Plug>(textobj-multiblock-a)
Each onoremap,xnoremap ib <Plug>(textobj-multiblock-i)
Each X=a,i Each onoremap,xnoremap Xb <Plug>(textobj-multiblock-X)
g:textobj_multiblock_blocks = [
[ "(", ")" ],
[ "[", "]" ],
Expand Down Expand Up @@ -169,8 +174,7 @@ Each imap,smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : p
g:skipslash_autocomplete = 1
nnoremap <Space>t <ScriptCmd>tabpopupmenu#popup()<CR>
nnoremap <Space>T <ScriptCmd>tablist#Show()<CR>
Each nnoremap,tnoremap <silent> <C-w><C-s> <Plug>(shrink-height)<C-w>w
Each nnoremap,tnoremap <silent> <C-w><C-h> <Plug>(shrink-width)<C-w>w
Each X=s,h Each nnoremap,tnoremap <silent> <C-w><C-X> <Plug>(shrink-height)<C-w>w
noremap <Space>s <Plug>(jumpcursor-jump)
# }}}

Expand All @@ -190,7 +194,7 @@ nnoremap <F1> <Cmd>Fern . -reveal=% -opener=edit<CR>
# その他 {{{
Enable g:rainbow_active
g:auto_cursorline_wait_ms = &updatetime
Each w,b,e,ge nnoremap {0} <Plug>(smartword-{0})
Each X=w,b,e,ge nnoremap X <Plug>(smartword-X)
nnoremap [c <Plug>(GitGutterPrevHunk)
nnoremap ]c <Plug>(GitGutterNextHunk)
Each nnoremap,xnoremap <Space>c <Plug>(caw:hatpos:toggle)
Expand All @@ -212,11 +216,11 @@ xnoremap * "vy/\V<C-r>=substitute(escape(@v,'\/'),"\n",'\\n','g')<CR><CR>
# https://github.com/astrorobot110/myvimrc/blob/master/vimrc
set matchpairs+=(:),「:」,『:』,【:】,[:],<:>
# https://github.com/Omochice/dotfiles
Each i,a,A nnoremap <expr> {0} !empty(getline('.')) ? '{0}' : '"_cc'
Each X=i,a,A nnoremap <expr> X !empty(getline('.')) ? 'X' : '"_cc'
# すごい
# https://zenn.dev/mattn/articles/83c2d4c7645faa
Each +,-,>,< Each nmap,tmap <C-w>{0} <C-w>{0}<SID>ws
Each +,-,>,< Each nnoremap,tnoremap <script> <SID>ws{0} <C-w>{0}<SID>ws
Each X=+,-,>,< Each nmap,tmap <C-w>X <C-w>X<SID>ws
Each X=+,-,>,< Each nnoremap,tnoremap <script> <SID>wsX <C-w>X<SID>ws
Each nmap,tmap <SID>ws <Nop>
# 感謝
# https://zenn.dev/vim_jp/articles/43d021f461f3a4
Expand Down Expand Up @@ -390,7 +394,7 @@ def ShowTab(a: string)
execute $'normal! g{a}'
au SafeState * ++once au CursorMoved * ++once set showtabline=0
enddef
Each t,T nmap g{} <SID>(tab){} | nmap <SID>(tab){} <ScriptCmd>ShowTab('{}')<CR><SID>(tab)
Each X=t,T nmap gX <SID>(tab)X | nmap <SID>(tab)X <ScriptCmd>ShowTab('X')<CR><SID>(tab)
# gnとgpでバッファ移動
def ShowBuf(a: string)
Expand All @@ -399,7 +403,7 @@ def ShowBuf(a: string)
execute $'b{a}'
au SafeState * ++once au CursorMoved * ++once set showtabline=0
enddef
Each n,p nmap g{} <SID>(buf){} | nmap <SID>(buf){} <ScriptCmd>ShowBuf('{}')<CR><SID>(buf)
Each X=n,p nmap gX <SID>(buf)X | nmap <SID>(buf)X <ScriptCmd>ShowBuf('X')<CR><SID>(buf)
#}}}

# ------------------------------------------------------
Expand Down Expand Up @@ -547,7 +551,7 @@ def g:QuitWin(expr: string) # TODO: minifyするとばぐる?
confirm quit
endif
enddef
Each h,j,k,l nnoremap q{0} <ScriptCmd>g:QuitWin('{0}')<CR>
Each X=h,j,k,l nnoremap qX <ScriptCmd>g:QuitWin('X')<CR>
nnoremap q <Nop>
nnoremap Q q
# 閉じる
Expand Down Expand Up @@ -734,8 +738,8 @@ xnoremap <C-g> <ScriptCmd>PopupVisualLength()<CR>
command! -nargs=1 Brep vimrc#myutil#Brep(<q-args>, <q-mods>)

# <C-f><C-b>、CTRLおしっぱがつらいので…
Each f,b nmap <C-{0}> <C-{0}><SID>(hold-ctrl)
Each f,b nnoremap <script> <SID>(hold-ctrl){0} <C-{0}><SID>(hold-ctrl)
Each $=f,b nmap <C-$> <C-$><SID>(hold-ctrl)
Each $=f,b nnoremap <script> <SID>(hold-ctrl)$ <C-$><SID>(hold-ctrl)
nmap <SID>(hold-ctrl) <Nop>
# 🐶🍚
Expand Down

0 comments on commit 3bafa74

Please sign in to comment.