diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 00000000..db2957d0 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,5 @@ +require('editor') +require('plugins') +require('color') +require('filetype') +require('lsp') diff --git a/nvim/init.vim b/nvim/init.vim deleted file mode 100644 index 22221e13..00000000 --- a/nvim/init.vim +++ /dev/null @@ -1,7 +0,0 @@ -source $XDG_CONFIG_HOME/nvim/plugins.vim -source $XDG_CONFIG_HOME/nvim/plugins_config.vim -source $XDG_CONFIG_HOME/nvim/editor.vim -source $XDG_CONFIG_HOME/nvim/color.vim -source $XDG_CONFIG_HOME/nvim/language.vim -source $XDG_CONFIG_HOME/nvim/lsp.vim -source $XDG_CONFIG_HOME/nvim/neovim.vim diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 00000000..8b22dfe0 --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,19 @@ +{ + "bufferline.nvim": { "branch": "main", "commit": "6ecd37e0fa8b156099daedd2191130e083fb1490" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "copilot.vim": { "branch": "release", "commit": "2c31989063b145830d5f0bea8ab529d2aef2427b" }, + "fzf-lua": { "branch": "main", "commit": "6589bdd872385d120a1eb3cb85e5d15d37621c1d" }, + "lazy.nvim": { "branch": "main", "commit": "16603c6917435d8446f7357cb61095138a417085" }, + "lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" }, + "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, + "nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" }, + "nvim-cmp": { "branch": "main", "commit": "51260c02a8ffded8e16162dcf41a23ec90cfba62" }, + "nvim-lspconfig": { "branch": "master", "commit": "cb49a4cd622d7ed775c31561bb8aa6a50712d6b9" }, + "nvim-tree.lua": { "branch": "master", "commit": "78a9ca5ed6557f29cd0ce203df44213e54bfabb9" }, + "nvim-web-devicons": { "branch": "master", "commit": "5de460ca7595806044eced31e3c36c159a493857" }, + "vim-kalisi": { "branch": "master", "commit": "8d076bd7989fcb14f995a0d4065a8f16cd00d4d6" }, + "vim-vsnip": { "branch": "master", "commit": "be277461265f1e5c7db470aa479f30956597ea9e" } +} \ No newline at end of file diff --git a/nvim/lua/color.lua b/nvim/lua/color.lua new file mode 100644 index 00000000..1faaee92 --- /dev/null +++ b/nvim/lua/color.lua @@ -0,0 +1,77 @@ +vim.cmd("syntax on") +vim.api.nvim_create_augroup('BgColor', {}) +vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, { + pattern = {'*'}, + group = 'BgColor', + command = 'highlight Normal ctermbg=none' +}) +vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, { + pattern = {'*'}, + group = 'BgColor', + command = 'highlight LineNr ctermbg=none' +}) +vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, { + pattern = {'*'}, + group = 'BgColor', + command = 'highlight SignColumn ctermbg=none' +}) +vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, { + pattern = {'*'}, + group = 'BgColor', + command = 'highlight VertSplit ctermbg=none' +}) +vim.api.nvim_create_autocmd({'VimEnter', 'ColorScheme'}, { + pattern = {'*'}, + group = 'BgColor', + command = 'highlight NonText ctermbg=none' +}) + + +vim.cmd("colorscheme kalisi") +vim.opt.background = "dark" + +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} +} + +local bufferline = require('bufferline') +bufferline.setup{} +vim.api.nvim_set_keymap('n', '', ':BufferLineCycleNext', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', ':BufferLineCyclePrev', { noremap = true, silent = true }) diff --git a/nvim/lua/editor.lua b/nvim/lua/editor.lua new file mode 100644 index 00000000..3ea26698 --- /dev/null +++ b/nvim/lua/editor.lua @@ -0,0 +1,24 @@ +vim.opt.number = true +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.expandtab = true +vim.opt.shiftwidth = 4 +vim.opt.smartindent = true +vim.opt.autoindent = true +vim.opt.list = true +vim.opt.listchars= 'tab:>-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%' +vim.opt.hidden = true +vim.opt.history = 50 +vim.opt.virtualedit = "block" +vim.opt.whichwrap = "b,s,h,l,<,>,[,]" +vim.opt.backspace = "indent,eol,start" +vim.opt.wildmenu = true +vim.opt.clipboard = "unnamed" +vim.opt.pumheight = 10 +vim.opt.showmode = true +vim.opt.wildmode = "list:full" +vim.opt.encoding = "utf-8" +vim.opt.helplang = "en" +vim.opt.cursorline = true +vim.opt.foldmethod = "syntax" +vim.opt.foldlevel = 100 diff --git a/nvim/lua/filetype.lua b/nvim/lua/filetype.lua new file mode 100644 index 00000000..9991ea3a --- /dev/null +++ b/nvim/lua/filetype.lua @@ -0,0 +1,23 @@ +vim.api.nvim_create_augroup('FileTypeIndent', {}) +vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, { + pattern = {'*.rs', }, + group = 'FileTypeIndent', + command = 'setlocal tabstop=4 softtabstop=4 shiftwidth=4' +}) +vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, { + pattern = {'*.lua', '*.yaml', '*.yml', '*.html', '*.css', '*.js', '*.jsx', '*.ts', '*.tsx'}, + group = 'FileTypeIndent', + command = 'setlocal tabstop=2 softtabstop=2 shiftwidth=2' +}) +vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, { + pattern = {'*.go'}, + group = 'FileTypeIndent', + command = 'setlocal tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab' +}) + +vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, { + pattern = {'*.md',}, + group = 'FileTypeIndent', + command = 'setlocal tabstop=2 softtabstop=2 shiftwidth=2' +}) + diff --git a/nvim/lua/lsp.lua b/nvim/lua/lsp.lua new file mode 100644 index 00000000..2336012f --- /dev/null +++ b/nvim/lua/lsp.lua @@ -0,0 +1,120 @@ + +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, +}) + + +local cmp = require ("cmp") +cmp.setup({ + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + window = { + -- completion = { + -- autocomplete = true, + -- }, + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + }), + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ select = true }), + }), +}) + + +local capabilities = require("cmp_nvim_lsp").default_capabilities() +local lspconfig = require('lspconfig') + +lspconfig.rust_analyzer.setup { + capabilities = capabilities, + flags = { + exit_timeout = 0, + }, + filetypes = {'rust'}, + settings = { + ['rust-analyzer'] = { + cargo = { + buildScripts = { + enable = true, + }, + }, + checkOnSave = { + allFeatures = true, + command = 'clippy', + }, + procMacro = { + enable = true, + }, + }, + } +} + +lspconfig.gopls.setup { + capabilities = capabilities, + cmd = {"gopls", "serve", "-rpc.trace"}, + filetypes = {'go'}, + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = true, + gofumpt = true, + }, + }, +} + + +vim.cmd [[autocmd BufWritePre *.go lua vim.lsp.buf.format({ async = true })]] +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.go', + callback = function() + vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true }) + end +}) + +-- probobuf +lspconfig.clangd.setup{ + capabilities = capabilities, +} + +-- GitHub Copilot +-- vim.keymap.set('i', '', 'copilot#Accept("")', { +-- expr = true, +-- replace_keycodes = false +-- }) +-- vim.g.copilot_no_tab_map = true diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua new file mode 100644 index 00000000..fbc280a0 --- /dev/null +++ b/nvim/lua/plugins.lua @@ -0,0 +1,94 @@ +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) + +local lazy = require('lazy') + +lazy.setup({ + { + "nvim-tree/nvim-tree.lua", + version = "*", + lazy = false, + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + config = function() + local function my_on_attach(bufnr) + local api = require "nvim-tree.api" + + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + -- default mappings + api.config.mappings.default_on_attach(bufnr) + + -- custom mappings + vim.keymap.set('n', '', api.tree.change_root_to_parent, opts('Up')) + vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help')) + vim.keymap.set('n', '', api.tree.toggle, opts('Toggle')) + end + require("nvim-tree").setup { + on_attach = my_on_attach, + } + end, + }, + {"freeo/vim-kalisi"}, + { + "ibhagwan/fzf-lua", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("fzf-lua").setup({}) + end + }, + -- completion and snippet + {"neovim/nvim-lspconfig"}, + {"hrsh7th/nvim-cmp"}, + {"hrsh7th/cmp-path"}, + {"hrsh7th/cmp-buffer"}, + {"hrsh7th/cmp-cmdline"}, + {"hrsh7th/cmp-nvim-lsp"}, + {"hrsh7th/vim-vsnip"}, + -- lualine + {'nvim-lualine/lualine.nvim'}, + { + 'akinsho/bufferline.nvim', + version = "*", + dependencies = 'nvim-tree/nvim-web-devicons', + }, + { + 'windwp/nvim-autopairs', + event = "InsertEnter", + opts = {} + }, + { + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + ft = { "markdown" }, + build = function() vim.fn["mkdp#util#install"]() end, + }, + -- copilot + { 'github/copilot.vim' } +}) + + +-- nvim-tree global keymap +local api = require "nvim-tree.api" +vim.keymap.set('n', '', api.tree.toggle) + +-- fzf-lua +vim.keymap.set("n", "", + "lua require('fzf-lua').files()", { silent = true }) +vim.keymap.set("n", "", + "lua require('fzf-lua').git_files()", { silent = true }) +vim.keymap.set("n", "", + "lua require('fzf-lua').live_grep()", { silent = true })