From 70d36b38d8ada8db41a8486d87d31cf98676ffd4 Mon Sep 17 00:00:00 2001 From: hheik <4469778+hheik@users.noreply.github.com> Date: Tue, 30 Dec 2025 17:50:40 +0200 Subject: [PATCH] Added part of configurations --- README.md | 23 ++++++++++ init.lua | 27 ++++++++++++ lazy-lock.json | 20 +++++++++ lsp/lua_ls.lua | 17 ++++++++ lua/general.lua | 34 +++++++++++++++ lua/keymap.lua | 81 +++++++++++++++++++++++++++++++++++ lua/lsp.lua | 11 +++++ lua/plugin/autopairs.lua | 7 +++ lua/plugin/colorscheme.lua | 11 +++++ lua/plugin/lazy.lua | 18 ++++++++ lua/plugin/lspconfig.lua | 11 +++++ lua/plugin/lspkind.lua | 6 +++ lua/plugin/mason.lua | 14 ++++++ lua/plugin/nvim-cmp.lua | 77 +++++++++++++++++++++++++++++++++ lua/plugin/nvimtree-icons.lua | 5 +++ lua/plugin/nvimtree.lua | 33 ++++++++++++++ lua/plugin/telescope.lua | 74 ++++++++++++++++++++++++++++++++ lua/plugin/toggleterm.lua | 12 ++++++ lua/plugin/treesitter.lua | 16 +++++++ lua/scripts.lua | 8 ++++ lua/spec.lua | 10 +++++ 21 files changed, 515 insertions(+) create mode 100644 README.md create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lsp/lua_ls.lua create mode 100644 lua/general.lua create mode 100644 lua/keymap.lua create mode 100644 lua/lsp.lua create mode 100644 lua/plugin/autopairs.lua create mode 100644 lua/plugin/colorscheme.lua create mode 100644 lua/plugin/lazy.lua create mode 100644 lua/plugin/lspconfig.lua create mode 100644 lua/plugin/lspkind.lua create mode 100644 lua/plugin/mason.lua create mode 100644 lua/plugin/nvim-cmp.lua create mode 100644 lua/plugin/nvimtree-icons.lua create mode 100644 lua/plugin/nvimtree.lua create mode 100644 lua/plugin/telescope.lua create mode 100644 lua/plugin/toggleterm.lua create mode 100644 lua/plugin/treesitter.lua create mode 100644 lua/scripts.lua create mode 100644 lua/spec.lua diff --git a/README.md b/README.md new file mode 100644 index 0000000..9d97920 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Requirements: + +## Apt packages + +There are some packages required by Mason, Telescope, etc. + +**Note: this list is very loose list.** + +```shell +sudo apt install gcc ripgrep unzip java-common default-jre luarocks cmake libbinutils moreutils shellcheck +``` + +## Language servers: + +``` +:MasonInstall lua-language-server@3.15.0 +:MasonInstall typescript-language-server +:MasonInstall rust_analyzer +``` + +## NerdFont + +A NerdFont with symbols is required to show icons in tree view diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..260588f --- /dev/null +++ b/init.lua @@ -0,0 +1,27 @@ +require 'general' +require 'spec' + +spec 'plugin/colorscheme' +spec 'plugin/treesitter' +spec 'plugin/telescope' +spec 'plugin/mason' +spec 'plugin/nvimtree' +spec 'plugin/nvimtree-icons' +spec 'plugin/toggleterm' +spec 'plugin/lspconfig' +-- spec 'plugin/bufferline' +-- spec 'plugin/copilot' +-- spec 'plugin/smartword' +-- spec 'plugin/gitsigns' +-- spec 'plugin/lualine' +spec 'plugin/autopairs' +spec 'plugin/lspkind' +spec 'plugin/nvim-cmp' +-- spec 'plugin/nvim-navic' +-- spec 'plugin/csvview' +-- spec 'plugin/which-key' + +require 'plugin/lazy' +require 'lsp' +require 'scripts' +require 'keymap' diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..e373385 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,20 @@ +{ + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-cmdline": { "branch": "main", "commit": "d126061b624e0af6c3a556428712dd4d4194ec6d" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, + "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, + "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, + "lspkind.nvim": { "branch": "master", "commit": "3ddd1b4edefa425fda5a9f95a4f25578727c0bb3" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "4cfe411526a7a99c18281135e8b4765ae6330d15" }, + "mason.nvim": { "branch": "main", "commit": "57e5a8addb8c71fb063ee4acda466c7cf6ad2800" }, + "nvim-autopairs": { "branch": "master", "commit": "c2a0dd0d931d0fb07665e1fedb1ea688da3b80b4" }, + "nvim-cmp": { "branch": "main", "commit": "d97d85e01339f01b842e6ec1502f639b080cb0fc" }, + "nvim-lspconfig": { "branch": "master", "commit": "41ceb6bba3a40128b7841f5b7f5a9dae7201e823" }, + "nvim-tree.lua": { "branch": "master", "commit": "b8b44b6a2494d086a9177251a119f9daec6cace8" }, + "nvim-treesitter": { "branch": "main", "commit": "7efc1b58a8061d29786860006c7257c90a5196dc" }, + "nvim-web-devicons": { "branch": "master", "commit": "6788013bb9cb784e606ada44206b0e755e4323d7" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope.nvim": { "branch": "master", "commit": "4d0f5e0e7f69071e315515c385fab2a4eff07b3d" }, + "toggleterm.nvim": { "branch": "main", "commit": "9a88eae817ef395952e08650b3283726786fb5fb" }, + "tokyonight.nvim": { "branch": "main", "commit": "5da1b76e64daf4c5d410f06bcb6b9cb640da7dfd" } +} diff --git a/lsp/lua_ls.lua b/lsp/lua_ls.lua new file mode 100644 index 0000000..232c5ce --- /dev/null +++ b/lsp/lua_ls.lua @@ -0,0 +1,17 @@ +return { + cmd = { 'lua-language-server' }, + filetypes = { 'lua' }, + root_markers = { '.luarc.json', '.luarc.jsonc' }, + settings = { + Lua = { + runtime = { version = 'LuaJIT' }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file('', true), + checkThirdParty = true, + }, + }, + }, +} diff --git a/lua/general.lua b/lua/general.lua new file mode 100644 index 0000000..915620c --- /dev/null +++ b/lua/general.lua @@ -0,0 +1,34 @@ +local tab_width = 4 + +vim.g.mapleader = ' ' + +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.cursorline = true + +vim.opt.hidden = true + +vim.o.whichwrap = '<,>,[,]' +vim.opt.wrap = false + +vim.opt.shiftwidth = tab_width +vim.opt.tabstop = tab_width +vim.opt.softtabstop = tab_width +vim.opt.expandtab = false + +vim.opt.textwidth = 120 + +vim.opt.undofile = true +vim.opt.undodir = os.getenv('HOME') .. '/.vim/undodir' + +vim.opt.list = true +vim.opt.listchars = { + leadmultispace = ' ', + multispace = '.', + tab = ' - ', +} + +vim.opt.signcolumn = 'number' +vim.opt.scrolloff = 10 + +vim.diagnostic.config { virtual_text = true } diff --git a/lua/keymap.lua b/lua/keymap.lua new file mode 100644 index 0000000..afd1883 --- /dev/null +++ b/lua/keymap.lua @@ -0,0 +1,81 @@ +local vertical_resize_step = 4 +local horizontal_resize_step = 8 +local small_step = 5 +local big_step = 25 + +vim.keymap.set('n', 'w', 'w') +vim.keymap.set('n', 'q', 'q') +vim.keymap.set('n', 'c', 'bpbd#') +vim.keymap.set('n', 'h', 'nohl') +vim.keymap.set('n', 'z', 'set wrap! wrap?') +vim.keymap.set('n', 'x', 'set cursorline! cursorline?') + +vim.keymap.set('n', '', 'k') +vim.keymap.set('n', '', 'j') +vim.keymap.set('n', '', 'h') +vim.keymap.set('n', '', 'l') +vim.keymap.set('n', '', 'k') +vim.keymap.set('n', '', 'j') +vim.keymap.set('n', '', 'h') +vim.keymap.set('n', '', 'l') + +vim.keymap.set('n', '', 'resize +' .. vertical_resize_step .. '') +vim.keymap.set('n', '', 'resize -' .. vertical_resize_step .. '') +vim.keymap.set('n', '', 'vertical resize -' .. horizontal_resize_step .. '') +vim.keymap.set('n', '', 'vertical resize +' .. horizontal_resize_step .. '') + +vim.keymap.set({'n', 'v'}, '', small_step .. 'k') +vim.keymap.set({'n', 'v'}, '', small_step .. 'j') +vim.keymap.set({'n', 'v'}, '', small_step .. '' .. small_step .. 'k') +vim.keymap.set({'n', 'v'}, '', small_step .. '' .. small_step .. 'j') +vim.keymap.set({'n', 'v'}, '', big_step .. 'lua center_cursor()') +vim.keymap.set({'n', 'v'}, '', big_step .. 'lua center_cursor()') +vim.keymap.set({'n', 'v'}, '', '^') +vim.keymap.set({'n', 'v'}, '', '$') +vim.keymap.set('n', 'zz', center_cursor) +vim.keymap.set('i', '', '' .. small_step .. 'k') +vim.keymap.set('i', '', '' .. small_step .. 'j') +vim.keymap.set('i', '', '' .. small_step .. '' .. small_step .. 'k') +vim.keymap.set('i', '', '' .. small_step .. '' .. small_step .. 'j') +vim.keymap.set('i', '', '' .. big_step .. 'lua center_cursor()') +vim.keymap.set('i', '', '' .. big_step .. 'lua center_cursor()') +vim.keymap.set('i', '', '^') +vim.keymap.set('i', '', '$') + +vim.keymap.set('i', '', '') +vim.keymap.set('i', '', '"_dw') + +vim.keymap.set('n', '', '"_dd') +vim.keymap.set('v', '', '"_d') +vim.keymap.set('n', '', 'mzk"_ddg`z') + +vim.keymap.set('n', '', 'call append(line("."), "")') +vim.keymap.set('i', '', 'O') + +vim.keymap.set({'n', 'i'}, '', 'm -2') +vim.keymap.set({'n', 'i'}, '', 'm +1') +vim.cmd [[ +xnoremap :m-2gv=gv +xnoremap :m'>+gv=gv +]] + +vim.keymap.set('v', '>', '>gv') +vim.keymap.set('v', '<', '') + +vim.keymap.set('n', '/', 'gcc', { remap = true }) +vim.keymap.set('v', '/', 'gcgv', { remap = true }) + +vim.keymap.set('n', 'gl', 'lua vim.diagnostic.open_float()') +vim.keymap.set('n', 'gj', 'lua vim.diagnostic.goto_next()') +vim.keymap.set('n', 'gk', 'lua vim.diagnostic.goto_prev()') + +vim.keymap.set('n', 'la', 'gra') +vim.keymap.set('n', 'lf', 'lua vim.lsp.buf.format({ async = true })') +vim.keymap.set('n', 'ln', 'lua vim.lsp.buf.rename()') +vim.keymap.set('n', 'lr', 'lua vim.lsp.buf.references()') + +for _, keymap in pairs(PLUGIN_KEYMAPS) do + keymap() +end diff --git a/lua/lsp.lua b/lua/lsp.lua new file mode 100644 index 0000000..c9630df --- /dev/null +++ b/lua/lsp.lua @@ -0,0 +1,11 @@ +local enable = vim.lsp.enable + +-- When calling `enable 'foo'`, there must be a given file in either: +-- * `~/.config/nvim/lsp/foo.lua` +-- * https://github.com/neovim/nvim-lspconfig/tree/master/lsp +-- you can then further configure them with `vim.lsp.config('foo'. {...})` + +enable 'lua_ls' +enable 'rust_analyzer' +enable 'ts_ls' +enable 'vue_ls' diff --git a/lua/plugin/autopairs.lua b/lua/plugin/autopairs.lua new file mode 100644 index 0000000..d19a89a --- /dev/null +++ b/lua/plugin/autopairs.lua @@ -0,0 +1,7 @@ +local M = { + 'windwp/nvim-autopairs', + event = 'InsertEnter', + config = true, +} + +return M diff --git a/lua/plugin/colorscheme.lua b/lua/plugin/colorscheme.lua new file mode 100644 index 0000000..9813ab7 --- /dev/null +++ b/lua/plugin/colorscheme.lua @@ -0,0 +1,11 @@ +local M = { + 'folke/tokyonight.nvim', + lazy = false, -- load colorscheme immediately + priority = 1000, +} + +M.config = function() + vim.cmd.colorscheme 'tokyonight-night' +end + +return M diff --git a/lua/plugin/lazy.lua b/lua/plugin/lazy.lua new file mode 100644 index 0000000..e457b49 --- /dev/null +++ b/lua/plugin/lazy.lua @@ -0,0 +1,18 @@ +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 + } +end +vim.opt.rtp:prepend(lazypath) + +require 'lazy'.setup(LAZY_PLUGIN_SPEC, { + change_detection = { + notify = false + } +}) diff --git a/lua/plugin/lspconfig.lua b/lua/plugin/lspconfig.lua new file mode 100644 index 0000000..4138a14 --- /dev/null +++ b/lua/plugin/lspconfig.lua @@ -0,0 +1,11 @@ +local M = { + 'neovim/nvim-lspconfig', + dependencies = { + { + 'mason-org/mason-lspconfig.nvim', + config = function() end, + }, + }, +} + +return M diff --git a/lua/plugin/lspkind.lua b/lua/plugin/lspkind.lua new file mode 100644 index 0000000..bd9a515 --- /dev/null +++ b/lua/plugin/lspkind.lua @@ -0,0 +1,6 @@ +local M = { + 'onsails/lspkind.nvim', + config = true, +} + +return M diff --git a/lua/plugin/mason.lua b/lua/plugin/mason.lua new file mode 100644 index 0000000..d85c80a --- /dev/null +++ b/lua/plugin/mason.lua @@ -0,0 +1,14 @@ +local M = { + 'mason-org/mason.nvim', + opts = { + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + }, + }, + }, +} + +return M diff --git a/lua/plugin/nvim-cmp.lua b/lua/plugin/nvim-cmp.lua new file mode 100644 index 0000000..64f971e --- /dev/null +++ b/lua/plugin/nvim-cmp.lua @@ -0,0 +1,77 @@ +local M = { + 'hrsh7th/nvim-cmp', + dependencies = { + 'neovim/nvim-lspconfig', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + 'windwp/nvim-autopairs', + 'onsails/lspkind.nvim', + }, +} + +M.config = function() + local cmp = require 'cmp' + local cmp_autopairs = require 'nvim-autopairs.completion.cmp' + + cmp.setup { + window = { + completion = vim.tbl_deep_extend( + 'force', + cmp.config.window.bordered(), + { + winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None', + col_offset = -3, + side_padding = -0, + } + ), + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = { 'kind', 'abbr', 'menu' }, + format = function(entry, vim_item) + local kind = require 'lspkind'.cmp_format { + mode = 'symbol_text', + maxwidth = 50, + }(entry, vim_item) + local strings = vim.split(kind.kind, '%s', { trimempty = true }) + kind.kind = ' ' .. (strings[1] or '') .. ' ' + kind.menu = ' (' .. (strings[2] or '') .. ')' + return kind + end + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources( + { + { name = 'nvim_lsp' }, + }, + { + { name = 'buffer' }, + } + ), + preselect = cmp.PreselectMode.Item, + experimental = { + ghost_text = false, + }, + } + + cmp.event:on( + 'confirm_done', + cmp_autopairs.on_confirm_done() + ) +end + +return M diff --git a/lua/plugin/nvimtree-icons.lua b/lua/plugin/nvimtree-icons.lua new file mode 100644 index 0000000..0b59a3c --- /dev/null +++ b/lua/plugin/nvimtree-icons.lua @@ -0,0 +1,5 @@ +local M = { + 'nvim-tree/nvim-web-devicons' +} + +return M diff --git a/lua/plugin/nvimtree.lua b/lua/plugin/nvimtree.lua new file mode 100644 index 0000000..629093f --- /dev/null +++ b/lua/plugin/nvimtree.lua @@ -0,0 +1,33 @@ +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 +vim.g.termguicolors = true + +local M = { + 'nvim-tree/nvim-tree.lua', + opts = { + view = { + side = 'left', + width = 40, + }, + actions = { + expand_all = { + max_folder_discovery = 1000, + exclude = { '.git', 'target', 'build', 'node_modules' }, + }, + }, + update_focused_file = { + enable = true, + }, + diagnostics = { + enable = true, + show_on_dirs = true, + show_on_open_dirs = true, + }, + }, +} + +M.keymap = function() + vim.keymap.set('n', 'e', 'NvimTreeFindFileToggle') +end + +return M diff --git a/lua/plugin/telescope.lua b/lua/plugin/telescope.lua new file mode 100644 index 0000000..307a314 --- /dev/null +++ b/lua/plugin/telescope.lua @@ -0,0 +1,74 @@ +local M = { + 'nvim-telescope/telescope.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + lazy = true, + cmd = 'Telescope', +} + +function M.config() + local actions = require 'telescope.actions' + require 'telescope'.setup { + defaults = { + path_display = { 'filename_first' }, + layout_strategy = 'horizontal', + layout_config = { + prompt_position = 'top', + width = function(_, max_columns, _) + return math.min(max_columns, 180) + end, + horizontal = { + preview_width = 0.5, + }, + }, + sorting_strategy = 'ascending', + scroll_strategy = 'limit', + mappings = { + i = {}, + n = { + [''] = actions.close, + ['q'] = actions.close, + }, + }, + }, + pickers = { + find_files = { + hidden = true, + }, + live_grep = { + disable_coordinates = true, + }, + grep_string = { + disable_coordinates = true, + }, + }, + extensions = { + file_browser = { + git_icons = { + added = "A", + changed = "M", + copied = "C", + deleted = "D", + renamed = "R", + unmerged = "U", + untracked = "?", + }, + }, + }, + } +end + +M.keymap = function() + local builtin = require 'telescope.builtin' + vim.keymap.set('n', 'f', builtin.find_files) + vim.keymap.set('n', 'r', builtin.resume) + vim.keymap.set('n', '', function() builtin.grep_string { word_match = '-w' } end) + vim.keymap.set('v', '', builtin.grep_string) + vim.keymap.set('n', 'st', builtin.live_grep) + vim.keymap.set('n', 'o', builtin.lsp_document_symbols) + vim.keymap.set('n', 'p', builtin.lsp_workspace_symbols) + vim.keymap.set('n', 'gb', builtin.git_branches) + vim.keymap.set('n', 'gc', builtin.git_commits) + vim.keymap.set('n', '', builtin.git_status) +end + +return M diff --git a/lua/plugin/toggleterm.lua b/lua/plugin/toggleterm.lua new file mode 100644 index 0000000..f1c3052 --- /dev/null +++ b/lua/plugin/toggleterm.lua @@ -0,0 +1,12 @@ +local M = { + 'akinsho/toggleterm.nvim', + config = true +} + +M.keymap = function() + for i = 1, 9 do + vim.keymap.set({'n', 't'}, '', '' .. i .. 'ToggleTerm direction=float name=term-' .. i .. '') + end +end + +return M diff --git a/lua/plugin/treesitter.lua b/lua/plugin/treesitter.lua new file mode 100644 index 0000000..c17f652 --- /dev/null +++ b/lua/plugin/treesitter.lua @@ -0,0 +1,16 @@ +local M = { + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', -- parsers must be kept up to date with the plugin + lazy = false, -- enable highlighting instantly + opts = { + ensure_installed = { + 'bash' + }, + sync_install = true, + auto_install = true, + highlight = { enable = true }, + indent = { enable = true }, + }, +} + +return M diff --git a/lua/scripts.lua b/lua/scripts.lua new file mode 100644 index 0000000..3b0d22d --- /dev/null +++ b/lua/scripts.lua @@ -0,0 +1,8 @@ +function center_cursor() + local window_height = vim.api.nvim_win_get_height(0) + local half_height = math.floor(window_height / 2) + local first_line = vim.fn.line('w0') + local pos = vim.fn.getpos('.') + pos[2] = first_line + half_height + vim.fn.setpos('.', pos) +end diff --git a/lua/spec.lua b/lua/spec.lua new file mode 100644 index 0000000..6d36de5 --- /dev/null +++ b/lua/spec.lua @@ -0,0 +1,10 @@ +LAZY_PLUGIN_SPEC = {} +PLUGIN_KEYMAPS = {} + +function spec(item) + table.insert(LAZY_PLUGIN_SPEC, { import = item }) + local keymap = require(item).keymap + if keymap then + table.insert(PLUGIN_KEYMAPS, keymap) + end +end