初版。
This commit is contained in:
8
lua/config/autocmds.lua
Normal file
8
lua/config/autocmds.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
-- Autocmds are automatically loaded on the VeryLazy event
|
||||
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
|
||||
--
|
||||
-- Add any additional autocmds here
|
||||
-- with `vim.api.nvim_create_autocmd`
|
||||
--
|
||||
-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
|
||||
-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")
|
||||
3
lua/config/keymaps.lua
Normal file
3
lua/config/keymaps.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
-- Keymaps are automatically loaded on the VeryLazy event
|
||||
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
|
||||
-- Add any additional keymaps here
|
||||
53
lua/config/lazy.lua
Normal file
53
lua/config/lazy.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
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
|
||||
vim.api.nvim_echo({
|
||||
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
|
||||
{ out, "WarningMsg" },
|
||||
{ "\nPress any key to exit..." },
|
||||
}, true, {})
|
||||
vim.fn.getchar()
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
require("lazy").setup({
|
||||
spec = {
|
||||
-- add LazyVim and import its plugins
|
||||
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
|
||||
-- import/override with your plugins
|
||||
{ import = "plugins" },
|
||||
},
|
||||
defaults = {
|
||||
-- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.
|
||||
-- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default.
|
||||
lazy = false,
|
||||
-- It's recommended to leave version=false for now, since a lot the plugin that support versioning,
|
||||
-- have outdated releases, which may break your Neovim install.
|
||||
version = false, -- always use the latest git commit
|
||||
-- version = "*", -- try installing the latest stable version for plugins that support semver
|
||||
},
|
||||
install = { colorscheme = { "tokyonight", "habamax" } },
|
||||
checker = {
|
||||
enabled = true, -- check for plugin updates periodically
|
||||
notify = false, -- notify on update
|
||||
}, -- automatically check for plugin updates
|
||||
performance = {
|
||||
rtp = {
|
||||
-- disable some rtp plugins
|
||||
disabled_plugins = {
|
||||
"gzip",
|
||||
-- "matchit",
|
||||
-- "matchparen",
|
||||
-- "netrwPlugin",
|
||||
"tarPlugin",
|
||||
"tohtml",
|
||||
"tutor",
|
||||
"zipPlugin",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
78
lua/config/options.lua
Normal file
78
lua/config/options.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
-- Options are automatically loaded before lazy.nvim startup
|
||||
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
|
||||
-- Add any additional options here
|
||||
-- Options are automatically loaded before lazy.nvim startup
|
||||
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
|
||||
-- Add any additional options here
|
||||
--
|
||||
-- 设置文件编码检测集
|
||||
-- vim.opt.fileencodings = "ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1"
|
||||
vim.opt.clipboard = "unnamedplus"
|
||||
vim.g.autoformat = false
|
||||
-- jkhl 移动时光标周围保留8行
|
||||
vim.o.scrolloff = 4
|
||||
vim.o.sidescrolloff = 4
|
||||
-- 使用相对行号
|
||||
vim.wo.number = true
|
||||
vim.wo.relativenumber = true
|
||||
-- 高亮所在行
|
||||
vim.wo.cursorline = true
|
||||
-- 右侧参考线,超过表示代码太长了,考虑换行
|
||||
vim.wo.colorcolumn = "110"
|
||||
-- 缩进2个空格等于一个Tab
|
||||
vim.o.tabstop = 4
|
||||
vim.bo.tabstop = 4
|
||||
vim.o.softtabstop = 4
|
||||
vim.o.shiftround = true
|
||||
-- >> << 时移动长度
|
||||
vim.o.shiftwidth = 4
|
||||
vim.bo.shiftwidth = 4
|
||||
-- 空格替代tab
|
||||
vim.o.expandtab = true
|
||||
vim.bo.expandtab = true
|
||||
-- 新行对齐当前行
|
||||
vim.o.autoindent = true
|
||||
vim.bo.autoindent = true
|
||||
vim.o.smartindent = true
|
||||
-- 搜索大小写不敏感,除非包含大写
|
||||
vim.o.ignorecase = true
|
||||
vim.o.smartcase = true
|
||||
-- 搜索不要高亮
|
||||
vim.o.hlsearch = false
|
||||
-- 边输入边搜索
|
||||
vim.o.incsearch = true
|
||||
-- 命令行高为2,提供足够的显示空间
|
||||
vim.o.cmdheight = 2
|
||||
-- 当文件被外部程序修改时,自动加载
|
||||
vim.o.autoread = true
|
||||
vim.bo.autoread = true
|
||||
-- 禁止折行
|
||||
vim.wo.wrap = false
|
||||
-- 光标在行首尾时<Left><Right>可以跳到下一行
|
||||
vim.o.whichwrap = "<,>,[,]"
|
||||
-- 允许隐藏被修改过的buffer
|
||||
vim.o.hidden = true
|
||||
-- 鼠标支持
|
||||
vim.o.mouse = "a"
|
||||
-- 禁止创建备份文件
|
||||
vim.o.backup = false
|
||||
vim.o.writebackup = false
|
||||
vim.o.swapfile = false
|
||||
-- smaller updatetime
|
||||
vim.o.updatetime = 300
|
||||
-- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒,可根据需要设置
|
||||
vim.o.timeoutlen = 500
|
||||
-- split window 从下边和右边出现
|
||||
vim.o.splitbelow = true
|
||||
vim.o.splitright = true
|
||||
-- 不可见字符的显示,这里只把空格显示为一个点
|
||||
-- vim.o.list = true
|
||||
-- vim.o.listchars = "space:·"
|
||||
-- 补全最多显示10行
|
||||
vim.o.pumheight = 10
|
||||
-- 永远显示 tabline
|
||||
vim.o.showtabline = 2
|
||||
-- 使用增强状态栏插件后不再需要 vim 的模式提示
|
||||
vim.o.showmode = false
|
||||
vim.o.background = "light"
|
||||
-- vim.o.background = "dark"
|
||||
37
lua/plugins/cmake-tools.lua
Normal file
37
lua/plugins/cmake-tools.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
return {
|
||||
"Civitasv/cmake-tools.nvim",
|
||||
lazy = true,
|
||||
init = function()
|
||||
local loaded = false
|
||||
local function check()
|
||||
local cwd = vim.uv.cwd()
|
||||
if vim.fn.filereadable(cwd .. "/CMakeLists.txt") == 1 then
|
||||
require("lazy").load({ plugins = { "cmake-tools.nvim" } })
|
||||
loaded = true
|
||||
end
|
||||
end
|
||||
check()
|
||||
vim.api.nvim_create_autocmd("DirChanged", {
|
||||
callback = function()
|
||||
if not loaded then
|
||||
check()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
keys = {
|
||||
{ "<leader>mg", ":CMakeGenerate -G Ninja<CR>", desc = "CMake Generate -G Ninja", remap = false },
|
||||
{ "<leader>mb", ":CMakeBuild<CR>", desc = "CMake Build", remap = false },
|
||||
{ "<leader>mr", ":CMakeRun<CR>", desc = "CMake Run", remap = false },
|
||||
{ "<leader>mc", ":CMakeClean<CR>", desc = "CMake Clear", remap = false },
|
||||
{ "<leader>ms", ":CMakeStop<CR>", desc = "CMake Stop", remap = false },
|
||||
{ "<leader>mq", ":CMakeCloseRunner<CR>", desc = "CMake Close", remap = false },
|
||||
{ "<leader>mt", ":CMakeSelectLaunchTarget<CR>", desc = "CMake Change Target", remap = false },
|
||||
{ "<leader>ma", ":CMakeLaunchArgs", desc = "CMake Launch Args", remap = false },
|
||||
{ "<leader>md", ":CMakeDebug<CR>", desc = "CMake Debug", remap = false },
|
||||
},
|
||||
opts = {
|
||||
cmake_build_directory = "build",
|
||||
cmake_soft_link_compile_commands = false,
|
||||
},
|
||||
}
|
||||
24
lua/plugins/conform.lua
Normal file
24
lua/plugins/conform.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
return {
|
||||
"stevearc/conform.nvim",
|
||||
opts = {
|
||||
formatters_by_ft = {
|
||||
xml = { "xmlformatter" },
|
||||
json = { "prettier" },
|
||||
cfg = { "prettier" },
|
||||
},
|
||||
formatters = {
|
||||
xmlformatter = {
|
||||
command = "xmlformat",
|
||||
args = {
|
||||
"--indent", "4", "-"
|
||||
},
|
||||
stdin = true,
|
||||
},
|
||||
prettier = {
|
||||
prepend_args = {
|
||||
"--tab-width", "4"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
197
lua/plugins/example.lua
Normal file
197
lua/plugins/example.lua
Normal file
@@ -0,0 +1,197 @@
|
||||
-- since this is just an example spec, don't actually load anything here and return an empty spec
|
||||
-- stylua: ignore
|
||||
if true then return {} end
|
||||
|
||||
-- every spec file under the "plugins" directory will be loaded automatically by lazy.nvim
|
||||
--
|
||||
-- In your plugin files, you can:
|
||||
-- * add extra plugins
|
||||
-- * disable/enabled LazyVim plugins
|
||||
-- * override the configuration of LazyVim plugins
|
||||
return {
|
||||
-- add gruvbox
|
||||
{ "ellisonleao/gruvbox.nvim" },
|
||||
|
||||
-- Configure LazyVim to load gruvbox
|
||||
{
|
||||
"LazyVim/LazyVim",
|
||||
opts = {
|
||||
colorscheme = "gruvbox",
|
||||
},
|
||||
},
|
||||
|
||||
-- change trouble config
|
||||
{
|
||||
"folke/trouble.nvim",
|
||||
-- opts will be merged with the parent spec
|
||||
opts = { use_diagnostic_signs = true },
|
||||
},
|
||||
|
||||
-- disable trouble
|
||||
{ "folke/trouble.nvim", enabled = false },
|
||||
|
||||
-- override nvim-cmp and add cmp-emoji
|
||||
{
|
||||
"hrsh7th/nvim-cmp",
|
||||
dependencies = { "hrsh7th/cmp-emoji" },
|
||||
---@param opts cmp.ConfigSchema
|
||||
opts = function(_, opts)
|
||||
table.insert(opts.sources, { name = "emoji" })
|
||||
end,
|
||||
},
|
||||
|
||||
-- change some telescope options and a keymap to browse plugin files
|
||||
{
|
||||
"nvim-telescope/telescope.nvim",
|
||||
keys = {
|
||||
-- add a keymap to browse plugin files
|
||||
-- stylua: ignore
|
||||
{
|
||||
"<leader>fp",
|
||||
function() require("telescope.builtin").find_files({ cwd = require("lazy.core.config").options.root }) end,
|
||||
desc = "Find Plugin File",
|
||||
},
|
||||
},
|
||||
-- change some options
|
||||
opts = {
|
||||
defaults = {
|
||||
layout_strategy = "horizontal",
|
||||
layout_config = { prompt_position = "top" },
|
||||
sorting_strategy = "ascending",
|
||||
winblend = 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- add pyright to lspconfig
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
---@class PluginLspOpts
|
||||
opts = {
|
||||
---@type lspconfig.options
|
||||
servers = {
|
||||
-- pyright will be automatically installed with mason and loaded with lspconfig
|
||||
pyright = {},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- add tsserver and setup with typescript.nvim instead of lspconfig
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
"jose-elias-alvarez/typescript.nvim",
|
||||
init = function()
|
||||
require("lazyvim.util").lsp.on_attach(function(_, buffer)
|
||||
-- stylua: ignore
|
||||
vim.keymap.set( "n", "<leader>co", "TypescriptOrganizeImports", { buffer = buffer, desc = "Organize Imports" })
|
||||
vim.keymap.set("n", "<leader>cR", "TypescriptRenameFile", { desc = "Rename File", buffer = buffer })
|
||||
end)
|
||||
end,
|
||||
},
|
||||
---@class PluginLspOpts
|
||||
opts = {
|
||||
---@type lspconfig.options
|
||||
servers = {
|
||||
-- tsserver will be automatically installed with mason and loaded with lspconfig
|
||||
tsserver = {},
|
||||
},
|
||||
-- you can do any additional lsp server setup here
|
||||
-- return true if you don't want this server to be setup with lspconfig
|
||||
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
|
||||
setup = {
|
||||
-- example to setup with typescript.nvim
|
||||
tsserver = function(_, opts)
|
||||
require("typescript").setup({ server = opts })
|
||||
return true
|
||||
end,
|
||||
-- Specify * to use this function as a fallback for any server
|
||||
-- ["*"] = function(server, opts) end,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- for typescript, LazyVim also includes extra specs to properly setup lspconfig,
|
||||
-- treesitter, mason and typescript.nvim. So instead of the above, you can use:
|
||||
{ import = "lazyvim.plugins.extras.lang.typescript" },
|
||||
|
||||
-- add more treesitter parsers
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
"bash",
|
||||
"html",
|
||||
"javascript",
|
||||
"json",
|
||||
"lua",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
"python",
|
||||
"query",
|
||||
"regex",
|
||||
"tsx",
|
||||
"typescript",
|
||||
"vim",
|
||||
"yaml",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- since `vim.tbl_deep_extend`, can only merge tables and not lists, the code above
|
||||
-- would overwrite `ensure_installed` with the new value.
|
||||
-- If you'd rather extend the default config, use the code below instead:
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
opts = function(_, opts)
|
||||
-- add tsx and treesitter
|
||||
vim.list_extend(opts.ensure_installed, {
|
||||
"tsx",
|
||||
"typescript",
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
-- the opts function can also be used to change the default opts:
|
||||
{
|
||||
"nvim-lualine/lualine.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = function(_, opts)
|
||||
table.insert(opts.sections.lualine_x, {
|
||||
function()
|
||||
return "😄"
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
-- or you can return new options to override all the defaults
|
||||
{
|
||||
"nvim-lualine/lualine.nvim",
|
||||
event = "VeryLazy",
|
||||
opts = function()
|
||||
return {
|
||||
--[[add your custom lualine config here]]
|
||||
}
|
||||
end,
|
||||
},
|
||||
|
||||
-- use mini.starter instead of alpha
|
||||
{ import = "lazyvim.plugins.extras.ui.mini-starter" },
|
||||
|
||||
-- add jsonls and schemastore packages, and setup treesitter for json, json5 and jsonc
|
||||
{ import = "lazyvim.plugins.extras.lang.json" },
|
||||
|
||||
-- add any tools you want to have installed below
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
"stylua",
|
||||
"shellcheck",
|
||||
"shfmt",
|
||||
"flake8",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
29
lua/plugins/nvim-lspconfig.lua
Normal file
29
lua/plugins/nvim-lspconfig.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
return {
|
||||
"neovim/nvim-lspconfig",
|
||||
event = "LazyFile",
|
||||
dependencies = {
|
||||
"mason.nvim",
|
||||
{ "mason-org/mason-lspconfig.nvim", config = function() end },
|
||||
},
|
||||
opts = {
|
||||
servers = {
|
||||
-- Ensure mason installs the server
|
||||
clangd = {
|
||||
cmd = {
|
||||
"clangd",
|
||||
"--background-index",
|
||||
"--header-insertion=never",
|
||||
"--all-scopes-completion",
|
||||
"-j=4",
|
||||
"--pch-storage=memory",
|
||||
"--compile-commands-dir=build",
|
||||
"--clang-tidy",
|
||||
"--background-index",
|
||||
"--header-insertion=iwyu",
|
||||
"--completion-style=detailed",
|
||||
"--function-arg-placeholders=false"
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
12
lua/plugins/tokyonight.lua
Normal file
12
lua/plugins/tokyonight.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
return {
|
||||
"folke/tokyonight.nvim",
|
||||
opts = {
|
||||
-- moon
|
||||
style = "day"
|
||||
},
|
||||
config = function (_, opts)
|
||||
require("tokyonight").setup(opts)
|
||||
vim.cmd("colorscheme tokyonight")
|
||||
end
|
||||
}
|
||||
|
||||
52
lua/tools/cmake.lua
Normal file
52
lua/tools/cmake.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
-- ~/.config/nvim/lua/myplugin/init.lua
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Function to copy files from the resource directory to the current directory
|
||||
local function copy_files(str)
|
||||
local resource_dir = vim.fn.stdpath("config") .. "/res/template/cmake"
|
||||
local target_dir = vim.fn.getcwd()
|
||||
|
||||
local files = { ".clangd", ".clang-format", "CMakeLists.txt", "main.cpp" }
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
local src_path = resource_dir .. "/" .. file
|
||||
local dest_path = target_dir .. "/" .. file
|
||||
|
||||
local input_file = io.open(src_path, "r")
|
||||
if input_file then
|
||||
local content = input_file:read("*all")
|
||||
input_file:close()
|
||||
|
||||
if file == "CMakeLists.txt" and str ~= "" then
|
||||
-- Replace the placeholder text in CMakeLists.txt
|
||||
content = content:gsub("replace", str)
|
||||
end
|
||||
|
||||
local output_file = io.open(dest_path, "w")
|
||||
if output_file then
|
||||
output_file:write(content)
|
||||
output_file:close()
|
||||
else
|
||||
print("Error writing file: " .. dest_path)
|
||||
end
|
||||
else
|
||||
print("Error reading file: " .. src_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
vim.api.nvim_create_user_command("CMakeQuick", function()
|
||||
local str = vim.fn.input("Enter project's name: ")
|
||||
|
||||
if str == "" then
|
||||
print("Name is empty. Nothing to do.")
|
||||
else
|
||||
copy_files(str)
|
||||
print("Create project successfully.")
|
||||
end
|
||||
end, {})
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user