dynamic tab, tabline changes

This commit is contained in:
2022-12-05 05:15:24 -06:00
parent 2358ac3d71
commit 3aca6d02ad
5 changed files with 95 additions and 44 deletions
+23 -10
View File
@@ -7,14 +7,19 @@ local g = vim.g
g.mapleader = ","
map("v", "<C-C>", '"+y')
map("n", "<Tab>", ":bnext<CR>")
map("n", "<S-Tab>", ":bprevious<CR>")
map("n", "<Esc>", ":noh<CR><Esc>", { silent = true }) --After searching, pressing escape stops the highlight
-- Move cursor relative to visual line breaks
local function silent_map(mode, lhs, rhs)
map(mode, lhs, rhs, { silent = true })
end
silent_map("v", "<C-C>", '"+y')
silent_map("n", "<Esc>", ":noh<CR><Esc>") --After searching, pressing escape stops the highlight
--silent_map("n", "<Tab>", ":bnext<CR>")
--silent_map("n", "<S-Tab>", ":bprevious<CR>")
map("n", "<Leader>w", [[:%s/\s\+$//e<CR>]])
map("n", "<Leader>x", ":bp|bd #<CR>")
map("n", "<Leader>t", ":tabnew<CR>")
map("n", "<Leader>t", ":tabnew<CR>:bp|bd #<CR>")
-- Move split
map("n", "<A-Right>", "<C-W><S-L>")
@@ -52,11 +57,7 @@ map("t", "<C-Space>", [[<C-\><C-n>]])
map("n", [[<Leader>\]], ":" .. term_command .. "<CR>")
map("n", [[<Leader>|]], ":v" .. term_command .. "<CR>")
-- Move cursor relative to visual line breaks
local function silent_map(mode, lhs, rhs)
map(mode, lhs, rhs, { silent = true })
end
-- line-break movement
silent_map("n", "<Up>", "gk")
silent_map("n", "<Down>", "gj")
silent_map("n", "<Home>", "g<Home>")
@@ -72,6 +73,18 @@ silent_map("i", "<Down>", "<C-o>gj")
silent_map("i", "<Home>", "<C-o>g<Home>")
silent_map("i", "<End>", "<C-o>g<End>")
-- half page movement
silent_map("n", "<PageDown>", "<C-d>zz")
silent_map("n", "<PageUp>", "<C-u>zz")
silent_map("v", "<PageDown>", "<C-d>zz")
silent_map("v", "<PageUp>", "<C-u>zz")
silent_map("i", "<PageDown>", "<C-o><C-d><C-o>zz")
silent_map("i", "<PageUp>", "<C-o><C-u><C-o>zz")
-- dynamic tab
silent_map("n", "<Tab>", ":lua require('dynamic_tab').tab()<CR>")
silent_map("n", "<S-Tab>", ":lua require('dynamic_tab').shift_tab()<CR>")
opt.autoindent = true
opt.autoread = true
opt.cursorcolumn = true
+24
View File
@@ -0,0 +1,24 @@
local M = {}
-- Whether to switch between buffers or tabs
local function tab_mode()
return vim.fn.tabpagenr("$") > 1
end
-- Whether to show windows or buffers in lualine
local function window_mode()
return vim.fn.winnr("$") > 1 or tab_mode()
end
M.tab_mode = tab_mode
M.window_mode = window_mode
function M.tab()
vim.cmd(tab_mode() and "tabn" or "bnext")
end
function M.shift_tab()
vim.cmd(tab_mode() and "tabp" or "bprevious")
end
return M
+8
View File
@@ -0,0 +1,8 @@
local M = {}
function M.cwd()
local path = vim.fn.expand("%:p:h")
vim.cmd("Files " .. path)
end
return M
+39 -33
View File
@@ -34,15 +34,15 @@ function M.fzf()
map("n", "<Leader>O", ":Files ~/<CR>")
map("n", "<Leader>p", ":Buffers<CR>")
map("n", "<Leader>h", ":Helptags<CR>")
map("n", "<Leader>H", ":Helptags <C-R><C-W><CR>")
map("n", "<Leader>;", ":History:<CR>")
map("n", "<Leader>c", ":Commands<CR>")
map("n", "<Leader>r", ":Rg <C-R><C-W><CR>")
map("n", "<Leader>R", ":Rg<CR>")
map("n", "<Leader>s", ":Lines<CR>")
map("n", "<Leader>s", ":BLines<CR>")
map("n", "<Leader>gl", ":GFiles<CR>")
map("n", "<Leader>gs", ":GFiles?<CR>")
map("n", "<Leader>gc", ":Commits<CR>")
map("n", "<Leader>l", ":lua require('fzf_funcs').cwd()<CR>")
end
function M.fzf_checkout()
@@ -55,7 +55,6 @@ end
function M.nvim_fzf()
require("fzf").default_options = {
--fzf_cli_args = " --height 100% --preview='bat --color=always --style=header,grid --line-range :300 {}' ",
fzf_cli_args = " --height 100% --preview='[[ -n \"$(command -v bat)\" ]] && bat --color=always --style=header,grid --line-range :300 {} || strings {+}' ",
}
end
@@ -93,6 +92,32 @@ function M.indent_blankline()
end
function M.lualine()
-- Out of 6 total columns
local function columns(num)
return vim.o.columns * num / 6
end
-- config options
local function buffer_window(type, cond)
return {
type,
cond = cond,
show_filename_only = true,
show_modified_status = true,
max_length = function()
return columns(5)
end,
filetype_names = {
TelescopePrompt = "Telescope",
dashboard = "Dashboard",
packer = "Packer",
fzf = "FZF",
alpha = "Alpha",
["lsp-installer"] = "LSP Installer",
},
}
end
require("lualine").setup({
options = { theme = "onedark", icons_enabled = true },
sections = {
@@ -127,43 +152,24 @@ function M.lualine()
tabline = {
lualine_a = {
{
"buffers",
show_filename_only = false, -- shows shortened relative path when false
show_modified_status = true, -- shows indicator then bufder is modified
"tabs",
max_length = function()
return vim.o.columns * 5 / 6
end, -- maximum width of buffers component
filetype_names = {
TelescopePrompt = "Telescope",
dashboard = "Dashboard",
packer = "Packer",
fzf = "FZF",
alpha = "Alpha",
["lsp-installer"] = "LSP Installer",
}, -- shows specific buffer name for that filetype ( { `filetype` = `buffer_name`, ... } )
buffers_color = {
active = nil, -- color for active buffer
inactive = nil, -- color for inactive buffer
},
return columns(1)
end,
},
},
lualine_b = {},
lualine_b = {
buffer_window("windows", function()
return require("dynamic_tab").window_mode()
end),
buffer_window("buffers", function()
return not require("dynamic_tab").window_mode()
end),
},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {
{
[[string.format("Tab %d/%d", vim.fn.tabpagenr(), vim.fn.tabpagenr('$'))]],
cond = function()
return vim.fn.tabpagenr("$") > 1
end,
},
{
[[harpoon_status()]],
cond = function()
return require("harpoon.mark").get_length() > 0
end,
},
},
},
extensions = {},
+1 -1
View File
@@ -32,7 +32,7 @@ require("packer").startup(function(use)
-- SNIPPETS
use("SirVer/ultisnips")
use("honza/vim-snippets")
use("L3MON4D3/LuaSnip") -- Snippets plugin
--use("L3MON4D3/LuaSnip") -- Snippets plugin
-- LSP
use("p00f/nvim-ts-rainbow")