nvim: rewrite config some more

This commit is contained in:
tea 2024-08-19 11:59:14 +02:00
parent f5e0a650b6
commit ae6dca60d0
No known key found for this signature in database
5 changed files with 371 additions and 65 deletions

View File

@ -1,3 +1,98 @@
local M = {}
function M.has_api_level(desired)
return vim.version().api_level >= desired
end
function M.nerdfont_installed()
if vim.fn.executable('fc-list') == 1 and
os.execute([[fc-list -q 'Symbols Nerd Font']]) == 0 then
return true
end
return false
end
function M.map(mode, shortcut, command, description, buffer)
local opts = { noremap = true, silent = true }
opts.desc = description or nil
opts.buffer = buffer or nil
vim.keymap.set(mode, shortcut, command, opts)
end
-- Files that could indicate the project's root directory
M.project_root_markers = {
'.git', '.hg', '.svn', '.bzr', '_darcs',
'.projectile', '.luarc.json', '.editorconfig', 'Cargo.toml'
}
function M.get_project_root()
local lsp_root = vim.lsp.buf.list_workspace_folders()[1]
if lsp_root ~= nil then
return lsp_root
end
local path = vim.api.nvim_buf_get_name(0)
local sep = '/'
repeat
path = path:gsub(string.format('%s[^%s]*$', sep, sep), '')
for _, marker in ipairs(M.project_root_markers) do
if path ~= os.getenv('HOME') and io.open(path .. sep .. marker) then
return path
end
end
until path == ''
return nil
end
function M.not_firenvim()
return vim.g.started_by_firenvim == nil
end
function M.lsp_status()
local status = ''
for _, msg in ipairs(require('lsp-status/messaging').messages()) do
if msg.progress then
status = ''
elseif msg.status then
-- clangd parsing includes and whatnot
if msg.content ~= 'idle' then
status = ''
end
end
end
return status
end
function M.lsp_sig_status()
if not vim.lsp.buf.server_ready() then
return ""
end
local width = vim.o.columns / 3
if width < 40 then
return ""
end
if width > 50 then
width = width * 1.5
end
local label = require('lsp_signature').status_line().label
if label:len() > width then
label = label:sub(1, math.floor(width)) .. ''
end
return label
end
function M.current_function()
local curfun = vim.b.lsp_current_function
if curfun and curfun ~= '' then
return '(' .. curfun .. ')'
end
return ''
end
return M

View File

@ -0,0 +1,64 @@
local has_api_level = require('my.functions').has_api_level
return {
{ 'https://github.com/nvim-treesitter/nvim-treesitter',
version = '*',
build = [[:TSUpdateSync]],
opts = {
ensure_installed = 'all',
ignore_install = { 'comment', 'help' },
sync_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = { 'cpp' }
}
},
},
{ 'https://github.com/JoosepAlviste/nvim-ts-context-commentstring',
dependencies = 'nvim-treesitter',
enabled = has_api_level(11),
opts = {
enable = true,
enable_autocmd = false
},
init = function()
vim.g.skip_ts_context_commentstring_module = true
end,
},
{ 'https://github.com/folke/todo-comments.nvim',
version = '*',
dependencies = { 'plenary.nvim' },
enabled = has_api_level(11),
opts = {
signs = false,
highlight = {
keyword = 'bg',
after = ''
}
},
init = function()
vim.g.vimtex_compiler_latexmk_engines = { _ = '-xelatex' }
end,
},
{ 'https://github.com/powerman/vim-plugin-AnsiEsc' },
{ 'https://github.com/lervag/vimtex',
version = '*',
enabled = has_api_level(11) and vim.fn.executable('xelatex') == 1
},
{ 'https://github.com/NvChad/nvim-colorizer.lua',
opts = {
filetypes = { '*' },
user_default_options = {
mode = 'virtualtext',
rgb_fn = true,
hsl_fn = true,
RRGGBBAA = true,
}
},
},
{ 'https://github.com/gennaro-tedesco/nvim-jqx',
version = '*',
ft = { "json", "yaml" },
},
{ 'https://github.com/isobit/vim-caddyfile' },
}

View File

