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

15
.luacheckrc Normal file
View File

@ -0,0 +1,15 @@
globals = {
'vim',
'assert',
}
-- Don't report unused self arguments of methods.
self = false
-- Rerun tests only if their modification time changed.
cache = true
ignore = {
'631', -- max_line_length
'212/_.*', -- unused argument, for vars with "_" prefix
}

View File

@ -20,73 +20,8 @@
=====================================================================
=====================================================================
What is Kickstart?
-- ]]
Kickstart.nvim is *not* a distribution.
Kickstart.nvim is a starting point for your own configuration.
The goal is that you can read every line of code, top-to-bottom, understand
what your configuration is doing, and modify it to suit your needs.
Once you've done that, you can start exploring, configuring and tinkering to
make Neovim your own! That might mean leaving Kickstart just the way it is for a while
or immediately breaking it into modular pieces. It's up to you!
If you don't know anything about Lua, I recommend taking some time to read through
a guide. One possible example which will only take 10-15 minutes:
- https://learnxinyminutes.com/docs/lua/
After understanding a bit more about Lua, you can use `:help lua-guide` as a
reference for how Neovim integrates Lua.
- :help lua-guide
- (or HTML version): https://neovim.io/doc/user/lua-guide.html
Kickstart Guide:
TODO: The very first thing you should do is to run the command `:Tutor` in Neovim.
If you don't know what this means, type the following:
- <escape key>
- :
- Tutor
- <enter key>
(If you already know the Neovim basics, you can skip this step.)
Once you've completed that, you can continue working through **AND READING** the rest
of the kickstart init.lua.
Next, run AND READ `:help`.
This will open up a help window with some basic information
about reading, navigating and searching the builtin help documentation.
This should be the first place you go to look when you're stuck or confused
with something. It's one of my favorite Neovim features.
MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation,
which is very useful when you're not exactly sure of what you're looking for.
I have left several `:help X` comments throughout the init.lua
These are hints about where to find more information about the relevant settings,
plugins or Neovim features used in Kickstart.
NOTE: Look for lines like this
Throughout the file. These are for you, the reader, to help you understand what is happening.
Feel free to delete them once you know what you're doing, but they should serve as a guide
for when you are first encountering a few different constructs in your Neovim config.
If you experience any errors while trying to install kickstart, run `:checkhealth` for more info.
I hope you enjoy your Neovim journey,
- TJ
P.S. You can delete this when you're done too. It's your config now! :)
--]]
-- Set <space> as the leader key
-- See `:help mapleader`
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
@ -110,7 +45,6 @@ vim.api.nvim_create_autocmd({ 'FileType' }, {
vim.opt_local.shiftwidth = 2
end,
})
-- [[ Setting options ]]
-- See `:help vim.opt`
-- NOTE: You can change these options as you wish!
@ -147,7 +81,7 @@ vim.opt.smartcase = true
vim.opt.signcolumn = 'yes'
-- Decrease update time
vim.opt.updatetime = 250
vim.opt.updatetime = 125
-- Decrease mapped sequence wait time
-- Displays which-key popup sooner
@ -184,7 +118,6 @@ vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
-- is not what someone will guess without a bit more experience.
@ -258,7 +191,8 @@ local opts = {
},
}
require 'autocommand'
require 'fancyutil'
require('lazy').setup('plugins', opts)
-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et

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,
'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,
},
{
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' },
},
},
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,5 +1,4 @@
return {
{
'stevearc/oil.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
event = 'VimEnter',
@ -12,6 +11,19 @@ return {
mode = '',
desc = 'Close current window',
},
{
'<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>',
@ -21,7 +33,7 @@ return {
{
'<Left>',
function()
if require('oil.util').is_oil_bufnr(0) then
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)
@ -31,7 +43,7 @@ return {
local keys = vim.api.nvim_replace_termcodes('<Left>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = 'i',
mode = '',
desc = 'Move up the file tree',
},
{
@ -40,7 +52,7 @@ return {
local oil = require 'oil'
local entry = oil.get_cursor_entry()
local dir = oil.get_current_dir()
if entry and dir then
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
@ -51,16 +63,17 @@ return {
local keys = vim.api.nvim_replace_termcodes('<Right>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = 'i',
mode = '',
desc = 'Move down the file tree',
},
},
opts = {
default_file_explorer = true,
restore_window_options = true,
win_options = {
wrap = true,
signcolumn = 'no',
signcolumn = 'yes',
cursorcolumn = false,
foldcolumn = '0',
spell = false,
@ -68,7 +81,6 @@ return {
conceallevel = 3,
concealcursor = 'nivc',
},
restore_window_options = true,
view_options = {
show_hidden = true,
@ -76,10 +88,31 @@ return {
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,
},
},
},
}

View File

@ -17,7 +17,7 @@
commit_author: Some(Rgb(116, 199, 236)),
danger_fg: Some(Rgb(243, 139, 168)),
push_gauge_bg: Some(Rgb(137, 180, 250)),
push_gauge_fg: Some(Rgb(30, 30, 46)),
push_gauge_fg: some(Rgb(30, 30, 46)),
tag_fg: Some(Rgb(245, 224, 220)),
branch_fg: Some(Rgb(148, 226, 213))
)

View File

@ -1,11 +0,0 @@
-- @return true | false | nil
function get_oil_nnn(winnr)
local ok, value = pcall(vim.api.nvim_win_get_var, winnr, 'nnn')
if not ok then
return nil
end
if value then
return true
end
return false
end