From fd509a515ba74589a7370edd7efbb075ec32188f Mon Sep 17 00:00:00 2001 From: CRy386i Date: Wed, 29 May 2024 16:20:25 +0300 Subject: [PATCH] init commit --- init.lua | 5 + lazy-lock.json | 22 ++++ lua/base/other.lua | 37 ++++++ lua/base/search.lua | 25 ++++ lua/base/tabs.lua | 24 ++++ lua/keys/alias.lua | 35 ++++++ lua/keys/main.lua | 7 ++ lua/plugins/lazy.lua | 264 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 419 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/base/other.lua create mode 100644 lua/base/search.lua create mode 100644 lua/base/tabs.lua create mode 100644 lua/keys/alias.lua create mode 100644 lua/keys/main.lua create mode 100644 lua/plugins/lazy.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..2fd22c6 --- /dev/null +++ b/init.lua @@ -0,0 +1,5 @@ +require("plugins/lazy") +require("base/search") +require("base/tabs") +require("base/other") +require("keys/main") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..e092218 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,22 @@ +{ + "aerial.nvim": { "branch": "master", "commit": "24ebacab5821107c50f628e8e7774f105c08fe9b" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "3d8912ebeb56e5ae08ef0906e3a54de1c66b92f1" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp-vsnip": { "branch": "main", "commit": "989a8a73c44e926199bfd05fa7a516d51f2d2752" }, + "gruvbox": { "branch": "master", "commit": "f1ecde848f0cdba877acb0c740320568252cc482" }, + "lazy.nvim": { "branch": "main", "commit": "31ddbea7c10b6920c9077b66c97951ca8682d5c8" }, + "nvim-cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" }, + "nvim-lspconfig": { "branch": "master", "commit": "b3014f2209503944f2714cf27c95591433a0c7d8" }, + "nvim-treesitter": { "branch": "master", "commit": "ef267f0c285928ea3a0d3362a260a0728fd4a146" }, + "plenary.nvim": { "branch": "master", "commit": "8aad4396840be7fc42896e3011751b7609ca4119" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, + "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, + "tokyonight.nvim": { "branch": "main", "commit": "9bf9ec53d5e87b025e2404069b71e7ebdc3a13e5" }, + "vim-commentary": { "branch": "master", "commit": "c4b8f52cbb7142ec239494e5a2c4a512f92c4d07" }, + "vim-fugitive": { "branch": "master", "commit": "dac8e5c2d85926df92672bf2afb4fc48656d96c7" }, + "vim-polyglot": { "branch": "master", "commit": "bc8a81d3592dab86334f27d1d43c080ebf680d42" }, + "vim-vsnip": { "branch": "master", "commit": "02a8e79295c9733434aab4e0e2b8c4b7cea9f3a9" } +} \ No newline at end of file diff --git a/lua/base/other.lua b/lua/base/other.lua new file mode 100644 index 0000000..15c75fa --- /dev/null +++ b/lua/base/other.lua @@ -0,0 +1,37 @@ +local opt = vim.opt +local g = vim.g + +-- [[ Set panels ]] -- +-- Vertical splits set right-side +-- By defalut, the panels in Neovim are placed according to the location of the current panel. +-- This setting will help us to keep the panels in order. +opt.splitright = true + +-- Horizontal splits become below +opt.splitbelow = true + +-- Use the system clipboard +opt.clipboard = "unnamedplus" + +-- Disable file addtion at the end +opt.fixeol = false + +-- Autocomplite (buil-in Neovim) +opt.completeopt = "menuone,noselect" + +-- Not autocomment new lines when moving to a new line + +vim.cmd [[autocmd BufEnter * set fo-=c fo-=r fo-=o]] + +-- Set encoding file and show terminal to UTF-8 + +opt.encoding = "utf-8" +opt.fileencoding = "utf-8" +opt.ff = "unix" + +-- Also work under ru +opt.langmap = "ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz" + +opt.colorcolumn = "120" + +opt.mouse = "" diff --git a/lua/base/search.lua b/lua/base/search.lua new file mode 100644 index 0000000..dff771c --- /dev/null +++ b/lua/base/search.lua @@ -0,0 +1,25 @@ +-- Set value for vim.opt and vim.g +local opt = vim.opt +local g = vim.g + + +-- [[ Serach ]] -- +-- Ignore case when searching +-- if we now type in "IGNORE", it will also find "ignore" +opt.ignorecase = true + +-- Don't ignore case searching if there are characters in upper case +-- If we now type "Ignore", it will only search for "Ignore" +opt.smartcase = true + +-- highlight found text +opt.showmatch = true +opt.incsearch = true +opt.hlsearch = true + +-- Show line numbers relatively +opt.number = true +opt.relativenumber = true + +-- Replace all by-default +opt.gdefault = true diff --git a/lua/base/tabs.lua b/lua/base/tabs.lua new file mode 100644 index 0000000..2cc434a --- /dev/null +++ b/lua/base/tabs.lua @@ -0,0 +1,24 @@ +local opt = vim.opt +local g = vim.g + +-- [[ set tabs ]] -- +-- Set the numbers of whitespace characters when shifting with "<" or ">". +-- In fact, in spite of expandtab, the terminal still displays whitespace charaters, +-- so let's set the number of whitespace characters for ones press of these buttons. +opt.shiftwidth = 2 + +-- one tab == two whitespace characters in new line. +-- Pressing will insert tabs. Tabs are drawn as whitespace. +-- that's why we have to set that each tab on a new line is two whitespace. +opt.tabstop = 2 + +-- Adjust new line to the previous indentation +opt.smartindent = true + +opt.expandtab = false +opt.smarttab = true +opt.scrolloff = 8 + +-- Show unprintable +opt.list = true +opt.listchars = {tab = '⁞ ', eol = '¬', trail = '·'} diff --git a/lua/keys/alias.lua b/lua/keys/alias.lua new file mode 100644 index 0000000..c3c49c3 --- /dev/null +++ b/lua/keys/alias.lua @@ -0,0 +1,35 @@ +-- Set alias for quick-access to method setting hotkey +local map = vim.api.nvim_set_keymap + +--[[ +Method for setting hotkey (normal) looks like this: +key - {string} String with hotkey +command - {string} Command (LUL) +]]-- + +function nm(key, command) + map("n", key, command, {noremap = true}) +end + +--[[ +Method for setting hotkey (input) +]]-- + +function im(key, command) + map("i", key, command, {noremap = true}) +end + +--[[ +Method for setting hotkey (visual) +]]-- + +function vm(key, command) + map("v", key, command, {noremap = true}) +end + +--[[ +Method for setting hotkey (terminal) +]]-- +function tm(key, command) + map("t", key, command, {noremap = true}) +end diff --git a/lua/keys/main.lua b/lua/keys/main.lua new file mode 100644 index 0000000..f4b2253 --- /dev/null +++ b/lua/keys/main.lua @@ -0,0 +1,7 @@ +require("keys/alias") + +-- Set addtional hotkey for disable mod +im("", "") +vm("", "") +nm("", "") +tm("", "") diff --git a/lua/plugins/lazy.lua b/lua/plugins/lazy.lua new file mode 100644 index 0000000..0560524 --- /dev/null +++ b/lua/plugins/lazy.lua @@ -0,0 +1,264 @@ +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) + +-- Install plugins using lazy +require('lazy').setup({ + { 'tpope/vim-commentary', }, + { 'tpope/vim-fugitive', }, + { 'sheerun/vim-polyglot', + init = function() + -- vim-polyglot confusingly registers *.comp both for perl and for glsl + vim.api.nvim_set_var('polyglot_disabled', {'perl'}) + end, + }, + { + 'morhetz/gruvbox', + lazy = false, + priority = 1000, + config = function() + vim.opt.background = 'dark' + vim.g.gruvbox_italic = 1 + vim.cmd([[colorscheme gruvbox]]) + end, + }, + { + "folke/tokyonight.nvim", + lazy = true, + -- config = function() + -- -- load the colorscheme here + -- vim.cmd([[colorscheme tokyonight]]) + -- end, + }, + { 'nvim-telescope/telescope-fzf-native.nvim', + build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' + }, + { + 'nvim-telescope/telescope.nvim', tag = '0.1.6', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + local telescope = require('telescope') + + telescope.setup{ + -- defaults = { + -- } + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + -- the default case_mode is "smart_case" + } + } + } + + --telescope.load_extension('fzy') + telescope.load_extension('fzf') + + local builtin = require('telescope.builtin') + vim.keymap.set('n', '', builtin.find_files, {}) + vim.keymap.set('n', 'ft', builtin.treesitter, {}) + vim.keymap.set('n', 'fg', builtin.live_grep, {}) + vim.keymap.set('n', 'fb', builtin.buffers, {}) + vim.keymap.set('n', 'fh', builtin.help_tags, {}) + end + }, + { "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup { + ensure_installed = { "c", "cpp", "pascal", "lua", "glsl", "yaml" }, + highlight = { enable = true, } + } + end + }, + { + 'neovim/nvim-lspconfig', + config = function() + -- Setup language servers. + local lspconfig = require('lspconfig') + lspconfig.clangd.setup {} + lspconfig.neocmake.setup {} + + -- Global mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + vim.keymap.set('n', 'e', vim.diagnostic.open_float) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + + -- Use LspAttach autocommand to only map the following keys + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, + }) + end + }, + { + 'hrsh7th/nvim-cmp', + dependencies = { + 'neovim/nvim-lspconfig', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + 'hrsh7th/cmp-vsnip', + 'hrsh7th/vim-vsnip', + 'hrsh7th/cmp-nvim-lsp-signature-help', + }, + config = function() + local cmp = require'cmp' + cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = 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 = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + { name = 'nvim_lsp_signature_help' }, + }) + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). + }, { + { name = 'buffer' }, + }) + }) + + cmp.setup.filetype('cmake', { + sources = cmp.config.sources({ + { name = 'cmake', "CMakeLists.txt" }, + }, { + { name = 'buffer' }, + }) + }) + + -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + + -- Set up lspconfig. + local capabilities = require('cmp_nvim_lsp').default_capabilities() + -- TODO Replace with each lsp server you've enabled. + require('lspconfig')['clangd'].setup { + capabilities = capabilities + } + end, + }, + { + 'stevearc/aerial.nvim', + dependencies = { 'neovim/nvim-lspconfig', }, + config = function() + require('aerial').setup({ + -- optionally use on_attach to set keymaps when aerial has attached to a buffer + on_attach = function(bufnr) + -- Jump forwards/backwards with '{' and '}' + vim.keymap.set('n', '{', 'AerialPrev', {buffer = bufnr}) + vim.keymap.set('n', '}', 'AerialNext', {buffer = bufnr}) + end + }) + -- You probably also want to set a keymap to toggle aerial + vim.keymap.set('n', '', 'AerialToggle!') + end, + } +}) + +vim.filetype.add({ + extension = { + vp = 'glsl', + fp = 'glsl', + gp = 'glsl', + vs = 'glsl', + fs = 'glsl', + gs = 'glsl', + tcs = 'glsl', + tes = 'glsl', + cs = 'glsl', + vert = 'glsl', + frag = 'glsl', + geom = 'glsl', + tess = 'glsl', + shd = 'glsl', + gls = 'glsl', + glsl = 'glsl', + rgen = 'glsl', + comp = 'glsl', + rchit = 'glsl', + rahit = 'glsl', + rmiss = 'glsl', + } +})