@ -0,0 +1,15 @@
-- TODO: configure
return {
{ 'https://github.com/neovim/nvim-lspconfig',
version = '*',
dependencies = 'cmp-nvim-lsp',
},
{ 'https://github.com/lukas-reineke/lsp-format.nvim',
version = '*',
},
{ 'https://github.com/ray-x/lsp_signature.nvim' },
{ 'https://github.com/p00f/clangd_extensions.nvim' },
{ 'https://github.com/simrat39/rust-tools.nvim',
dependencies = 'nvim-lspconfig',
}
}

View File

@ -1,12 +1,15 @@
local function has_api_level(desired)
return vim.version().api_level >= desired
end
local has_api_level = require('my.functions').has_api_level
-- NOTE: next line is a variable, not a function
local nerdfont_installed = require('my.functions').nerdfont_installed()
return {
-- common dependencies
{ 'https://github.com/nvim-lua/plenary.nvim',
lazy = true
},
{ 'https://github.com/kyazdani42/nvim-web-devicons',
enabled = nerdfont_installed
},
-- basics
{ 'https://github.com/owozsh/amora',
@ -34,66 +37,4 @@ return {
}
end,
},
-- filetypes
{ 'https://github.com/nvim-treesitter/nvim-treesitter',
version = '*',
build = [[:TSUpdateSync]],
opts = {
ensure_installed = 'all',
ignore_install = { 'comment', 'help' },
sync_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = { 'cpp' }
}
},
},
{ 'https://github.com/JoosepAlviste/nvim-ts-context-commentstring',
dependencies = 'nvim-treesitter',
enabled = has_api_level(11),
opts = {
enable = true,
enable_autocmd = false
},
init = function()
vim.g.skip_ts_context_commentstring_module = true
end,
},
{ 'https://github.com/folke/todo-comments.nvim',
version = '*',
dependencies = { 'plenary.nvim' },
enabled = has_api_level(11),
opts = {
signs = false,
highlight = {
keyword = 'bg',
after = ''
}
},
init = function()
vim.g.vimtex_compiler_latexmk_engines = { _ = '-xelatex' }
end,
},
{ 'https://github.com/powerman/vim-plugin-AnsiEsc' },
{ 'https://github.com/lervag/vimtex',
version = '*',
enabled = has_api_level(11) and vim.fn.executable('xelatex') == 1
},
{ 'https://github.com/NvChad/nvim-colorizer.lua',
opts = {
filetypes = { '*' },
user_default_options = {
mode = 'virtualtext',
rgb_fn = true,
hsl_fn = true,
RRGGBBAA = true,
}
},
},
{ 'https://github.com/gennaro-tedesco/nvim-jqx',
version = '*',
ft = { "json", "yaml" },
},
{ 'https://github.com/isobit/vim-caddyfile' },
}

View File

