lots of macbook vim stuff

This commit is contained in:
Iwaniuk Krzysztof 2024-06-07 03:14:27 +02:00
parent 5b483a9db7
commit feb59d91c5
20 changed files with 267 additions and 226 deletions

5
lua/autocommand.lua Normal file
View file

@ -0,0 +1,5 @@
vim.cmd [[:command! -nargs=1 I lua inspectFn(<f-args>)]]
function inspectFn(obj)
local cmd = string.format('lua print(vim.inspect(%s))', obj)
require('noice').redirect(cmd, { view = 'messages', filter = {} })
end

19
lua/fancyutil.lua Normal file
View file

@ -0,0 +1,19 @@
-- init module
local _M = {}
--- @param bufnr integer | nil
--- @return true | false | nil
function _M.get_oil_nnn(bufnr)
bufnr = bufnr or 0
local ok, value = pcall(vim.api.nvim_buf_get_var, bufnr, 'nnn')
if not ok then
return nil
end
if value then
return true
end
return false
end
vim.fn.get_oil_nnn = _M.get_oil_nnn
return _M

View file

@ -1,7 +1,7 @@
return {
{
'tzachar/highlight-undo.nvim',
config = function(opts)
config = function()
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }),

View file

@ -6,7 +6,6 @@ return {
priority = 1000,
init = function()
vim.cmd.colorscheme 'catppuccin-mocha'
-- You can configure highlights by doing something like:
vim.cmd.hi 'Comment gui=none'
end,
opts = {

25
lua/plugins/lazydev.lua Normal file
View file

@ -0,0 +1,25 @@
return {
{
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
vim.env.HOME .. '.local/share/nvim/lazy/luvit-meta/library/',
-- You can also add plugins you always want to have loaded.
-- Useful if the plugin has globals or types you want to use
-- vim.env.LAZY .. "/LazyVim", -- see below
},
},
},
{ 'Bilal2453/luvit-meta', lazy = true },
{
'hrsh7th/nvim-cmp',
opts = function(_, opts)
opts.sources = opts.sources or {}
table.insert(opts.sources, {
name = 'lazydev',
group_index = 0, -- set group index to 0 to skip loading LuaLS completions
})
end,
},
}

View file

@ -15,6 +15,7 @@ return {
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
group = lint_augroup,
callback = function()
require('lint').try_lint 'codespell'
require('lint').try_lint()
end,
})

View file

@ -5,12 +5,21 @@ return {
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim',
'folke/neodev.nvim',
'folke/lazydev.nvim',
{ 'j-hui/fidget.nvim' },
},
config = function()
require 'plugins.neodev'
require('lazydev').setup {}
require('neoconf').setup {}
vim.diagnostic.config {
update_in_insert = true,
float = {
focusable = false,
},
signs = true,
underline = true,
virtual_text = false,
}
-- function will be executed to configure the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
@ -46,22 +55,13 @@ return {
tsserver = {},
lua_ls = {
settings = {
lua = {
Lua = {
runtime = {
version = 'LuaJIT',
},
workspace = {
checkthirdparty = { lazyPlugins },
library = {
vim.env.VIMRUNTIME,
-- -- depending on the usage, you might want to add additional paths here.
-- -- "${3rd}/luv/library"
-- -- "${3rd}/busted/library",
-- },
-- or pull in all of 'runtimepath'. note: this is a lot slower
},
-- library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), { vim.env.VIMRUNTIME }),
library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), { vim.env.VIMRUNTIME }),
},
completion = {
callSnippet = 'Replace',
@ -76,6 +76,7 @@ return {
},
jsonls = {},
yamlls = {},
eslint_d = {},
}
-- You can press `g?` for help in this menu.
@ -89,17 +90,11 @@ return {
handlers = {
function(server_name)
local server = servers[server_name] or {}
-- This handles overriding only values explicitly passed
-- by the server configuration above. Useful when disabling
-- certain features of an LSP (for example, turning off formatting for tsserver)
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup(server)
end,
},
}
end,
settings = {
Lua = {},
},
},
}

View file

