From 99f27a707614e5681fc03d8a949f4e13e8eae698 Mon Sep 17 00:00:00 2001 From: JiuYu <1992817771@qq.com> Date: Sat, 21 Sep 2024 21:58:26 +0800 Subject: [PATCH] first commit --- README.md | 11 ---- init.lua | 20 ++++++ lua/configs/autopairs.lua | 5 ++ lua/configs/bufferline.lua | 121 ++++++++++++++++++++++++++++++++++ lua/configs/cmp.lua | 30 +++++++++ lua/configs/fidget.lua | 57 ++++++++++++++++ lua/configs/lsp.lua | 8 +++ lua/configs/lsp_signature.lua | 17 +++++ lua/configs/lualine.lua | 46 +++++++++++++ lua/configs/mason-lsp.lua | 13 ++++ lua/configs/mason.lua | 19 ++++++ lua/configs/neo-tree.lua | 22 +++++++ lua/configs/notify.lua | 20 ++++++ lua/configs/null-ls.lua | 13 ++++ lua/configs/toggleterm.lua | 11 ++++ lua/configs/treesitter.lua | 15 +++++ lua/maps.lua | 19 ++++++ lua/packer-plugins.lua | 75 +++++++++++++++++++++ lua/settings.lua | 66 +++++++++++++++++++ 19 files changed, 577 insertions(+), 11 deletions(-) delete mode 100644 README.md create mode 100644 init.lua create mode 100644 lua/configs/autopairs.lua create mode 100644 lua/configs/bufferline.lua create mode 100644 lua/configs/cmp.lua create mode 100644 lua/configs/fidget.lua create mode 100644 lua/configs/lsp.lua create mode 100644 lua/configs/lsp_signature.lua create mode 100644 lua/configs/lualine.lua create mode 100644 lua/configs/mason-lsp.lua create mode 100644 lua/configs/mason.lua create mode 100644 lua/configs/neo-tree.lua create mode 100644 lua/configs/notify.lua create mode 100644 lua/configs/null-ls.lua create mode 100644 lua/configs/toggleterm.lua create mode 100644 lua/configs/treesitter.lua create mode 100644 lua/maps.lua create mode 100644 lua/packer-plugins.lua create mode 100644 lua/settings.lua diff --git a/README.md b/README.md deleted file mode 100644 index 1459320..0000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# clone -```shell -git clone https://github.com/JiuYu77/vim-conf.git -``` - -# Installation - -```shell -git clone -b vim https://github.com/JiuYu77/vim-conf.git ~/ -``` - diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..469a120 --- /dev/null +++ b/init.lua @@ -0,0 +1,20 @@ +require("settings") +require("packer-plugins") +require("maps") + +require("configs.lualine") -- 启动状态栏 +require("configs.bufferline") -- 启动标签栏/标签页 +require("configs.neo-tree") -- 目录树 +require("configs.toggleterm") -- Terminal +require("configs.autopairs") -- autopairs +require("configs.lsp") -- lsp +require("configs.mason") -- mason +require("configs.mason-lsp") -- mason-lspconfig + +require("configs.notify") -- notify + +require("configs.fidget") -- fidget +require("configs.cmp") -- cmp +require("configs.lsp_signature") -- lsp_signature +require("configs.treesitter") -- treesitter +--require("configs.null-ls") -- null-ls diff --git a/lua/configs/autopairs.lua b/lua/configs/autopairs.lua new file mode 100644 index 0000000..a966aff --- /dev/null +++ b/lua/configs/autopairs.lua @@ -0,0 +1,5 @@ +local status, autopairs = pcall(require, "nvim-autopairs") + +if status then + autopairs.setup() +end diff --git a/lua/configs/bufferline.lua b/lua/configs/bufferline.lua new file mode 100644 index 0000000..8c17640 --- /dev/null +++ b/lua/configs/bufferline.lua @@ -0,0 +1,121 @@ +local status, bufferline= pcall(require, 'bufferline') + +if not status then + return +end +bufferline.setup { +options = { + mode = "buffers", -- set to "tabs" to only show tabpages instead + --style_preset = bufferline.style_preset.default, -- or bufferline.style_preset.minimal, + --themable = true | false, -- allows highlight groups to be overriden i.e. sets highlights as default + --numbers = "none" | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string, + numbers = "buffer_id", -- 打开文件的buffer编号 + close_command = "bdelete! %d", -- can be a string | function, | false see "Mouse actions" + right_mouse_command = "bdelete! %d", -- can be a string | function | false, see "Mouse actions" + left_mouse_command = "buffer %d", -- can be a string | function, | false see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, | false see "Mouse actions" + indicator = { + icon = '▎', -- this should be omitted if indicator style is not 'icon' + --style = 'icon' | 'underline' | 'none', + }, + buffer_close_icon = '󰅖', + modified_icon = '●', + close_icon = '', + left_trunc_marker = '', + right_trunc_marker = '', + --- name_formatter can be used to change the buffer's label in the bufferline. + --- Please note some names can/will break the + --- bufferline so use this at your discretion knowing that it has + --- some limitations that will *NOT* be fixed. + name_formatter = function(buf) -- buf contains: + -- name | str | the basename of the active file + -- path | str | the full path of the active file + -- bufnr (buffer only) | int | the number of the active buffer + -- buffers (tabs only) | table(int) | the numbers of the buffers in the tab + -- tabnr (tabs only) | int | the "handle" of the tab, can be converted to its ordinal number using: `vim.api.nvim_tabpage_get_number(buf.tabnr)` + end, + max_name_length = 18, + max_prefix_length = 15, -- prefix used when a buffer is de-duplicated + truncate_names = true, -- whether or not tab names should be truncated + tab_size = 18, + --diagnostics = false | "nvim_lsp" | "coc", + diagnostics = "nvim_lsp", + diagnostics_update_in_insert = false, + -- The diagnostics indicator can be set to nil to keep the buffer name highlight but delete the highlighting + diagnostics_indicator = function(count, level, diagnostics_dict, context) + return "("..count..")" + end, + -- NOTE: this will be called a lot so don't do any heavy processing here + custom_filter = function(buf_number, buf_numbers) + -- filter out filetypes you don't want to see + if vim.bo[buf_number].filetype ~= "" then + return true + end + -- filter out by buffer name + if vim.fn.bufname(buf_number) ~= "" then + return true + end + -- filter out based on arbitrary rules + -- e.g. filter out vim wiki buffer from tabline in your work repo + if vim.fn.getcwd() == "" and vim.bo[buf_number].filetype ~= "wiki" then + return true + end + -- filter out by it's index number in list (don't show first buffer) + if buf_numbers[1] ~= buf_number then + return true + end + end, + offsets = { + { + --filetype = "NvimTree", + filetype = "neo-tree", -- 让出文件树的位置 + --text = "File Explorer" | function , + text = "File Explorer", + --text_align = "left" | "center" | "right" -- 文件名对齐方式 + text_align = "left", + --separator = true + } + }, + --color_icons = true | false, -- whether or not to add the filetype icon highlights + color_icons = true, --彩色图标 + get_element_icon = function(element) + -- element consists of {filetype: string, path: string, extension: string, directory: string} + -- This can be used to change how bufferline fetches the icon + -- for an element e.g. a buffer or a tab. + -- e.g. + local icon, hl = require('nvim-web-devicons').get_icon_by_filetype(element.filetype, { default = false }) + return icon, hl + -- or + ----local custom_map = {my_thing_ft: {icon = "my_thing_icon", hl}} + ----return custom_map[element.filetype] + end, + --show_buffer_icons = true | false, -- disable filetype icons for buffers + show_buffer_icons = true, + --show_buffer_close_icons = true | false, + show_buffer_close_icons = true, + --show_close_icon = true | false, + show_close_icon = true, + --show_tab_indicators = true | false, + show_tab_indicators = true, + --show_duplicate_prefix = true | false, -- whether to show duplicate buffer prefix + persist_buffer_sort = true, -- whether or not custom sorted buffers should persist + move_wraps_at_ends = false, -- whether or not the move command "wraps" at the first or last position + -- can also be a table containing 2 custom separators + -- [focused and unfocused]. eg: { '|', '|' } + --separator_style = "slant" | "slope" | "thick" | "thin" | { 'any', 'any' }, + separator_style = "thin", + --enforce_regular_tabs = false | true, + enforce_regular_tabs = false, + --always_show_bufferline = true | false, + always_show_bufferline = true, + hover = { + enabled = true, + delay = 200, + reveal = {'close'} + }, + --[[sort_by = 'insert_after_current' |'insert_at_end' | 'id' | 'extension' | 'relative_directory' | 'directory' | 'tabs' | function(buffer_a, buffer_b) + -- add custom logic + return buffer_a.modified > buffer_b.modified + end]] + } +} diff --git a/lua/configs/cmp.lua b/lua/configs/cmp.lua new file mode 100644 index 0000000..b18fc49 --- /dev/null +++ b/lua/configs/cmp.lua @@ -0,0 +1,30 @@ +local status, cmp = pcall(require, "cmp") + +if not status then -- The plugin is not existed + return +end + +cmp.setup({ + 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 }), + }), + 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' }, + }), + +}) diff --git a/lua/configs/fidget.lua b/lua/configs/fidget.lua new file mode 100644 index 0000000..fab895f --- /dev/null +++ b/lua/configs/fidget.lua @@ -0,0 +1,57 @@ +local status, fidget = pcall(require, "fidget") + +if not status then -- The plugin is not existed + return +end + +fidget.setup{ + text = { + spinner = "pipe", -- animation shown when tasks are ongoing + done = "✔", -- character shown when all tasks are complete + commenced = "Started", -- message shown when task starts + completed = "Completed", -- message shown when task completes + }, + align = { + bottom = true, -- align fidgets along bottom edge of buffer + right = true, -- align fidgets along right edge of buffer + }, + timer = { + spinner_rate = 125, -- frame rate of spinner animation, in ms + fidget_decay = 2000, -- how long to keep around empty fidget, in ms + task_decay = 1000, -- how long to keep around completed task, in ms + }, + window = { + relative = "win", + blend = 100, + zindex = 200, + border = "none" + }, + fmt = { + max_messages = 2, -- The maximum number of messages stacked at any give time + leftpad = true, -- right-justify text in fidget box + stack_upwards = true, -- list of tasks grows upwards + max_width = 0, -- maximum width of the fidget box + fidget = -- function to format fidget title + function(fidget_name, spinner) + return string.format("%s %s", spinner, fidget_name) + end, + task = -- function to format each task line + function(task_name, message, percentage) + return string.format( + "%s%s [%s]", + message, + percentage and string.format(" (%s%%)", percentage) or "", + task_name + ) + end, + }, + --[[sources = { -- Sources to configure + * = { -- Name of source + ignore = false, -- Ignore notifications from this source + }, + },]] + debug = { + logging = false, -- whether to enable logging, for debugging + strict = false, -- whether to interpret LSP strictly + }, +} diff --git a/lua/configs/lsp.lua b/lua/configs/lsp.lua new file mode 100644 index 0000000..a9331ad --- /dev/null +++ b/lua/configs/lsp.lua @@ -0,0 +1,8 @@ +local status, lspconfig = pcall(require, "lspconfig") + +if not status then -- The plugin is not existed + return +end + +lspconfig.clangd.setup{} +lspconfig.pyright.setup{} diff --git a/lua/configs/lsp_signature.lua b/lua/configs/lsp_signature.lua new file mode 100644 index 0000000..f6235f4 --- /dev/null +++ b/lua/configs/lsp_signature.lua @@ -0,0 +1,17 @@ +local status, lsp_signature = pcall(require, "lsp_signature") + +if not status then -- The plugin is not existed + return +end + +--require'lspconfig'.gopls.setup{} + +lsp_signature.setup({ + wrap = true, + floating_window = true, + floating_window_above_cur_line = true, + bind = true, -- This is mandatory, otherwise border config won't get registered. + handler_opts = { + border = "rounded" + } +}) diff --git a/lua/configs/lualine.lua b/lua/configs/lualine.lua new file mode 100644 index 0000000..9bb01d9 --- /dev/null +++ b/lua/configs/lualine.lua @@ -0,0 +1,46 @@ +local status, lualine = pcall(require, 'lualine') + +if not status then + return +end + +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 = {} +} diff --git a/lua/configs/mason-lsp.lua b/lua/configs/mason-lsp.lua new file mode 100644 index 0000000..b831d72 --- /dev/null +++ b/lua/configs/mason-lsp.lua @@ -0,0 +1,13 @@ +local status, mason_lsp = pcall(require, "mason-lspconfig") + +if not status then -- The plugin is not existed + return +end + +mason_lsp.setup({ + --automatic_installation = false, + ensure_installed = { + "clangd", + "pyright", + } +}) diff --git a/lua/configs/mason.lua b/lua/configs/mason.lua new file mode 100644 index 0000000..ff9a78e --- /dev/null +++ b/lua/configs/mason.lua @@ -0,0 +1,19 @@ +local status, mason = pcall(require, "mason") + +if not status then -- The plugin is not existed + return +end + +mason.setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + }, + height = 0.7, -- 0 to 1 + width = 0.6, + --check_outdated_packages_on_open = true, + border = "rounded", + } +}) diff --git a/lua/configs/neo-tree.lua b/lua/configs/neo-tree.lua new file mode 100644 index 0000000..f9f42d0 --- /dev/null +++ b/lua/configs/neo-tree.lua @@ -0,0 +1,22 @@ +local status, neo_tree = pcall(require, "neo-tree") + +if not status then + return +end + +neo_tree.setup({ + close_if_last_window = true, -- Close Neo-tree if it is the last window left in the tab + icon = { + folder_closed = "", + folder_open = "", + folder_empty = "󰜌", + -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there + -- then these will never be used. + default = "*", + highlight = "NeoTreeFileIcon" + }, + window = { + position = "left", -- location + width = 30, -- window width + }, +}) diff --git a/lua/configs/notify.lua b/lua/configs/notify.lua new file mode 100644 index 0000000..030334a --- /dev/null +++ b/lua/configs/notify.lua @@ -0,0 +1,20 @@ +local status, notify = pcall(require, "notify") + +if not status then -- The plugin is not existed + return +end + + +local plugin = "My Awesome Plugin" +notify.setup({ + background_colour = "#F70067", + --background_colour = "#000000", + title = "My Awesome Plugin", + render = "default" +}) + +--notify.history() +notify("My super important message") + +vim.notify = notify -- vim.notify = require("notify") +--vim.notify("This is an error massage", "error") -- use to test diff --git a/lua/configs/null-ls.lua b/lua/configs/null-ls.lua new file mode 100644 index 0000000..63c8ab6 --- /dev/null +++ b/lua/configs/null-ls.lua @@ -0,0 +1,13 @@ +local status, null_ls = pcall(require, "null-ls") + +if not status then -- The plugin is not existed + return +end + +null_ls.setup({ + sources = { + null_ls.builtins.formatting.stylua, + null_ls.builtins.diagnostics.eslint, + null_ls.builtins.completion.spell, + }, +}) diff --git a/lua/configs/toggleterm.lua b/lua/configs/toggleterm.lua new file mode 100644 index 0000000..7b6a370 --- /dev/null +++ b/lua/configs/toggleterm.lua @@ -0,0 +1,11 @@ +local status, toggleterm = pcall(require, "toggleterm") + +if not status then -- The plugin is not existed + return +end + +toggleterm.setup({ + open_mapping = [[tt]], + direction = "horizontal", -- float horizontal vertical + shade_terminal = true +}) diff --git a/lua/configs/treesitter.lua b/lua/configs/treesitter.lua new file mode 100644 index 0000000..36961e2 --- /dev/null +++ b/lua/configs/treesitter.lua @@ -0,0 +1,15 @@ +local status, treesitter = pcall(require, "nvim-treesitter.configs") + +if not status then -- The plugin is not existed + return +end + +treesitter.setup({ + ensure_install = {"c", "cpp", "python", "lua"}, + auto_install = true, + sync_install = false, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + } +}) diff --git a/lua/maps.lua b/lua/maps.lua new file mode 100644 index 0000000..7fa7321 --- /dev/null +++ b/lua/maps.lua @@ -0,0 +1,19 @@ +local map = vim.api.nvim_set_keymap +local opt = {noremap = true,silent = true} + +-- File tree,,Neotree +map("n", "e", "Neotree toggle", opt) +-- bufferline +map("n", "gb", "BufferLinePick", opt) + +----- telescope ----- +local status, builtin = pcall(require,"telescope.builtin") -- builtin == require("telescope.builtin") +if status then + vim.keymap.set("n", "ff", builtin.find_files,{}) + map("n", "fg", "Telescope live_grep", opt) + map("n", "fb", "Telescope buffers", opt) + map("n", "fh", "Telescope help_tags", opt) +else + print("Telescope is not found") +end +----- telescope ----- diff --git a/lua/packer-plugins.lua b/lua/packer-plugins.lua new file mode 100644 index 0000000..947cb6c --- /dev/null +++ b/lua/packer-plugins.lua @@ -0,0 +1,75 @@ +return require("packer").startup(function(use) + -- Packer can manage itself + use("wbthomason/packer.nvim") + + -- plenary.nvim + use("nvim-lua/plenary.nvim") + + -- File manager + use({ + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + requires = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "MunifTanjim/nui.nvim", + } + }) + -- Statusline + use({ + "nvim-lualine/lualine.nvim", + requires = {"nvim-tree/nvim-web-devicons", opt = true}, + }) + -- tab bar + use ({ + 'akinsho/bufferline.nvim', tag = "*", + requires = 'nvim-tree/nvim-web-devicons' + }) + -- telescope + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.2', + -- or , branch = '0.1.x', + requires = { {'nvim-lua/plenary.nvim'} } + } + -- Terminal toggleterm + use({ + "akinsho/toggleterm.nvim", + tag = '*', + }) + -- popup + use("nvim-lua/popup.nvim") + + -- aotupairs + use("windwp/nvim-autopairs") + + ------------- lsp -------------- + use({ + "williamboman/mason.nvim", -- Mason + "williamboman/mason-lspconfig.nvim", -- Mason + "neovim/nvim-lspconfig", -- lspconfig + }) + -- cmp Autocomplete + use("hrsh7th/nvim-cmp") + use "hrsh7th/cmp-nvim-lsp" -- nvim_lsp + -- lsp_signature + use("ray-x/lsp_signature.nvim") + -- null-ls + use({ + "jose-elias-alvarez/null-ls.nvim", + requires = { "nvim-lua/plenary.nvim" }, + }) + ------------- lsp -------------- + + -- treesitter + use { + 'nvim-treesitter/nvim-treesitter', + --run = ':TSUpdate' + } + -- notify + use("rcarriga/nvim-notify") + -- fidget + use({ + "j-hui/fidget.nvim", + tag = "legacy" + }) +end) diff --git a/lua/settings.lua b/lua/settings.lua new file mode 100644 index 0000000..e678e37 --- /dev/null +++ b/lua/settings.lua @@ -0,0 +1,66 @@ +local global = vim.g + +-- map to key + +global.mapleader = " " +global.maplocalleader = " " + +-- Edit option + +vim.o.number = true -- 显示行号 +vim.o.mouse = "a" -- 启用鼠标 +vim.o.selection = "exclusive" +vim.o.selectmode = "mouse,key" +-- 设置编码 +vim.o.fileencodings = "utf-8,ucs-bom,gb1800,gbk,gb2312,cp936" -- 写入文件时采用的编码 +--vim.o.termencoding = "utf-8" -- 输出到终端时采用的编码类型,neovim的高版本没有这个设置 +vim.o.encoding = "utf-8" -- 用于缓存的文本、寄存器等 +-- 设置编码 +vim.o.cursorline = true -- 突出显示当前行 + +vim.o.syntax = "on" -- on off 语法检测,,颜色显示 +vim.o.hlsearch = true -- 若查找到匹配的短语(字符串),则高亮显示,,默认就是true,默认是开启的 + +------ 制表符 ------ +vim.o.expandtab = true +vim.o.shiftwidth = 4 +vim.o.tabstop = 4 +vim.o.softtabstop = 4 -- 在编辑模式,按退格键 退回缩进的长度 +------ 制表符 ------ + +vim.o.autoindent = true -- 自动缩进 +vim.o.cindent = true-- 针对C语言语法 自动缩进 +vim.o.smartindent = true -- 根据文件中其他地方的缩进空格数来确定一个tab是多少个空格 +vim.o.showcmd = true +vim.o.showmode = true +vim.o.cmdheight = 1 -- 设置底部命令行的高度 +vim.o.list = true -- 显示空格、换行 +vim.o.listchars = "tab:>-,trail:-" -- 修改tab的显示符号 +vim.o.ruler = true -- 在最下面一行显示状态,,默认就是true +vim.o.filetype = "on" -- 检测文件类型 +vim.o.history = 1000 -- 记录历史命令的行数 +vim.o.foldmethod = "manual" -- 设置代码折叠方式,,共6中方式 +--vim.o.clipboard = "unnamedplus" -- 让vim使用系统剪贴板 +vim.o.wildmenu = true -- 提示框 +vim.o.ttimeoutlen = 0 -- Esc键 延迟 + +vim.o.termguicolors = true -- 24-bit-color + +vim.o.title = true +vim.o.inccommand = "split" -- nosplit split +vim.o.splitright = true -- :vsp向右分屏 +vim.o.splitbelow = true -- :sp向下分屏 + +------ 文档备份设置 ------- +vim.opt.backup = false -- 不自动备份 +vim.opt.writebackup = false +------ 文档备份设置 ------- + +vim.opt.filetype = "on" -- check file type + +--vim.opt.spell = true -- 拼写检查 +--vim.opt.spelllang = {"en_us","cjk"} -- 只接受美式拼法,不对中文报错;;默认值是en + +vim.o.completeopt = "preview,menuone" +--vim.o.popupmenu = true +vim.o.complete = ".,w,b,u,t,i"