From 169148fc14e8776b76ac83079fde08270944bb12 Mon Sep 17 00:00:00 2001 From: speedie Date: Fri, 19 Jan 2024 11:29:06 +0100 Subject: [PATCH] speedie-nvim | Add new config --- .config/nvim/.luarc.json | 13 ++ .config/nvim/init.lua | 117 +++++++++++----- .config/nvim/lazy-lock.json | 19 +++ .config/nvim/lua/bootstrap.lua | 18 +++ .config/nvim/lua/lsp_config.lua | 5 + .config/nvim/lua/lualine_config.lua | 202 ++++++++++++++++++++++++++++ 6 files changed, 344 insertions(+), 30 deletions(-) create mode 100644 .config/nvim/.luarc.json create mode 100644 .config/nvim/lazy-lock.json create mode 100644 .config/nvim/lua/bootstrap.lua create mode 100644 .config/nvim/lua/lsp_config.lua create mode 100644 .config/nvim/lua/lualine_config.lua diff --git a/.config/nvim/.luarc.json b/.config/nvim/.luarc.json new file mode 100644 index 0000000..154c5b3 --- /dev/null +++ b/.config/nvim/.luarc.json @@ -0,0 +1,13 @@ +{ + "runtime.version": "LuaJIT", + "runtime.path": [ + "lua/?.lua", + "lua/?/init.lua" + ], + "diagnostics.globals": ["vim"], + "workspace.checkThirdParty": false, + "workspace.library": [ + "$VIMRUNTIME", + "./lua" + ] +} diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 3c7547e..f4b9216 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -3,14 +3,44 @@ -- https://git.speedie.site/speedie/speedie-nvim -- ]]-- +require('bootstrap') + local cmd = vim.cmd local opt = vim.opt local o = vim.o -local api = vim.api local keymap = vim.api.nvim_set_keymap local autocmd = vim.api.nvim_create_autocmd local sessionFile = vim.fn.expand('~/.config/nvim/.session.nvim') +require("lazy").setup({ + { 'nvim-telescope/telescope.nvim', dependencies = { + 'nvim-lua/plenary.nvim', + } }, -- Fuzzy-finding + { 'nvim-lualine/lualine.nvim' }, -- Status line + { 'm4xshen/autoclose.nvim' }, -- Autoclose brackets + { 'romgrk/doom-one.vim' }, -- Doom-One theme + { 'stevearc/conform.nvim' }, -- Formatting + { 'romgrk/barbar.nvim', + dependencies = { + 'lewis6991/gitsigns.nvim', + 'nvim-tree/nvim-web-devicons', + }, opts = { + clickable = true, + animation = true, + focus_on_close = 'left', + } }, -- Tabs + { 'williamboman/mason.nvim', + dependencies = { + 'williamboman/mason-lspconfig.nvim', + } }, -- Server auto-install + { 'VonHeikemen/lsp-zero.nvim', branch = 'v3.x', dependencies = { + 'neovim/nvim-lspconfig', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/nvim-cmp', + 'L3MON4D3/LuaSnip', + } }, -- LSP +}) + opt.title = true -- Display title opt.spelllang = 'en_us' -- Use English (United States) as spellcheck language by default opt.relativenumber = true -- Show relative line numbers @@ -25,7 +55,7 @@ opt.smartindent = true -- Automatically indent the next line opt.autoindent = true -- Pretty much same for this one opt.expandtab = true -- Replace tabs with spaces automatically opt.swapfile = false -- Don't use a swapfile -opt.cursorline = false -- Don't show the cursor line +opt.cursorline = true -- Show the cursor line opt.undolevels = 10000 -- Allow up to 10000 undos opt.tabstop = 4 -- Display a tab (\t) as 4 spaces opt.softtabstop = 4 -- Display a tab (\t) as 4 spaces @@ -41,45 +71,67 @@ o.t_8f = '\27[38;2;%lu;%lu;%lum' -- To be honest, I don't know what this does bu o.t_8b = '\27[48;2;%lu;%lu;%lum' -- To be honest, I don't know what this does but if I remember correctly it's something good. cmd([[ - colorscheme elflord + colorscheme doom-one highlight Normal ctermfg=grey ctermbg=lightgray guifg=#ffffff guibg=#222222 + highlight EndOfBuffer ctermfg=grey ctermbg=lightgray guifg=#ffffff guibg=#222222 highlight Folded ctermfg=grey ctermbg=lightgray guifg=#afeeee guibg=#333333 highlight SpellBad guisp=red gui=undercurl guifg=none guibg=none ctermfg=none ctermbg=none term=underline cterm=undercurl highlight SpellCap guisp=yellow gui=undercurl guifg=none guibg=none ctermfg=none ctermbg=none term=underline cterm=undercurl filetype plugin indent on ]]) -keymap('n', '', 'h', { noremap = true }) -keymap('n', '', 'j', { noremap = true }) -keymap('n', '', 'k', { noremap = true }) -keymap('n', '', 'l', { noremap = true }) -keymap('n', '', ':split', { noremap = true }) -keymap('n', '', ':vsplit', { noremap = true }) -keymap('n', '', ':only', { noremap = true }) -keymap('n', '', ':term', { noremap = true }) -keymap('n', '', ':set spell!', { noremap = true }) -keymap('n', '', ':set spelllang=en_us', { noremap = true }) -keymap('n', '', ':set spelllang=sv_se', { noremap = true }) -keymap('n', '', ':silent execute "!setxkbmap us"', { noremap = true }) -keymap('n', '', ':silent execute "!setxkbmap se"', { noremap = true }) -keymap('n', '', '[sz=', { noremap = true }) -keymap('n', '', 'z=', { noremap = true }) -keymap('n', '', ':!ninja -C build', { noremap = true }) -keymap('n', 'H', ':vertical resize -10', { noremap = true }) -keymap('n', 'J', ':resize -10', { noremap = true }) -keymap('n', 'K', ':resize +10', { noremap = true }) -keymap('n', 'L', ':vertical resize +10', { noremap = true }) -keymap('n', 'd', '"_d', { noremap = true }) -keymap('x', 'd', '"_d', { noremap = true }) -keymap('x', 'p', '"_dP', { noremap = true }) -keymap('n', 'c', '"_c', { noremap = true }) -keymap('n', '', 'v/{%', { noremap = true }) +keymap('n', '', 'h', { noremap = true, silent = true }) +keymap('n', '', 'j', { noremap = true, silent = true }) +keymap('n', '', 'k', { noremap = true, silent = true }) +keymap('n', '', 'l', { noremap = true, silent = true }) +keymap('n', '', ':split', { noremap = true, silent = true }) +keymap('n', '', ':vsplit', { noremap = true, silent = true }) +keymap('n', '', ':only', { noremap = true, silent = true }) +keymap('n', '', ':term', { noremap = true, silent = true }) +keymap('n', '', ':Telescope fd', { noremap = true, silent = true }) +keymap('n', '', ':set spell!', { noremap = true, silent = true }) +keymap('n', '', ':set spelllang=en_us', { noremap = true, silent = true }) +keymap('n', '', ':set spelllang=sv_se', { noremap = true, silent = true }) +keymap('n', '', ':silent execute "!setxkbmap us"', { noremap = true, silent = true }) +keymap('n', '', ':silent execute "!setxkbmap se"', { noremap = true, silent = true }) +keymap('n', '', 'z=', { noremap = true, silent = true }) +keymap('n', '', ':!ninja -C build', { noremap = true, silent = true }) +keymap('n', 'H', ':vertical resize -10', { noremap = true, silent = true }) +keymap('n', 'J', ':resize -10', { noremap = true, silent = true }) +keymap('n', 'K', ':resize +10', { noremap = true, silent = true }) +keymap('n', 'L', ':vertical resize +10', { noremap = true, silent = true }) +keymap('n', 'd', '"_d', { noremap = true, silent = true }) +keymap('x', 'd', '"_d', { noremap = true, silent = true }) +keymap('x', 'p', '"_dP', { noremap = true, silent = true }) +keymap('n', 'c', '"_c', { noremap = true, silent = true }) +keymap('n', '', 'v/{%', { noremap = true, silent = true }) +keymap('n', '', 'BufferPrevious', { noremap = true, silent = true }) +keymap('n', '', 'BufferNext', { noremap = true, silent = true }) +keymap('n', '', 'BufferMovePrevious', { noremap = true, silent = true }) +keymap('n', '>', 'BufferMoveNext', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 1', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 2', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 3', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 4', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 5', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 6', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 7', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 8', { noremap = true, silent = true }) +keymap('n', '', 'BufferGoto 9', { noremap = true, silent = true }) +keymap('n', '', 'BufferLast', { noremap = true, silent = true }) +keymap('n', '', 'BufferPin', { noremap = true, silent = true }) +keymap('n', '', 'BufferClose', { noremap = true, silent = true }) +keymap('n', 'bb', 'BufferOrderByBufferNumber', { noremap = true, silent = true }) +keymap('n', 'bd', 'BufferOrderByDirectory', { noremap = true, silent = true }) +keymap('n', 'bl', 'BufferOrderByLanguage', { noremap = true, silent = true }) +keymap('n', 'bw', 'BufferOrderByWindowNumber', { noremap = true, silent = true }) -function saveSession() -- Save the current session + +local function saveSession() -- Save the current session vim.cmd('mksession! ' .. sessionFile) end -function restoreSession() -- Restore the last session +local function restoreSession() -- Restore the last session if vim.fn.argc() == 0 then if vim.fn.filereadable(sessionFile) == 1 then vim.cmd('source ' .. sessionFile) @@ -118,3 +170,8 @@ autocmd('VimLeave', { -- Save session on exit saveSession() end, }) + +require('lsp_config') +require('lualine_config') +require('conform').setup({}) +require('autoclose').setup({}) diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json new file mode 100644 index 0000000..c1538a3 --- /dev/null +++ b/.config/nvim/lazy-lock.json @@ -0,0 +1,19 @@ +{ + "LuaSnip": { "branch": "master", "commit": "2dbef19461198630b3d7c39f414d09fb07d1fdd2" }, + "autoclose.nvim": { "branch": "main", "commit": "37e11589aac55b0e8810dc5865f898f9cb36fef6" }, + "barbar.nvim": { "branch": "master", "commit": "4ba9ac54f0c5d82131905160afff94172e3325e6" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "conform.nvim": { "branch": "master", "commit": "cbc5745bf7519acaf3a5cbaaa677fd556aa813d7" }, + "doom-one.vim": { "branch": "master", "commit": "323b7c31c617b153d12095e9fd9648f2fda2b646" }, + "gitsigns.nvim": { "branch": "main", "commit": "4aaacbf5e5e2218fd05eb75703fe9e0f85335803" }, + "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "dec1c21204e2d9d49dad989b577c88958ed2c113" }, + "lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "3ba1b92b771f33256b4969d696b82c8ae7075364" }, + "mason.nvim": { "branch": "main", "commit": "e110bc3be1a7309617cecd77bfe4bf86ba1b8134" }, + "nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" }, + "nvim-lspconfig": { "branch": "master", "commit": "7eed8b2150192e5ad05e1886fdf133493ddf2928" }, + "nvim-web-devicons": { "branch": "master", "commit": "140edfcf25093e8b321d13e154cbce89ee868ca0" }, + "plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" }, + "telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" } +} \ No newline at end of file diff --git a/.config/nvim/lua/bootstrap.lua b/.config/nvim/lua/bootstrap.lua new file mode 100644 index 0000000..fb33348 --- /dev/null +++ b/.config/nvim/lua/bootstrap.lua @@ -0,0 +1,18 @@ +--[[ + speedie's neovim configuration + -- https://git.speedie.site/speedie/speedie-nvim -- +]]-- + + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) diff --git a/.config/nvim/lua/lsp_config.lua b/.config/nvim/lua/lsp_config.lua new file mode 100644 index 0000000..7354192 --- /dev/null +++ b/.config/nvim/lua/lsp_config.lua @@ -0,0 +1,5 @@ +local lsp_zero = require('lsp-zero') +lsp_zero.on_attach(function(client, bufnr) lsp_zero.default_keymaps({buffer = bufnr}) end) + +require('mason').setup({}) +require('mason-lspconfig').setup({handlers = { lsp_zero.default_setup }, }) diff --git a/.config/nvim/lua/lualine_config.lua b/.config/nvim/lua/lualine_config.lua new file mode 100644 index 0000000..2dc7c20 --- /dev/null +++ b/.config/nvim/lua/lualine_config.lua @@ -0,0 +1,202 @@ +-- Eviline config for lualine +-- Author: shadmansaleh +-- Credit: glepnir +require('lualine').setup() + +local lualine = require('lualine') + +-- Color table for highlights +-- stylua: ignore +local colors = { + bg = '#202328', + fg = '#bbc2cf', + yellow = '#ECBE7B', + cyan = '#008080', + darkblue = '#081633', + green = '#98be65', + orange = '#FF8800', + violet = '#a9a1e1', + magenta = '#c678dd', + blue = '#51afef', + red = '#ec5f67', +} + +local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand('%:t')) ~= 1 + end, + hide_in_width = function() + return vim.fn.winwidth(0) > 80 + end, + check_git_workspace = function() + local filepath = vim.fn.expand('%:p:h') + local gitdir = vim.fn.finddir('.git', filepath .. ';') + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, +} + +-- Config +local config = { + options = { + -- Disable sections and component separators + component_separators = '', + section_separators = '', + theme = { + -- We are going to use lualine_c an lualine_x as left and + -- right section. Both are highlighted by c theme . So we + -- are just setting default looks o statusline + normal = { c = { fg = colors.fg, bg = colors.bg } }, + inactive = { c = { fg = colors.fg, bg = colors.bg } }, + }, + }, + sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + -- These will be filled later + lualine_c = {}, + lualine_x = {}, + }, + inactive_sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + lualine_c = {}, + lualine_x = {}, + }, +} + +-- Inserts a component in lualine_c at left section +local function ins_left(component) + table.insert(config.sections.lualine_c, component) +end + +-- Inserts a component in lualine_x at right section +local function ins_right(component) + table.insert(config.sections.lualine_x, component) +end + +ins_left { + function() + return '▊' + end, + color = { fg = colors.blue }, -- Sets highlighting of component + padding = { left = 0, right = 1 }, -- We don't need space before this +} + +ins_left { + -- mode component + function() + return '' + end, + color = function() + -- auto change color according to neovims mode + local mode_color = { + n = colors.red, + i = colors.green, + v = colors.blue, + [''] = colors.blue, + V = colors.blue, + c = colors.magenta, + no = colors.red, + s = colors.orange, + S = colors.orange, + [''] = colors.orange, + ic = colors.yellow, + R = colors.violet, + Rv = colors.violet, + cv = colors.red, + ce = colors.red, + r = colors.cyan, + rm = colors.cyan, + ['r?'] = colors.cyan, + ['!'] = colors.red, + t = colors.red, + } + return { fg = mode_color[vim.fn.mode()] } + end, + padding = { right = 1 }, +} + +ins_left { + -- filesize component + 'filesize', + cond = conditions.buffer_not_empty, +} + +ins_left { + 'filename', + cond = conditions.buffer_not_empty, + color = { fg = colors.magenta, gui = 'bold' }, +} + +ins_left { 'location' } + +ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } } + +ins_left { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + symbols = { error = ' ', warn = ' ', info = ' ' }, + diagnostics_color = { + color_error = { fg = colors.red }, + color_warn = { fg = colors.yellow }, + color_info = { fg = colors.cyan }, + }, +} + +-- Insert mid section. You can make any number of sections in neovim :) +-- for lualine it's any number greater then 2 +ins_left { + function() + return '%=' + end, +} + +-- Add components to right sections +ins_right { + 'o:encoding', -- option component same as &encoding in viml + fmt = string.upper, -- I'm not sure why it's upper case either ;) + cond = conditions.hide_in_width, + color = { fg = colors.green, gui = 'bold' }, +} + +ins_right { + 'fileformat', + fmt = string.upper, + icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh + color = { fg = colors.green, gui = 'bold' }, +} + +ins_right { + 'branch', + icon = '', + color = { fg = colors.violet, gui = 'bold' }, +} + +ins_right { + 'diff', + -- Is it me or the symbol for modified us really weird + symbols = { added = ' ', modified = '󰝤 ', removed = ' ' }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.orange }, + removed = { fg = colors.red }, + }, + cond = conditions.hide_in_width, +} + +ins_right { + function() + return '▊' + end, + color = { fg = colors.blue }, + padding = { left = 1 }, +} + +-- Now don't forget to initialize lualine +lualine.setup(config)