@ -4,9 +4,13 @@ return {
dependencies = {
{ 'nvim-tree/nvim-web-devicons' },
{ 'folke/noice.nvim' },
{ 'arkav/lualine-lsp-progress' },
},
config = function()
local noice = require 'noice'
local colors = {
gray = '#6c7086',
purple = '#cba6f7',
}
require('lualine').setup {
options = {
@ -19,17 +23,17 @@ return {
{
'mode',
separator = { left = '' },
fmt = function(_, context)
local winnr = vim.fn.tabpagewinnr(context.tabnr)
local ok, val = pcall(vim.api.nvim_win_get_var, winnr, 'nnn')
if ok and val then
fmt = function(_, _)
-- local winnr = vim.fn.tab (context.tabnr)
-- vim.fn.winbufnr(winnr)
local val = require('fancyutil').get_oil_nnn()
if val then
return 'nnn'
end
end,
color = function(section)
local winnr = vim.api.nvim_get_current_win()
local ok, val = pcall(vim.api.nvim_win_get_var, winnr, 'nnn')
if ok and val then
color = function(_)
local val = require('fancyutil').get_oil_nnn()
if val == true then
return { fg = '#054fca' }
end
return {}
@ -38,18 +42,16 @@ return {
},
lualine_x = {
{
noice.api.status.message.get_hl,
cond = noice.api.status.message.has,
},
{
noice.api.status.command.get_hl,
cond = noice.api.status.command.has,
color = { fg = '#ff0000' },
},
{
noice.api.status.mode.get,
cond = noice.api.status.mode.has,
color = { fg = '#00ff00' },
'lsp_progress',
display_components = { 'lsp_client_name', { 'title', 'percentage', 'message' } },
colors = {
percentage = colors.gray,
title = colors.gray,
message = colors.gray,
spinner = colors.gray,
lsp_client_name = colors.purple,
use = true,
},
},
},
lualine_z = {

View file

@ -1,17 +0,0 @@
return {
{
'folke/neodev.nvim',
opts = {
library = {
enabled = true,
runtime = true,
types = true,
plugins = true,
-- plugins = { "nvim-treesitter", "plenary.nvim", "telescope.nvim" },
},
setup_jsonls = true,
lspconfig = true,
pathStrict = true,
},
},
}

View file

@ -24,6 +24,7 @@ return {
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
'hrsh7th/cmp-nvim-lsp-signature-help',
},
config = function()
-- See `:help cmp`
@ -88,6 +89,7 @@ return {
sources = cmp.config.sources({
{ name = 'nvim_lsp_signature_help' },
{ name = 'nvim_lsp' },
{ name = 'lazydev' },
{ name = 'luasnip' },
{ name = 'path' },
{ name = 'nvim_lua' },

View file

@ -1,85 +1,118 @@
return {
{
'stevearc/oil.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
event = 'VimEnter',
keys = {
{
'qq',
function()
require('oil').close()
end,
mode = '',
desc = 'Close current window',
},
{
'~',
'<CMD>Oil<CR>',
mode = '',
desc = 'Open parent directory',
},
{
'<Left>',
function()
if require('oil.util').is_oil_bufnr(0) then
local oil = require 'oil'
local bufname = vim.api.nvim_buf_get_name(0)
local parent = oil.get_buffer_parent_url(bufname, true)
return oil.open(parent)
end
-- fallback to sending page up key
local keys = vim.api.nvim_replace_termcodes('<Left>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = 'i',
desc = 'Move up the file tree',
},
{
'<Right>',
function()
local oil = require 'oil'
local entry = oil.get_cursor_entry()
local dir = oil.get_current_dir()
if entry and dir then
local path = dir .. entry.name
local stat = vim.loop.fs_stat(path)
if stat and stat.type == 'directory' then
return oil.open(path)
end
end
-- fallback to sending arrow key
local keys = vim.api.nvim_replace_termcodes('<Right>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = 'i',
desc = 'Move down the file tree',
},
'stevearc/oil.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
event = 'VimEnter',
keys = {
{
'qq',
function()
require('oil').close()
end,
mode = '',
desc = 'Close current window',
},
opts = {
default_file_explorer = true,
win_options = {
wrap = true,
signcolumn = 'no',
cursorcolumn = false,
foldcolumn = '0',
spell = false,
list = false,
conceallevel = 3,
concealcursor = 'nivc',
},
restore_window_options = true,
view_options = {
show_hidden = true,
is_always_hidden = function(name, _)
return name:match '.git'
end,
},
extensions = {
'oil',
},
{
'<leader>tn',
function()
local val = require('fancyutil').get_oil_nnn()
if val == true then
vim.api.nvim_buf_set_var(bufnr, 'nnn', false)
elseif val == false then
vim.api.nvim_buf_set_var(bufnr, 'nnn', true)
end
end,
mode = '',
desc = '[T]oggle [n]nn Mode',
},
{
'~',
'<CMD>Oil<CR>',
mode = '',
desc = 'Open parent directory',
},
{
'<Left>',
function()
if require('oil.util').is_oil_bufnr(0) and require('fancyutil').get_oil_nnn() then
local oil = require 'oil'
local bufname = vim.api.nvim_buf_get_name(0)
local parent = oil.get_buffer_parent_url(bufname, true)
return oil.open(parent)
end
-- fallback to sending page up key
local keys = vim.api.nvim_replace_termcodes('<Left>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = '',
desc = 'Move up the file tree',
},
{
'<Right>',
function()
local oil = require 'oil'
local entry = oil.get_cursor_entry()
local dir = oil.get_current_dir()
if entry and dir and require('fancyutil').get_oil_nnn() then
local path = dir .. entry.name
local stat = vim.loop.fs_stat(path)
if stat and stat.type == 'directory' then
return oil.open(path)
end
end
-- fallback to sending arrow key
local keys = vim.api.nvim_replace_termcodes('<Right>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = '',
desc = 'Move down the file tree',
},
},
opts = {
default_file_explorer = true,
restore_window_options = true,
win_options = {
wrap = true,
signcolumn = 'yes',
cursorcolumn = false,
foldcolumn = '0',
spell = false,
list = false,
conceallevel = 3,
concealcursor = 'nivc',
},
view_options = {
show_hidden = true,
is_always_hidden = function(name, _)
return name:match '.git'
end,
},
-- group = aug,
extensions = {
'oil',
},
},
config = function(_, opts)
local oil = require 'oil'
oil.setup(opts)
end,
init = function()
vim.api.nvim_create_autocmd('BufEnter', {
desc = 'Detect buffer and setup oil nnn flag',
-- group = aug,
pattern = '*',
nested = true,
callback = function(params)
local bufnr = params.buf
local _, filetype = pcall(vim.api.nvim_get_option_value, 'filetype', { buf = bufnr })
if filetype == 'oil' then
local val = require('fancyutil').get_oil_nnn(bufnr)
if val == nil then
vim.api.nvim_buf_set_var(bufnr, 'nnn', true)
end
end
end,
})
end,
}

View file

@ -8,7 +8,7 @@ return {
local schemastore = require 'schemastore'
local lspconfig = require 'lspconfig'
lspconfig.jsonls.setup {
settigns = {
settings = {
json = {
schemas = schemastore.json.schemas(),
validate = {
@ -18,7 +18,7 @@ return {
},
}
lspconfig.yamlls.setup {
settigns = {
settings = {
yaml = {
schemas = schemastore.yaml.schemas(),
},

View file

@ -16,10 +16,10 @@ return {
show_tabs_always = true, -- this shows tabs only when there are more than one tab or if the first tab is named
show_devicons = true, -- this shows devicons in buffer section
colored = true,
show_bufnr = false, -- this appends [bufnr] to buffer section,
show_bufnr = true, -- this appends [bufnr] to buffer section,
tabline_show_last_separator = true,
show_filename_only = true, -- shows base filename only instead of relative path in filename
modified_icon = '+ ', -- change the default modified icon
modified_icon = 'single', -- change the default modified icon
modified_italic = true, -- set to true by default; this determines whether the filename turns italic if modified
show_tabs_only = false, -- this shows only tabs instead of tabs + buffers
},

23
lua/plugins/trouble.lua Normal file
View file

@ -0,0 +1,23 @@
return {
{
'folke/trouble.nvim',
opts = {
modes = {
preview_float = {
mode = 'diagnostics',
preview = {
type = 'float',
relative = 'editor',
border = 'rounded',
title = 'Preview',
title_pos = 'center',
position = { 0, -2 },
size = { width = 0.3, height = 0.3 },
zindex = 200,
},
},
},
},
cmd = 'Trouble',
},
}

View file

@ -20,7 +20,7 @@ return {
end, { desc = '[T]oggle [N]umbers' })
vim.keymap.set('n', '<leader>tw', function()
vim.opt.warp = not vim.opt.warp._value
vim.opt.wrap = not vim.opt.wrap._value
end, { desc = '[T]oggle [W]rap Lines' })
end,
},

16
lua/plugins/yanky.lua Normal file
View file

@ -0,0 +1,16 @@
return {
{
'gbprod/yanky.nvim',
opts = {
ystem_clipboard = {
sync_with_ring = true,
clipboard_register = nil,
},
highlight = {
on_put = true,
on_yank = true,
timer = 500,
},
},
},
}