added tabby and telescope tab for managing tabs in nvim

This commit is contained in:
jjwoz 2024-04-01 06:28:34 -04:00
parent 375591f85b
commit e7b01ccca5
3 changed files with 157 additions and 3 deletions

View File

@ -86,6 +86,7 @@ P.S. You can delete this when you're done too. It's your config now! :)
-- Set <space> as the leader key -- Set <space> as the leader key
-- See `:help mapleader` -- See `:help mapleader`
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
vim.opt.termguicolors = true
vim.g.mapleader = ' ' vim.g.mapleader = ' '
vim.g.maplocalleader = ' ' vim.g.maplocalleader = ' '
@ -93,18 +94,21 @@ vim.g.maplocalleader = ' '
vim.opt.swapfile = false vim.opt.swapfile = false
-- Set to true if you have a Nerd Font installed -- Set to true if you have a Nerd Font installed
vim.g.have_nerd_font = false vim.g.have_nerd_font = true
-- [[ Setting options ]] -- [[ Setting options ]]
-- See `:help vim.opt` -- See `:help vim.opt`
-- NOTE: You can change these options as you wish! -- NOTE: You can change these options as you wish!
-- For more options, you can see `:help option-list` -- For more options, you can see `:help option-list`
-- At default, neovim only display tabline when there are at least two tab pages. If you want always display tabline:
vim.o.showtabline = true
-- Make line numbers default -- Make line numbers default
vim.opt.number = true vim.opt.number = true
-- You can also add relative line numbers, for help with jumping. -- You can also add relative line numbers, for help with jumping.
-- Experiment for yourself to see if you like it! -- Experiment for yourself to see if you like it!
-- vim.opt.relativenumber = true vim.opt.relativenumber = true
-- Enable mouse mode, can be useful for resizing splits for example! -- Enable mouse mode, can be useful for resizing splits for example!
vim.opt.mouse = 'a' vim.opt.mouse = 'a'
@ -173,7 +177,16 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagn
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
-- -- Tabby keymaps
vim.api.nvim_set_keymap('n', '<leader>ta', ':$tabnew<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>tc', ':tabclose<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>to', ':tabonly<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>tn', ':tabn<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>tp', ':tabp<CR>', { noremap = true })
-- move current tab to previous position
vim.api.nvim_set_keymap('n', '<leader>tmp', ':-tabmove<CR>', { noremap = true })
-- move current tab to next position
vim.api.nvim_set_keymap('n', '<leader>tmn', ':+tabmove<CR>', { noremap = true })
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which -- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which

View File

@ -0,0 +1,115 @@
local theme = {
fill = 'TabLineFill',
head = 'TabLine',
current_tab = 'TabLineSel',
tab = 'TabLine',
win = 'TabLine',
tail = 'TabLine',
}
local open_tabs = {}
local tab_name = function(tab)
local api = require 'tabby.module.api'
local cur_win = api.get_tab_current_win(tab.id)
if api.is_float_win(cur_win) then
return '[Floating]'
end
local current_bufnr = vim.fn.getwininfo(cur_win)[1].bufnr
local current_bufinfo = vim.fn.getbufinfo(current_bufnr)[1]
local current_buf_name = vim.fn.fnamemodify(current_bufinfo.name, ':t')
-- local no_extension = vim.fn.fnamemodify(current_bufinfo.name, ":p:r")
if string.find(current_buf_name, 'NvimTree') ~= nil then
return '[File Explorer]'
end
if current_buf_name == 'NeogitStatus' then
return '[Neogit]'
end
if open_tabs[current_bufinfo.name] == nil then
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
open_tabs[current_bufinfo.name] = project_name
end
if current_buf_name == '' then
return '[Empty]'
else
if open_tabs[current_bufinfo.name] == nil then
return current_buf_name
end
return open_tabs[current_bufinfo.name] .. ':' .. current_buf_name
end
end
local tab_count = function()
local num_tabs = #vim.api.nvim_list_tabpages()
if num_tabs > 1 then
local tabpage_number = tostring(vim.api.nvim_tabpage_get_number(0))
return tabpage_number .. '/' .. tostring(num_tabs)
end
end
local change_mark = function(tab)
local already_marked = false
return tab.wins().foreach(function(win)
local bufnr = vim.fn.getwininfo(win.id)[1].bufnr
local bufinfo = vim.fn.getbufinfo(bufnr)[1]
if not already_marked and bufinfo.changed == 1 then
already_marked = true
return ''
else
return ''
end
end)
end
local window_count = function(tab)
local api = require 'tabby.module.api'
local win_count = #api.get_tab_wins(tab.id)
if win_count == 1 then
return ''
else
return '[' .. win_count .. ']'
end
end
return {
'nanozuki/tabby.nvim',
event = 'VeryLazy',
config = function()
require('tabby.tabline').set(function(line)
return {
{
{ ' 󰓩 ', hl = theme.head },
{ tab_count(), hl = theme.head },
-- line.sep(" ", theme.head, theme.fill),
line.sep(' ', theme.head, theme.fill),
},
line.tabs().foreach(function(tab)
local hl = tab.is_current() and theme.current_tab or theme.tab
return {
-- line.sep("", hl, theme.fill),
line.sep('', hl, theme.fill),
tab.is_current() and '' or '',
tab_name(tab),
-- tab.close_btn("󰅖 "),
-- window_count(tab),
-- change_mark(tab),
-- line.sep(" ", hl, theme.fill),
line.sep('', hl, theme.fill),
hl = hl,
margin = ' ',
}
end),
hl = theme.fill,
}
end, {
buf_name = {
mode = 'unique',
},
})
end,
}

View File

@ -0,0 +1,26 @@
local M = {
'LukasPietzschmann/telescope-tabs',
event = 'VeryLazy',
}
function M.config()
local wk = require 'which-key'
wk.register {
['<leader>aa'] = {
"<cmd>lua require('telescope').extensions['telescope-tabs'].list_tabs(require('telescope.themes').get_dropdown{previewer = false, initial_mode='normal', prompt_title='Tabs'})<cr>",
'Find Tabs',
},
}
require('telescope-tabs').setup {
show_preview = false,
close_tab_shortcut_i = '<C-d>', -- if you're in insert mode
close_tab_shortcut_n = 'dd', -- if you're in normal mode
entry_formatter = function(tab_id, buffer_ids, file_names, file_paths, is_current)
local entry_string = table.concat(file_names, ', ')
return string.format('%d: %s%s', tab_id, entry_string, is_current and '' or '')
end,
}
end
return M