From 3aca6d02ad90423a4f78035a060291fea549a16a Mon Sep 17 00:00:00 2001 From: long Date: Mon, 5 Dec 2022 05:15:24 -0600 Subject: [PATCH] dynamic tab, tabline changes --- lua/base.lua | 33 +++++++++++++------ lua/dynamic_tab.lua | 24 ++++++++++++++ lua/fzf_funcs.lua | 8 +++++ lua/plugins/config.lua | 72 ++++++++++++++++++++++------------------- lua/plugins/startup.lua | 2 +- 5 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 lua/dynamic_tab.lua create mode 100644 lua/fzf_funcs.lua diff --git a/lua/base.lua b/lua/base.lua index 70997c0..b972b62 100644 --- a/lua/base.lua +++ b/lua/base.lua @@ -7,14 +7,19 @@ local g = vim.g g.mapleader = "," -map("v", "", '"+y') -map("n", "", ":bnext") -map("n", "", ":bprevious") -map("n", "", ":noh", { 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", "", '"+y') +silent_map("n", "", ":noh") --After searching, pressing escape stops the highlight +--silent_map("n", "", ":bnext") +--silent_map("n", "", ":bprevious") map("n", "w", [[:%s/\s\+$//e]]) map("n", "x", ":bp|bd #") -map("n", "t", ":tabnew") +map("n", "t", ":tabnew:bp|bd #") -- Move split map("n", "", "") @@ -52,11 +57,7 @@ map("t", "", [[]]) map("n", [[\]], ":" .. term_command .. "") map("n", [[|]], ":v" .. term_command .. "") --- 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", "", "gk") silent_map("n", "", "gj") silent_map("n", "", "g") @@ -72,6 +73,18 @@ silent_map("i", "", "gj") silent_map("i", "", "g") silent_map("i", "", "g") +-- half page movement +silent_map("n", "", "zz") +silent_map("n", "", "zz") +silent_map("v", "", "zz") +silent_map("v", "", "zz") +silent_map("i", "", "zz") +silent_map("i", "", "zz") + +-- dynamic tab +silent_map("n", "", ":lua require('dynamic_tab').tab()") +silent_map("n", "", ":lua require('dynamic_tab').shift_tab()") + opt.autoindent = true opt.autoread = true opt.cursorcolumn = true diff --git a/lua/dynamic_tab.lua b/lua/dynamic_tab.lua new file mode 100644 index 0000000..ed6fd97 --- /dev/null +++ b/lua/dynamic_tab.lua @@ -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 diff --git a/lua/fzf_funcs.lua b/lua/fzf_funcs.lua new file mode 100644 index 0000000..337b817 --- /dev/null +++ b/lua/fzf_funcs.lua @@ -0,0 +1,8 @@ +local M = {} + +function M.cwd() + local path = vim.fn.expand("%:p:h") + vim.cmd("Files " .. path) +end + +return M diff --git a/lua/plugins/config.lua b/lua/plugins/config.lua index 9b46e06..ab5d76c 100644 --- a/lua/plugins/config.lua +++ b/lua/plugins/config.lua @@ -34,15 +34,15 @@ function M.fzf() map("n", "O", ":Files ~/") map("n", "p", ":Buffers") map("n", "h", ":Helptags") - map("n", "H", ":Helptags ") map("n", ";", ":History:") map("n", "c", ":Commands") map("n", "r", ":Rg ") map("n", "R", ":Rg") - map("n", "s", ":Lines") + map("n", "s", ":BLines") map("n", "gl", ":GFiles") map("n", "gs", ":GFiles?") map("n", "gc", ":Commits") + map("n", "l", ":lua require('fzf_funcs').cwd()") 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 = {}, diff --git a/lua/plugins/startup.lua b/lua/plugins/startup.lua index ff6818e..6f1fbea 100644 --- a/lua/plugins/startup.lua +++ b/lua/plugins/startup.lua @@ -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")