added bufferline and removed tabby
This commit is contained in:
		
							parent
							
								
									31f0bfe509
								
							
						
					
					
						commit
						f1e6cb34b1
					
				
							
								
								
									
										42
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										42
									
								
								init.lua
								
								
								
								
							|  | @ -184,16 +184,36 @@ 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 | local keymap = vim.keymap | ||||||
| vim.api.nvim_set_keymap('n', '<leader>ta', ':$tabnew<CR>', { noremap = true }) | local opts = { noremap = true, silent = true } | ||||||
| vim.api.nvim_set_keymap('n', '<leader>tc', ':tabclose<CR>', { noremap = true }) | -- New tab | ||||||
| vim.api.nvim_set_keymap('n', '<leader>to', ':tabonly<CR>', { noremap = true }) | -- Split window | ||||||
| vim.api.nvim_set_keymap('n', '<leader>tn', ':tabn<CR>', { noremap = true }) | keymap.set('n', 'ss', ':split<Return>', opts) | ||||||
| vim.api.nvim_set_keymap('n', '<leader>tp', ':tabp<CR>', { noremap = true }) | keymap.set('n', 'sv', ':vsplit<Return>', opts) | ||||||
| -- move current tab to previous position | -- Resize window | ||||||
| vim.api.nvim_set_keymap('n', '<leader>tmp', ':-tabmove<CR>', { noremap = true }) | keymap.set('n', '<C-w><left>', '<C-w><') | ||||||
| -- move current tab to next position | keymap.set('n', '<C-w><right>', '<C-w>>') | ||||||
| vim.api.nvim_set_keymap('n', '<leader>tmn', ':+tabmove<CR>', { noremap = true }) | keymap.set('n', '<C-w><up>', '<C-w>+') | ||||||
|  | keymap.set('n', '<C-w><down>', '<C-w>-') | ||||||
|  | 
 | ||||||
|  | -- NOTE: bufferline keymap | ||||||
|  | 
 | ||||||
|  | --NOTE: " the order of buffers :bnext and :bprevious will not respect the custom ordering | ||||||
|  | keymap.set('n', '<tab>', ':BufferLineCycleNext<CR>', opts) | ||||||
|  | keymap.set('n', '<s-tab>', ':BufferLineCyclePrev<CR>', opts) | ||||||
|  | -- " These commands will move the current buffer backwards or forwards in the bufferline | ||||||
|  | -- nnoremap <silent><mymap> :BufferLineMoveNext<CR> | ||||||
|  | -- nnoremap <silent><mymap> :BufferLineMovePrev<CR> | ||||||
|  | -- | ||||||
|  | -- " These commands will move the current buffer to the first or the last position in the bufferline | ||||||
|  | -- nnoremap <silent><mymap> :lua require'bufferline'.move_to(1)<CR> | ||||||
|  | -- nnoremap <silent><mymap> :lua require'bufferline'.move_to(-1)<CR> | ||||||
|  | -- | ||||||
|  | -- " These commands will sort buffers by directory, language, or a custom criteria | ||||||
|  | -- nnoremap <silent>be :BufferLineSortByExtension<CR> | ||||||
|  | -- nnoremap <silent>bd :BufferLineSortByDirectory<CR> | ||||||
|  | -- nnoremap <silent><mymap> :lua require'bufferline'.sort_by(function (buf_a, buf_b) return buf_a.id < buf_b.id end)<CR> | ||||||
|  | -- | ||||||
| 
 | 
 | ||||||
| -- 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 | ||||||
|  | @ -407,6 +427,8 @@ require('lazy').setup({ | ||||||
|       -- NOTE: Git Telescope Mappings |       -- NOTE: Git Telescope Mappings | ||||||
|       vim.keymap.set('n', '<leader>cm', '<cmd>Telescope git_commits<CR>', { desc = 'Telescope Git commits' }) |       vim.keymap.set('n', '<leader>cm', '<cmd>Telescope git_commits<CR>', { desc = 'Telescope Git commits' }) | ||||||
|       vim.keymap.set('n', '<leader>gt', '<cmd>Telescope git_status<CR>', { desc = 'Telescope Git status' }) |       vim.keymap.set('n', '<leader>gt', '<cmd>Telescope git_status<CR>', { desc = 'Telescope Git status' }) | ||||||
|  |       -- NOTE: TodoTelescope | ||||||
|  |       vim.keymap.set('n', '<leader>tt', '<cmd>TodoTelescope<CR>', { desc = 'TodoTelescope list' }) | ||||||
| 
 | 
 | ||||||
|       -- Slightly advanced example of overriding default behavior and theme |       -- Slightly advanced example of overriding default behavior and theme | ||||||
|       vim.keymap.set('n', '<leader>fz', function() |       vim.keymap.set('n', '<leader>fz', function() | ||||||
|  |  | ||||||
|  | @ -0,0 +1,34 @@ | ||||||
|  | local M = { | ||||||
|  |   'akinsho/bufferline.nvim', | ||||||
|  |   version = '*', | ||||||
|  |   dependencies = 'nvim-tree/nvim-web-devicons', | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function M.config() | ||||||
|  |   local bufferLine = require 'bufferline' | ||||||
|  |   bufferLine.setup { | ||||||
|  |     options = { | ||||||
|  |       mode = 'buffers', | ||||||
|  |       style_preset = bufferLine.style_preset.default, | ||||||
|  |       themable = true, | ||||||
|  |       numbers = 'ordinal', | ||||||
|  |       close_command = 'bdelete! %d', -- can be a string | function, | false see "Mouse actions" | ||||||
|  |       right_mouse_command = 'bdelete! %d', -- can be a string | function | false, see "Mouse actions" | ||||||
|  |       left_mouse_command = 'buffer %d', -- can be a string | function, | false see "Mouse actions" | ||||||
|  |       middle_mouse_command = nil, -- can be a string | function, | false see "Mouse actions" | ||||||
|  |       indicator = { | ||||||
|  |         icon = '▎', -- this should be omitted if indicator style is not 'icon' | ||||||
|  |         style = 'icon', | ||||||
|  |       }, | ||||||
|  |       buffer_close_icon = '', | ||||||
|  |       modified_icon = '●', | ||||||
|  |       close_icon = '', | ||||||
|  |       left_trunc_marker = '', | ||||||
|  |       right_trunc_marker = '', | ||||||
|  |       show_close_icon = true, | ||||||
|  |       show_tab_indicators = true, | ||||||
|  |     }, | ||||||
|  |   } | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | return M | ||||||
|  | @ -1,115 +0,0 @@ | ||||||
| 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, |  | ||||||
| } |  | ||||||
		Loading…
	
		Reference in New Issue