Skip to content

Commit

Permalink
✨feat: tablineとbuflineを移動時だけ表示
Browse files Browse the repository at this point in the history
  • Loading branch information
utubo committed Dec 4, 2024
1 parent 7fc2696 commit e5f9b8f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 128 deletions.
53 changes: 9 additions & 44 deletions .vim/autoload/vimrc/bufline.vim
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
vim9script
g:buflist_term_sign = get(g:, 'buflist_term_sign', "\uf489")
var k = 0
var k = ''
var n = ''
var q = ''
var t = ''
var p = ''
def A()
q = ''
n = ''
var a = []
const b = execute('ls')->split("\n")
const c = &columns / (!b ? 1 : len(b))
Expand All @@ -29,51 +28,17 @@ endif
const h = $'{e}:{f}'
const i = m[2][0] ==# '%'
if i
n = a->join(' ')
q = (!n ? '' : ' ') .. h .. ' '
k = a->join(' ')
n = (!k ? '' : ' ') .. h .. ' '
a = []
else
add(a, h)
endif
endfor
t = a->join(' ')
p = a->join(' ')
enddef
export def Popup()
if !n && !t
return
endif
var w = &columns
const o = getwininfo(win_getid(1))[0].textoff
w -= o
const s = q->substitute($'\%{w}v.*', '', '')
w -= strdisplaywidth(s)
var l = n->reverse()->substitute($'\%{w}v.*', '', '')->reverse()
if l !=# n
l = l->substitute('^.', '<', '')
endif
w -= strdisplaywidth(l)
var r = t->substitute($'\%{w}v.*', '', '')
if r !=# t
r = r->substitute('.$', '>', '')
endif
w -= strdisplaywidth(r)
const p = max([0, w])
var a = popup_create($'{l}{s}{r}', {
line: 1,
col: 1,
fixed: true,
highlight: 'TabLine',
padding: [0, p, 0, o],
moved: 'any',
})
if !!k
popup_close(k)
endif
k = a
enddef
export def Show()
export def MyBufline(): string
A()
Popup()
enddef
export def Setup()
const o = getwininfo(win_getid(1))[0].textoff
return $'{repeat(' ', o)}{k}%#TabLineSel#{n}%#TabLine#{p}'
enddef
40 changes: 23 additions & 17 deletions .vim/autoload/vimrc/lazyload.vim
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ au vimrc SafeState * ++once B()
enddef
au vimrc BufReadPost * C()
C()
Each n,p nmap g{} <SID>(buf)n|nm <SID>(buf){} <Cmd>b{}<CR><Cmd>call vimrc#bufline#Show()<CR><SID>(buf)
g:recentBufnr = 0
au vimrc BufLeave * g:recentBufnr = bufnr()
nn <expr> gr $"\<Cmd>b{g:recentBufnr}\<CR>"
Expand Down Expand Up @@ -251,14 +250,21 @@ echoh Normal
echow expand('%:p:h')
enddef
nn <script> <C-g> <ScriptCmd>D()<CR>
set tabline=%!vimrc#tabline#MyTabline()
set showtabline=0
def E(t: string)
set showtabline=1
exe $'normal! g{t}'
def E(a: string)
set tabline=%!vimrc#tabline#MyTabline()
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>E('{}')<CR><SID>(tab)
def F(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>F('{}')<CR><SID>(buf)
nn <Space>e G?\cErr\\|Exception<CR>
nn <expr> <Space>f $'{(getreg('"') =~ '^\d\+$' ? ':' : '/')}{getreg('"')}<CR>'
nm <Space>. :
Expand All @@ -273,7 +279,7 @@ nn <Space>a A
nn <Space>h ^
nn <Space>l $
nn <Space>y yiw
def F()
def G()
if !!bufname()
update
return
Expand Down Expand Up @@ -308,7 +314,7 @@ if !!e
exe 'sav' e
endif
enddef
com! AutoNamingAndSave F()
com! AutoNamingAndSave G()
cno ;n <CR>
Each nnoremap,inoremap ;n <Esc><Cmd>AutoNamingAndSave<CR>
ino ;m <Esc>`^
Expand Down Expand Up @@ -453,31 +459,31 @@ nn <silent> <F10> <ESC>1<C-w>s:1<CR><C-w>w
xn <F10> <ESC>1<C-w>s<C-w>w
nn <F9> my
nn <Space><F9> 'y
def G()
def H()
for a in get(w:, 'my_syntax', [])
sil! matchdelete(a)
endfor
w:my_syntax = []
enddef
def H(a: string, b: string)
def I(a: string, b: string)
w:my_syntax->add(matchadd(a, b))
enddef
au vimrc Syntax * G()
au vimrc Syntax * H()
au vimrc Syntax javascript {
H('SpellRare', '\s[=!]=\s')
I('SpellRare', '\s[=!]=\s')
}
au vimrc Syntax vim {
H('SpellRare', '\s[=!]=\s')
H('SpellBad', '\s[=!]==\s')
H('SpellBad', '\s\~[=!][=#]\?\s')
H('SpellRare', '\<normal!\@!')
I('SpellRare', '\s[=!]=\s')
I('SpellBad', '\s[=!]==\s')
I('SpellBad', '\s\~[=!][=#]\?\s')
I('SpellRare', '\<normal!\@!')
}
set report=9999
def g:EchoYankText(t: number)
vimrc#echoyanktext#EchoYankText()
enddef
au vimrc TextYankPost * timer_start(1, g:EchoYankText)
def I()
def J()
normal! "vygv
var a = @v->substitute('\n', '', 'g')
popup_create($'{strlen(a)}chars', {
Expand All @@ -488,7 +494,7 @@ moved: 'any',
padding: [1, 1, 1, 1],
})
enddef
xn <C-g> <ScriptCmd>I()<CR>
xn <C-g> <ScriptCmd>J()<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)
Expand Down
62 changes: 3 additions & 59 deletions src/.vim/autoload/vimrc/bufline.src.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ vim9script
# `>_`みたいなアイコン
g:buflist_term_sign = get(g:, 'buflist_term_sign', "\uf489")

var pum = 0
var left = ''
var select = ''
var right = ''
Expand Down Expand Up @@ -44,64 +43,9 @@ def RefreshBufList()
right = bufs->join(' ')
enddef

export def Popup()
if !left && !right
return
endif
var w = &columns
# 左オフセット
const o = getwininfo(win_getid(1))[0].textoff
w -= o
# 選択バッファ
const s = select->substitute($'\%{w}v.*', '', '')
w -= strdisplaywidth(s)
# 選択より左側
var l = left->reverse()->substitute($'\%{w}v.*', '', '')->reverse()
if l !=# left
l = l->substitute('^.', '<', '')
endif
w -= strdisplaywidth(l)
# 選択より右側
var r = right->substitute($'\%{w}v.*', '', '')
if r !=# right
r = r->substitute('.$', '>', '')
endif
w -= strdisplaywidth(r)
# 右パディング
const p = max([0, w])
# 表示
#redraw
var newpum = popup_create($'{l}{s}{r}', {
line: 1,
col: 1,
fixed: true,
highlight: 'TabLine',
padding: [0, p, 0, o],
moved: 'any',
})
#echoh TabLineFill
#echon repeat(' ', o)
#echoh TabLine
#echon l
#echoh TabLineSel
#echon s
#echoh TabLine
#echon r
#echoh TabLineFill
#echon repeat(' ', p)
#echoh Normal
if !!pum
popup_close(pum)
endif
pum = newpum
enddef

export def Show()
export def MyBufline(): string
RefreshBufList()
Popup()
enddef

export def Setup()
# nop
const o = getwininfo(win_getid(1))[0].textoff
return $'{repeat(' ', o)}{left}%#TabLineSel#{select}%#TabLine#{right}'
enddef

24 changes: 16 additions & 8 deletions src/.vim/autoload/vimrc/lazyload.src.vim
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ SetupTabstopLazy()

# ------------------------------------------------------
# バッファ操作 {{{
# gnとgpで移動
Each n,p nmap g{} <SID>(buf)n|nmap <SID>(buf){} <Cmd>b{}<CR><Cmd>call vimrc#bufline#Show()<CR><SID>(buf)
# grで直前のバッファ
g:recentBufnr = 0
au vimrc BufLeave * g:recentBufnr = bufnr()
Expand Down Expand Up @@ -375,15 +373,25 @@ nnoremap <script> <C-g> <ScriptCmd>ShowBufInfo()<CR>
#}}} -------------------------------------------------------

# ------------------------------------------------------
# Tabline {{{
set tabline=%!vimrc#tabline#MyTabline()
# TablineとBufline {{{
# gt, gTしたときだけtablineを表示する(thx:kawarimidollさん)
set showtabline=0
def ShowTab(t: string)
set showtabline=1
execute $'normal! g{t}'
def ShowTab(a: string)
set tabline=%!vimrc#tabline#MyTabline()
set showtabline=2
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 t,T nmap g{} <SID>(tab){} | nmap <SID>(tab){} <ScriptCmd>ShowTab('{}')<CR><SID>(tab)
# gnとgpでバッファ移動
def ShowBuf(a: string)
set tabline=%!vimrc#bufline#MyBufline()
set showtabline=2
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)
#}}}

# ------------------------------------------------------
Expand Down

0 comments on commit e5f9b8f

Please sign in to comment.