diff options
| author | hachem <im@hachem.wtf> | 2024-10-11 15:09:38 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2024-10-11 15:09:38 +0200 |
| commit | ad04f4345377b92eb2464a352dae5f3cd2194ca2 (patch) | |
| tree | 74cd1950aa1520b635606c09ad3f276c2635509f | |
| parent | 3fdd611e3354d286840bf797f637f0a05f591c60 (diff) | |
Add nvim
| -rw-r--r-- | .config/nvim/init.lua | 546 | ||||
| -rw-r--r-- | .config/nvim/lazy-lock.json | 21 |
2 files changed, 390 insertions, 177 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index cdfaa9e..8b1da4a 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,197 +1,431 @@ -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', lazypath, }) +local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = 'https://github.com/folke/lazy.nvim.git' + local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } + if vim.v.shell_error ~= 0 then + error('Error cloning lazy.nvim:\n' .. out) + end end vim.opt.rtp:prepend(lazypath) -require('lazy').setup -{ - { - 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', - config = function () - local configs = require('nvim-treesitter.configs') +require('lazy').setup({ + 'tpope/vim-sleuth', + 'lambdalisue/suda.vim', + 'lukas-reineke/indent-blankline.nvim', - configs.setup({ - sync_install = false, - highlight = { enable = true }, - indent = { enable = true }, + { + 'windwp/nvim-autopairs', + opts = {} + }, + + { + 'rainglow/vim', + config = function() + vim.cmd [[colorscheme bold-contrast]] + end + }, + + { + 'nvim-telescope/telescope.nvim', + tag = '0.1.8', + dependencies = { + 'nvim-lua/plenary.nvim', + }, + }, + + { + 'folke/noice.nvim', + event = 'VeryLazy', + dependencies = { + 'MunifTanjim/nui.nvim', + 'hrsh7th/nvim-cmp', + }, + config = function() + require('noice').setup({ + lsp = { + override = { + ['vim.lsp.util.convert_input_to_markdown_lines'] = true, + ['cmp.entry.get_documentation'] = true + }, + }, + + presets = { + bottom_search = true, + command_palette = true, + long_message_to_split = true, + inc_rename = false, + lsp_doc_border = false, + } + }) + end, + }, + + { + 'Bilal2453/luvit-meta', + lazy = true + }, + + { + 'neovim/nvim-lspconfig', + dependencies = { + { + 'j-hui/fidget.nvim', + opts = {} + }, + + { + 'williamboman/mason.nvim', + config = true + }, + + 'williamboman/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', + 'hrsh7th/cmp-nvim-lsp', + }, + + config = function() + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), + callback = function(event) + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') + map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) + map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then + local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, }) - end - }, + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.clear_references, + }) - { 'm00qek/baleia.nvim', tag = 'v1.3.0' }, + vim.api.nvim_create_autocmd('LspDetach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), + callback = function(event2) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } + end, + }) + end - 'lukas-reineke/indent-blankline.nvim', - 'nvim-telescope/telescope.nvim', - 'andreasvc/vim-256noir', - 'luisiacc/gruvbox-baby', - 'voldikss/vim-floaterm', - 'nvim-lua/plenary.nvim', - 'windwp/nvim-autopairs', - 'sam4llis/nvim-tundra', - 'sheerun/vim-polyglot', - 'lambdalisue/suda.vim', - 'etdev/vim-hexcolor', - 'tpope/vim-fugitive', - 'rust-lang/rust.vim', - 'preservim/nerdtree', - 'peterhoeg/vim-qml', - 'rainglow/vim', -} + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then + map('<leader>th', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) + end, '[T]oggle Inlay [H]ints') + end + end, + }) + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) + local servers = { + clangd = {}, + rust_analyzer = {}, -require('nvim-treesitter.configs').setup( -{ - highlight = - { - enable = true, - additional_vim_regex_highlighting = true, - } -}) + lua_ls = { + settings = { + Lua = { + completion = { + callSnippet = 'Replace', + }, + }, + }, + }, + } -require('telescope').setup -{ - defaults = - { - file_ignore_patterns = - { - 'node_modules/', - - 'vendor/', - 'Vendor/', - - 'bin/', - 'bin-int/', - - 'build/', + require('mason').setup() - 'Cargo.lock', - } - } -} + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + 'stylua', + }) + require('mason-tool-installer').setup { ensure_installed = ensure_installed } -require('nvim-autopairs').setup() + require('mason-lspconfig').setup { + handlers = { + function(server_name) + local server = servers[server_name] or {} + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + require('lspconfig')[server_name].setup(server) + end, + }, + } + end, + }, -vim.opt.termguicolors = true -vim.opt.cursorline = true -vim.opt.showcmd = false -vim.opt.laststatus = 0 -vim.opt.relativenumber = true -vim.opt.linebreak = true -vim.opt.wrap = false -vim.opt.splitbelow = true -vim.opt.splitright = true -vim.opt.swapfile = false -vim.opt.backup = false -vim.opt.hlsearch = false -vim.opt.incsearch = true -vim.opt.autoread = true -vim.opt.autowrite = true -vim.opt.expandtab = true -vim.opt.shiftwidth = 4 -vim.opt.tabstop = 4 -vim.opt.guicursor = '' -vim.opt.rulerformat = '(%l:%c%V)' -vim.opt.smartindent = true -vim.opt.fillchars.vert = ' ' -vim.opt.fillchars.eob = ' ' -vim.opt.background = 'dark' -vim.opt.clipboard = 'unnamedplus' + { + 'nvim-lualine/lualine.nvim', + dependencies = { + 'nvim-tree/nvim-web-devicons', + }, + config = function() + local lualine = require('lualine') -vim.g.mapleader = ' ' + local colors = { + bg = '#00000000', + 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, + } -vim.g.NERDTreeMinimalUI = true -vim.g.NERDTreeWinPos = 'right' -vim.g.NERDTreeWinSize = 20 + local config = { + options = { + component_separators = '', + section_separators = '', + theme = { + normal = { c = { fg = colors.fg, bg = colors.bg } }, + inactive = { c = { fg = colors.fg, bg = colors.bg } }, + }, + }, + sections = { + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + lualine_c = {}, + lualine_x = {}, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + lualine_c = {}, + lualine_x = {}, + }, + } -vim.g.floaterm_borderchars = ' ' -vim.g.floaterm_position = 'right' -vim.g.floaterm_autoinsert = true -vim.g.floaterm_autoclose = false -vim.g.floaterm_height = 1.0 -vim.g.floaterm_title = '' + local function ins_left(component) + table.insert(config.sections.lualine_c, component) + end + local function ins_right(component) + table.insert(config.sections.lualine_x, component) + end -vim.g.rust_clip_command = 'xclip -selection clipboard' -vim.g.cargo_shell_command_runner = 'FloatermNew' + ins_left { + function() + return '▊' + end, + color = { fg = colors.blue }, + padding = { left = 0, right = 1 }, + } -vim.api.nvim_set_keymap('n', '<F12>', ':FloatermNew<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<F11>', ':FloatermKill<CR>', { noremap = true }) + ins_left { + function() + return '' + end, + color = function() + 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 }, + } -vim.api.nvim_set_keymap('n', '<C-e>', ':NERDTreeToggle<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<C-t>', ':NERDTreeFocus<CR>', { noremap = true }) + ins_left { + 'filesize', + cond = conditions.buffer_not_empty, + } -vim.api.nvim_set_keymap('n', '<leader>ff', '<CMD>Telescope find_files<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<leader>fg', '<CMD>Telescope live_grep<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<leader>fb', '<CMD>Telescope buffers<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<leader>fh', '<CMD>Telescope help_tags<CR>', { noremap = true }) + ins_left { + 'filename', + cond = conditions.buffer_not_empty, + color = { fg = colors.magenta, gui = 'bold' }, + } -vim.api.nvim_set_keymap('n', '<leader>tn', '<CMD>tabn<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<leader>tp', '<CMD>tabp<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<leader>tt', '<CMD>tabnew<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<leader>tl', '<CMD>tablast<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<leader>tf', '<CMD>tabfirst<CR>', { noremap = true }) + ins_left { 'location' } + ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } } + ins_left { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + symbols = { error = ' ', warn = ' ', info = ' ' }, + diagnostics_color = { + error = { fg = colors.red }, + warn = { fg = colors.yellow }, + info = { fg = colors.cyan }, + }, + } -vim.api.nvim_set_keymap('n', '<C-h>', ':vertical resize -3<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<C-l>', ':vertical resize +3<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<C-j>', ':resize -3<CR>', { noremap = true }) -vim.api.nvim_set_keymap('n', '<C-k>', ':resize +3<CR>', { noremap = true }) + ins_left { + function() + return '%=' + end, + } -vim.api.nvim_set_keymap('n', 'j', 'gj', { noremap = true }) -vim.api.nvim_set_keymap('n', 'k', 'gk', { noremap = true }) + ins_left { + function() + local msg = 'No Active Lsp' + local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype') + local clients = vim.lsp.get_active_clients() + if next(clients) == nil then + return msg + end + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return client.name + end + end + return msg + end, + icon = ' LSP:', + color = { fg = '#ffffff', gui = 'bold' }, + } -vim.api.nvim_set_keymap('n', ';', ':', { noremap = true }) -vim.api.nvim_set_keymap('v', ';', ':', { noremap = true }) + ins_right { + 'o:encoding', + fmt = string.upper, + cond = conditions.hide_in_width, + color = { fg = colors.green, gui = 'bold' }, + } -vim.api.nvim_set_keymap('t', '<Esc>', '<C-\\><C-n>', { noremap = true }) -vim.api.nvim_set_keymap('', 'Q', '<Nop>', { noremap = false }) + ins_right { + 'fileformat', + fmt = string.upper, + icons_enabled = false, + color = { fg = colors.green, gui = 'bold' }, + } -vim.cmd([[ - aunmenu PopUp.How-to\ disable\ mouse - aunmenu PopUp.-1- + ins_right { + 'branch', + icon = '', + color = { fg = colors.violet, gui = 'bold' }, + } - au BufReadPost,BufNewFile *.dart set sw=2 ts=2 - au BufReadPost,BufNewFile *.md set linebreak wrap + ins_right { + 'diff', + symbols = { added = ' ', modified = ' ', removed = ' ' }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.orange }, + removed = { fg = colors.red }, + }, + cond = conditions.hide_in_width, + } - au BufReadPost,BufNewFile *.csx set ft=cs - au BufReadPost,BufNewFile *.asm set ft=nasm - au BufReadPost,BufNewFile *.s set ft=nasm - au BufReadPost,BufNewFile *.hpp set ft=cpp + ins_right { + function() + return '▊' + end, + color = { fg = colors.blue }, + padding = { left = 1 }, + } - au BufReadPost,BufNewFile *.rs nnoremap <F5> :Crun<CR> - au BufReadPost,BufNewFile *.rs nnoremap <F10> :Cbuild<CR> - au BufReadPost,BufNewFile *.rs nnoremap <F7> :RustFmt<CR> + lualine.setup(config) + end + }, +}) + +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +vim.opt.number = true +vim.opt.mouse = 'a' +vim.opt.showmode = false +vim.opt.breakindent = false +vim.opt.wrap = false +vim.opt.undofile = false +vim.opt.inccommand = 'split' +vim.opt.clipboard = 'unnamedplus' +vim.opt.cursorline = true +vim.opt.scrolloff = 10 +vim.opt.ignorecase = true +vim.opt.smartcase = true +vim.opt.splitright = true +vim.opt.splitbelow = true +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true +vim.opt.smartindent = true +vim.opt.autoindent = true +vim.opt.termguicolors = true - au BufReadPost,BufNewFile *.go nnoremap <F5> :FloatermNew go run .<CR> - au BufReadPost,BufNewFile *.go nnoremap <F10> :FloatermNew go build .<CR> +vim.opt.list = true +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } - au BufReadPost,BufNewFile *.c nnoremap <F5> :FloatermNew make run<CR> - au BufReadPost,BufNewFile *.c nnoremap <F10> :FloatermNew make build<CR> +local telescope_builtin = require('telescope.builtin') +vim.keymap.set('n', '<leader>ff', telescope_builtin.find_files) +vim.keymap.set('n', '<leader>fg', telescope_builtin.live_grep) +vim.keymap.set('n', '<leader>fb', telescope_builtin.buffers) +vim.keymap.set('n', '<leader>fh', telescope_builtin.help_tags) - syntax on - colorscheme 256_noir +vim.keymap.set('n', '<Esc>', '<CMD>nohlsearch<CR>') +vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>') - hi VertSplit guifg=#000000 guibg=NONE +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, +}) - hi LineNr guibg=NONE guifg=#333333 +vim.api.nvim_command [[ hi Normal guibg=NONE hi Visual guibg=#212121 hi NonText guibg=NONE - hi CursorLine guibg=#0A0A0A hi StatusLine guibg=#000000 hi SignColumn guibg=#000000 guifg=#000000 hi EndOfBuffer guibg=NONE - - hi Comment gui=italic - hi Macro gui=bold - - hi IndentBlankLineChar guifg=#333333 - hi FloatermBorder guibg=#0A0A0A - - command W w - command Q q - command WQ wq - command Wq wq -]]) - + hi VertSplit guifg=#00000000 guibg=NONE + hi Comment gui=italic + hi Macro gui=bold +]] diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json deleted file mode 100644 index 3001afe..0000000 --- a/.config/nvim/lazy-lock.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "baleia.nvim": { "branch": "main", "commit": "fb3aff021b2b64ef820d0230d2c22ebfaf71bb6a" }, - "gruvbox-baby": { "branch": "main", "commit": "bd52e62d8134647090108189e69c8b3cd18bdbbf" }, - "indent-blankline.nvim": { "branch": "master", "commit": "3d08501caef2329aba5121b753e903904088f7e6" }, - "lazy.nvim": { "branch": "main", "commit": "83493db50a434a4c5c648faf41e2ead80f96e478" }, - "nerdtree": { "branch": "master", "commit": "f3a4d8eaa8ac10305e3d53851c976756ea9dc8e8" }, - "nvim-autopairs": { "branch": "master", "commit": "c6139ca0d5ad7af129ea6c89cb4c56093f2c034a" }, - "nvim-treesitter": { "branch": "master", "commit": "bb3dd60ebcf6f75f73f39c44724b4a426ece6b7b" }, - "nvim-tundra": { "branch": "main", "commit": "374ec2e2075ebe699a20d29e0c141cf5113adf0c" }, - "plenary.nvim": { "branch": "master", "commit": "f7adfc4b3f4f91aab6caebf42b3682945fbc35be" }, - "rust.vim": { "branch": "master", "commit": "889b9a7515db477f4cb6808bef1769e53493c578" }, - "suda.vim": { "branch": "master", "commit": "66727b416837836712975e748bc8a19fb6cf4ec3" }, - "telescope.nvim": { "branch": "master", "commit": "e9e01d699843af530ef4ad2c8679a7e273bb3dd1" }, - "vim": { "branch": "master", "commit": "837fd7292274e0ee2f3b5aee4519c3f74d7dc3d1" }, - "vim-256noir": { "branch": "master", "commit": "e8668a18a4a90272c1cae87e655f8bddc5ac3665" }, - "vim-floaterm": { "branch": "master", "commit": "c0535d758004bcce016839e318cbbe802b92c469" }, - "vim-fugitive": { "branch": "master", "commit": "8d4e8d45385c63a0bf735fe1164772116bf0da0d" }, - "vim-hexcolor": { "branch": "master", "commit": "f80182254377c402f90536802732aad69acc5d99" }, - "vim-polyglot": { "branch": "master", "commit": "bc8a81d3592dab86334f27d1d43c080ebf680d42" }, - "vim-qml": { "branch": "master", "commit": "892c36a80a8711025af7bb9d09a8a6b90fe3d0c8" } -}
\ No newline at end of file |
