From feb59d91c54d95b59f0ed27ae4c4f3336fad3795 Mon Sep 17 00:00:00 2001 From: Iwaniuk Krzysztof Date: Fri, 7 Jun 2024 03:14:27 +0200 Subject: [PATCH] lots of macbook vim stuff --- .luacheckrc | 15 +++ init.lua | 74 +----------- lua/autocommand.lua | 5 + lua/fancyutil.lua | 19 +++ lua/plugins/highlight-action.lua | 2 +- lua/plugins/init.lua | 1 - lua/plugins/lazydev.lua | 25 ++++ lua/plugins/lint.lua | 1 + lua/plugins/lsp.lua | 33 +++--- lua/plugins/lualine.lua | 44 +++---- lua/plugins/neodev.lua | 17 --- lua/plugins/nvim-cmp.lua | 2 + lua/plugins/oil.lua | 193 ++++++++++++++++++------------- lua/plugins/schemastore.lua | 4 +- lua/plugins/tabline.lua | 4 +- lua/plugins/trouble.lua | 23 ++++ lua/plugins/which-key.lua | 2 +- lua/plugins/yanky.lua | 16 +++ mocha.ron | 2 +- util.lua | 11 -- 20 files changed, 267 insertions(+), 226 deletions(-) create mode 100644 .luacheckrc create mode 100644 lua/autocommand.lua create mode 100644 lua/fancyutil.lua create mode 100644 lua/plugins/lazydev.lua delete mode 100644 lua/plugins/neodev.lua create mode 100644 lua/plugins/trouble.lua create mode 100644 lua/plugins/yanky.lua delete mode 100644 util.lua diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 00000000..661a112a --- /dev/null +++ b/.luacheckrc @@ -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 +} diff --git a/init.lua b/init.lua index 344ea8cc..f6ba04c3 100644 --- a/init.lua +++ b/init.lua @@ -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: - - - - : - - Tutor - - - - (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 "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 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', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) vim.keymap.set('n', '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 , 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 diff --git a/lua/autocommand.lua b/lua/autocommand.lua new file mode 100644 index 00000000..be8a4330 --- /dev/null +++ b/lua/autocommand.lua @@ -0,0 +1,5 @@ +vim.cmd [[:command! -nargs=1 I lua inspectFn()]] +function inspectFn(obj) + local cmd = string.format('lua print(vim.inspect(%s))', obj) + require('noice').redirect(cmd, { view = 'messages', filter = {} }) +end diff --git a/lua/fancyutil.lua b/lua/fancyutil.lua new file mode 100644 index 00000000..e94de0ca --- /dev/null +++ b/lua/fancyutil.lua @@ -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 diff --git a/lua/plugins/highlight-action.lua b/lua/plugins/highlight-action.lua index 022585c7..4fa0b62a 100644 --- a/lua/plugins/highlight-action.lua +++ b/lua/plugins/highlight-action.lua @@ -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 }), diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index d8ac6e91..1eaaffa5 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -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 = { diff --git a/lua/plugins/lazydev.lua b/lua/plugins/lazydev.lua new file mode 100644 index 00000000..cf2c1371 --- /dev/null +++ b/lua/plugins/lazydev.lua @@ -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, + }, +} diff --git a/lua/plugins/lint.lua b/lua/plugins/lint.lua index 66a74f1f..91c8d59b 100644 --- a/lua/plugins/lint.lua +++ b/lua/plugins/lint.lua @@ -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, }) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index cd6a4073..00312122 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -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 = {}, - }, }, } diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index 090c168c..e0219641 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -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 = { diff --git a/lua/plugins/neodev.lua b/lua/plugins/neodev.lua deleted file mode 100644 index 7e8fc97a..00000000 --- a/lua/plugins/neodev.lua +++ /dev/null @@ -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, - }, - }, -} diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua index 4f2c0158..c7ec8d1e 100644 --- a/lua/plugins/nvim-cmp.lua +++ b/lua/plugins/nvim-cmp.lua @@ -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' }, diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua index 25793028..337e19cf 100644 --- a/lua/plugins/oil.lua +++ b/lua/plugins/oil.lua @@ -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', - }, - { - '~', - 'Oil', - mode = '', - desc = 'Open parent directory', - }, - { - '', - 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('', true, false, true) - vim.api.nvim_feedkeys(keys, 'n', false) - end, - mode = 'i', - desc = 'Move up the file tree', - }, - { - '', - 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('', 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', - }, + { + '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', + }, + { + '~', + 'Oil', + mode = '', + desc = 'Open parent directory', + }, + { + '', + 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('', true, false, true) + vim.api.nvim_feedkeys(keys, 'n', false) + end, + mode = '', + desc = 'Move up the file tree', + }, + { + '', + 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('', 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, } diff --git a/lua/plugins/schemastore.lua b/lua/plugins/schemastore.lua index ed6f4282..4a7ae05c 100644 --- a/lua/plugins/schemastore.lua +++ b/lua/plugins/schemastore.lua @@ -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(), }, diff --git a/lua/plugins/tabline.lua b/lua/plugins/tabline.lua index ff2f57b4..5e2e49d2 100644 --- a/lua/plugins/tabline.lua +++ b/lua/plugins/tabline.lua @@ -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 }, diff --git a/lua/plugins/trouble.lua b/lua/plugins/trouble.lua new file mode 100644 index 00000000..ff48e2e9 --- /dev/null +++ b/lua/plugins/trouble.lua @@ -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', + }, +} diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 35b7c7b0..0300dca0 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -20,7 +20,7 @@ return { end, { desc = '[T]oggle [N]umbers' }) vim.keymap.set('n', '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, }, diff --git a/lua/plugins/yanky.lua b/lua/plugins/yanky.lua new file mode 100644 index 00000000..2f8da55c --- /dev/null +++ b/lua/plugins/yanky.lua @@ -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, + }, + }, + }, +} diff --git a/mocha.ron b/mocha.ron index 9818424e..7a4be738 100644 --- a/mocha.ron +++ b/mocha.ron @@ -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)) ) diff --git a/util.lua b/util.lua deleted file mode 100644 index c66e0ee4..00000000 --- a/util.lua +++ /dev/null @@ -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