add simple statusline
This commit is contained in:
parent
d33355ed44
commit
c8a9a4c10b
6 changed files with 175 additions and 72 deletions
|
|
@ -1,9 +1,7 @@
|
|||
-- Taken from
|
||||
-- https://github.com/LazyVim/LazyVim/blob/566049aa4a26a86219dd1ad1624f9a1bf18831b6/lua/lazyvim/config/autocmds.lua
|
||||
|
||||
local function augroup(name)
|
||||
return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true })
|
||||
end
|
||||
local augroup = require("rayandrew.util").augroup
|
||||
|
||||
local autocmd = vim.api.nvim_create_autocmd
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ function M.setup()
|
|||
require("rayandrew.autocmds")
|
||||
require("rayandrew.remap")
|
||||
require("rayandrew.theme").setup()
|
||||
require("rayandrew.statusline").setup()
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -295,75 +295,75 @@ return {
|
|||
------------------------------
|
||||
-- User Interface
|
||||
------------------------------
|
||||
{
|
||||
"folke/noice.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = {
|
||||
lsp = {
|
||||
override = {
|
||||
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
||||
["vim.lsp.util.stylize_markdown"] = true,
|
||||
["cmp.entry.get_documentation"] = true,
|
||||
},
|
||||
hover = {
|
||||
enabled = false,
|
||||
},
|
||||
signature = {
|
||||
enabled = false,
|
||||
},
|
||||
},
|
||||
cmdline = {
|
||||
enabled = true,
|
||||
view = "cmdline",
|
||||
},
|
||||
routes = {
|
||||
{
|
||||
filter = {
|
||||
event = "msg_show",
|
||||
any = {
|
||||
{ find = "%d+L, %d+B" },
|
||||
{ find = "; after #%d+" },
|
||||
{ find = "; before #%d+" },
|
||||
},
|
||||
},
|
||||
view = "mini",
|
||||
},
|
||||
},
|
||||
presets = {
|
||||
bottom_search = true,
|
||||
command_palette = true,
|
||||
long_message_to_split = true,
|
||||
inc_rename = true,
|
||||
},
|
||||
},
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{ "<S-Enter>", function() require("noice").redirect(vim.fn.getcmdline()) end, mode = "c", desc = "Redirect Cmdline" },
|
||||
{ "<leader>snl", function() require("noice").cmd("last") end, desc = "Noice Last Message" },
|
||||
{ "<leader>snh", function() require("noice").cmd("history") end, desc = "Noice History" },
|
||||
{ "<leader>sna", function() require("noice").cmd("all") end, desc = "Noice All" },
|
||||
{ "<leader>snd", function() require("noice").cmd("dismiss") end, desc = "Dismiss All" },
|
||||
{ "<c-f>", function() if not require("noice.lsp").scroll(4) then return "<c-f>" end end, silent = true, expr = true, desc = "Scroll forward", mode = {"i", "n", "s"} },
|
||||
{ "<c-b>", function() if not require("noice.lsp").scroll(-4) then return "<c-b>" end end, silent = true, expr = true, desc = "Scroll backward", mode = {"i", "n", "s"}},
|
||||
},
|
||||
},
|
||||
-- {
|
||||
-- "folke/noice.nvim",
|
||||
-- event = "VeryLazy",
|
||||
-- opts = {
|
||||
-- lsp = {
|
||||
-- override = {
|
||||
-- ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
||||
-- ["vim.lsp.util.stylize_markdown"] = true,
|
||||
-- ["cmp.entry.get_documentation"] = true,
|
||||
-- },
|
||||
-- hover = {
|
||||
-- enabled = false,
|
||||
-- },
|
||||
-- signature = {
|
||||
-- enabled = false,
|
||||
-- },
|
||||
-- },
|
||||
-- cmdline = {
|
||||
-- enabled = true,
|
||||
-- view = "cmdline",
|
||||
-- },
|
||||
-- routes = {
|
||||
-- {
|
||||
-- filter = {
|
||||
-- event = "msg_show",
|
||||
-- any = {
|
||||
-- { find = "%d+L, %d+B" },
|
||||
-- { find = "; after #%d+" },
|
||||
-- { find = "; before #%d+" },
|
||||
-- },
|
||||
-- },
|
||||
-- view = "mini",
|
||||
-- },
|
||||
-- },
|
||||
-- presets = {
|
||||
-- bottom_search = true,
|
||||
-- command_palette = true,
|
||||
-- long_message_to_split = true,
|
||||
-- inc_rename = true,
|
||||
-- },
|
||||
-- },
|
||||
-- -- stylua: ignore
|
||||
-- keys = {
|
||||
-- { "<S-Enter>", function() require("noice").redirect(vim.fn.getcmdline()) end, mode = "c", desc = "Redirect Cmdline" },
|
||||
-- { "<leader>snl", function() require("noice").cmd("last") end, desc = "Noice Last Message" },
|
||||
-- { "<leader>snh", function() require("noice").cmd("history") end, desc = "Noice History" },
|
||||
-- { "<leader>sna", function() require("noice").cmd("all") end, desc = "Noice All" },
|
||||
-- { "<leader>snd", function() require("noice").cmd("dismiss") end, desc = "Dismiss All" },
|
||||
-- { "<c-f>", function() if not require("noice.lsp").scroll(4) then return "<c-f>" end end, silent = true, expr = true, desc = "Scroll forward", mode = {"i", "n", "s"} },
|
||||
-- { "<c-b>", function() if not require("noice.lsp").scroll(-4) then return "<c-b>" end end, silent = true, expr = true, desc = "Scroll backward", mode = {"i", "n", "s"}},
|
||||
-- },
|
||||
-- },
|
||||
|
||||
{
|
||||
"stevearc/dressing.nvim",
|
||||
lazy = true,
|
||||
init = function()
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
vim.ui.select = function(...)
|
||||
require("lazy").load({ plugins = { "dressing.nvim" } })
|
||||
return vim.ui.select(...)
|
||||
end
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
vim.ui.input = function(...)
|
||||
require("lazy").load({ plugins = { "dressing.nvim" } })
|
||||
return vim.ui.input(...)
|
||||
end
|
||||
end,
|
||||
},
|
||||
-- {
|
||||
-- "stevearc/dressing.nvim",
|
||||
-- lazy = true,
|
||||
-- init = function()
|
||||
-- ---@diagnostic disable-next-line: duplicate-set-field
|
||||
-- vim.ui.select = function(...)
|
||||
-- require("lazy").load({ plugins = { "dressing.nvim" } })
|
||||
-- return vim.ui.select(...)
|
||||
-- end
|
||||
-- ---@diagnostic disable-next-line: duplicate-set-field
|
||||
-- vim.ui.input = function(...)
|
||||
-- require("lazy").load({ plugins = { "dressing.nvim" } })
|
||||
-- return vim.ui.input(...)
|
||||
-- end
|
||||
-- end,
|
||||
-- },
|
||||
|
||||
{
|
||||
"lukas-reineke/indent-blankline.nvim",
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ opt.hlsearch = false
|
|||
opt.ignorecase = true -- Ignore case
|
||||
opt.incsearch = true
|
||||
opt.inccommand = "nosplit" -- preview incremental substitute
|
||||
opt.laststatus = 0
|
||||
opt.laststatus = 2
|
||||
opt.list = true -- Show some invisible characters (tabs...
|
||||
opt.mouse = "a" -- Enable mouse mode
|
||||
opt.nu = true
|
||||
|
|
@ -32,6 +32,7 @@ opt.number = true -- Print line number
|
|||
opt.pumblend = 10 -- Popup blend
|
||||
opt.pumheight = 10 -- Maximum number of entries in a popup
|
||||
opt.relativenumber = true -- Relative line numbers
|
||||
opt.ruler = false -- Disable ruler
|
||||
opt.scrolloff = 4 -- Lines of context
|
||||
opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" }
|
||||
opt.shiftround = true -- Round indent
|
||||
|
|
|
|||
99
lua/rayandrew/statusline.lua
Normal file
99
lua/rayandrew/statusline.lua
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
local M = {}
|
||||
|
||||
local modes = {
|
||||
["n"] = "NORMAL",
|
||||
["no"] = "NORMAL",
|
||||
["v"] = "VISUAL",
|
||||
["V"] = "VISUAL LINE",
|
||||
[""] = "VISUAL BLOCK",
|
||||
["s"] = "SELECT",
|
||||
["S"] = "SELECT LINE",
|
||||
[""] = "SELECT BLOCK",
|
||||
["i"] = "INSERT",
|
||||
["ic"] = "INSERT",
|
||||
["R"] = "REPLACE",
|
||||
["Rv"] = "VISUAL REPLACE",
|
||||
["c"] = "COMMAND",
|
||||
["cv"] = "VIM EX",
|
||||
["ce"] = "EX",
|
||||
["r"] = "PROMPT",
|
||||
["rm"] = "MOAR",
|
||||
["r?"] = "CONFIRM",
|
||||
["!"] = "SHELL",
|
||||
["t"] = "TERMINAL",
|
||||
}
|
||||
|
||||
local function mode()
|
||||
local current_mode = vim.api.nvim_get_mode().mode
|
||||
return string.format(" %s ", modes[current_mode]):upper()
|
||||
end
|
||||
|
||||
local function filepath()
|
||||
local fpath = vim.fn.fnamemodify(vim.fn.expand("%"), ":~:.:h")
|
||||
if fpath == "" or fpath == "." then
|
||||
return " "
|
||||
end
|
||||
|
||||
return string.format(" %%<%s/", fpath)
|
||||
end
|
||||
|
||||
local function update_mode_colors()
|
||||
local current_mode = vim.api.nvim_get_mode().mode
|
||||
local mode_color = "%#StatusLineAccent#"
|
||||
if current_mode == "n" then
|
||||
mode_color = "%#StatuslineAccent#"
|
||||
elseif current_mode == "i" or current_mode == "ic" then
|
||||
mode_color = "%#StatuslineInsertAccent#"
|
||||
elseif current_mode == "v" or current_mode == "V" or current_mode == "" then
|
||||
mode_color = "%#StatuslineVisualAccent#"
|
||||
elseif current_mode == "R" then
|
||||
mode_color = "%#StatuslineReplaceAccent#"
|
||||
elseif current_mode == "c" then
|
||||
mode_color = "%#StatuslineCmdLineAccent#"
|
||||
elseif current_mode == "t" then
|
||||
mode_color = "%#StatuslineTerminalAccent#"
|
||||
end
|
||||
return mode_color
|
||||
end
|
||||
|
||||
local function filename()
|
||||
local fname = vim.fn.expand("%:t")
|
||||
if fname == "" then
|
||||
return ""
|
||||
end
|
||||
return fname .. " "
|
||||
end
|
||||
|
||||
function M.render()
|
||||
local parts = {
|
||||
"%#Statusline#",
|
||||
update_mode_colors(),
|
||||
mode(),
|
||||
"%#Normal# ",
|
||||
"%=%#StatusLineExtra#",
|
||||
filepath(),
|
||||
filename(),
|
||||
}
|
||||
|
||||
local statusline = table.concat(parts, "")
|
||||
|
||||
return statusline
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
local augroup = require("rayandrew.util").augroup
|
||||
local autocmd = vim.api.nvim_create_autocmd
|
||||
|
||||
-- Statusline
|
||||
autocmd({ "BufEnter", "BufWinEnter", "WinEnter" }, {
|
||||
group = augroup("statusline"),
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
-- vim.opt_local.statusline = "%!v:lua.require('rayandrew.util').statusline()"
|
||||
vim.opt_local.statusline = M.render()
|
||||
end,
|
||||
-- command = [[lua require("rayandrew.util").render()]],
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
local M = {}
|
||||
|
||||
function M.augroup(name)
|
||||
return vim.api.nvim_create_augroup("rayandrew_" .. name, { clear = true })
|
||||
end
|
||||
|
||||
---@param on_attach fun(client, buffer)
|
||||
function M.on_attach(on_attach)
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
|
|
|
|||
Loading…
Reference in a new issue