@ -0,0 +1,191 @@
local map = require('my.functions').map
local not_firenvim = require('my.functions').not_firenvim
-- TODO: enable projections and dap plugins
return {
{ 'https://github.com/folke/which-key.nvim',
version = '*',
},
{ 'https://github.com/nvim-telescope/telescope.nvim',
dependencies = {
'plenary.nvim',
'nvim-treesitter',
'nvim-web-devicons',
},
config = function()
local telescope = require('telescope')
local t_actions = require('telescope.actions')
-- telescope.load_extension('projections')
-- telescope.load_extension('dap')
telescope.load_extension('fzf')
telescope.setup({
mappings = {
i = {
["<C-_>"] = t_actions.which_key,
},
n = {
["?"] = t_actions.which_key,
}
},
defaults = {
file_ignore_patterns = { '^\\.git', '^fun' },
},
pickers = {
find_files = {
-- show hidden files by default
find_command = { "rg", "--files", "--hidden", "--glob", "!.git/*" }
}
}
})
local t_builtin = require('telescope.builtin')
local get_project_root = require('my.functions').get_project_root
require('which-key').add({{ '<Leader>t', group = 'telescope' }})
map('n', '<Leader>tb', t_builtin.buffers, 'buffers')
map('n', '<Leader>tf', function()
t_builtin.find_files({ cwd = get_project_root() })
end, 'files')
map('n', '<Leader>tF', t_builtin.find_files, 'files in cwd')
map('n', '<Leader>to', t_builtin.oldfiles, 'recently opened files')
map('n', '<Leader>tg', function()
t_builtin.live_grep({ cwd = get_project_root() })
end, 'Live-grep')
map('n', '<Leader>tm', t_builtin.man_pages, 'man pages')
map('n', '<Leader>tr', t_builtin.registers, 'registers')
map('n', '<Leader>gh', t_builtin.git_bcommits, 'history of this file')
map('n', '<F7>', t_builtin.diagnostics, 'show diagnostics')
-- map('n', '<Leader>tp', telescope.extensions.projections.projections, 'projects')
map('n', '<Leader>tt',
require("telescope._extensions.todo-comments").exports.todo,
'display TODO comments in project')
map('n', '<Leader>tn', telescope.extensions.notify.notify, 'notifications')
end,
},
{ 'https://github.com/nvim-telescope/telescope-fzf-native.nvim',
build = 'make',
},
{ 'https://github.com/kyazdani42/nvim-tree.lua',
version = '*',
dependencies = { 'nvim-web-devicons' },
config = function()
require("nvim-tree").setup({
filters = {
dotfiles = false,
custom = { '^\\.git' }
},
sync_root_with_cwd = true,
respect_buf_cwd = true,
update_focused_file = {
enable = true,
update_root = true
},
renderer = {
icons = {
show = {
file = nerdfont_installed,
folder = nerdfont_installed,
folder_arrow = nerdfont_installed,
git = nerdfont_installed
}
}
}
})
map('n', '<F9>', require("nvim-tree.api").tree.toggle, 'open nvim-tree')
map('i', '<F9>', require("nvim-tree.api").tree.toggle, 'open nvim-tree')
end,
},
{ 'https://github.com/nvim-lualine/lualine.nvim',
dependencies = {
'nvim-web-devicons',
'https://github.com/nvim-lua/lsp-status.nvim',
},
init = function()
vim.o.showmode = false
end,
opts = {
options = {
icons_enabled = nerdfont_installed,
component_separators = {},
section_separators = {},
extensions = {},
globalstatus = true
},
sections = {
lualine_a = { { 'mode' } },
lualine_b = {
{ 'branch', icons_enabled = true },
{ 'diff' },
{ require('my.functions').lsp_status, padding = 0 },
{ 'diagnostics' }
},
lualine_c = {
{
'filename',
path = 1,
newfile_status = true,
cond = not_firenvim
},
{
require('my.functions').current_function,
padding = 0,
color = 'StatusLineNC'
}
},
lualine_x = {
{
require('my.functions').lsp_sig_status,
color = 'StatusLineNC'
},
{ 'filetype' }
},
lualine_y = { { 'progress' } },
lualine_z = { { 'location' }, { '"🍄"', padding = 0 }},
},
inactive_winbar = {
lualine_c = { { 'filename', cond = not_firenvim } },
},
},
},
{ 'https://codeberg.org/tastytea/bug-reference.nvim',
keys = {
{ '<leader>B', '<cmd>BugReference<cr>',
desc = 'open bug under cursor' },
},
},
{ 'https://github.com/dhruvasagar/vim-table-mode',
version = '*',
init = function()
vim.g.table_mode_map_prefix = '<leader>T'
require('which-key').add({{ '<Leader>T', group = 'Table mode' }})
end,
},
{ 'https://github.com/stevearc/dressing.nvim',
opts = {
input = {
relative = 'win',
min_width = { 60, 0.4 },
},
},
},
{ 'https://github.com/rcarriga/nvim-notify',
version = '*',
opts = {
on_open = function(win)
vim.api.nvim_win_set_option(win, 'wrap', true) -- does not work
end,
stages = 'static',
},
init = function()
vim.notify = require('notify')
end,
},
{ 'https://github.com/gaoDean/autolist.nvim',
version = '*',
},
{ 'https://github.com/LittleMorph/copyright-updater.nvim',
event = 'BufModifiedSet',
},
}