Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fresh new #321

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
require "user.options"
require "user.keymaps"
require "user.plugins"
require "user.colorscheme"
require "user.cmp"
require "user.lsp"
require "user.telescope"
require "user.treesitter"
require "user.autopairs"
require "user.comment"
require "user.gitsigns"
require "user.nvim-tree"
require "user.bufferline"
require "user.lualine"
require "user.toggleterm"
require "user.project"
require "user.impatient"
require "user.indentline"
require "user.alpha"
require "user.whichkey"
require "user.autocommands"

require("basic")

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)
-- require("lazy").setup(plugins, opts)

vim.g.mapleader = ','

require("lazy").setup("plugins")

require("keybindings")
require("treesitter")
require("nvimtree")
require("lsp")
require("formatters")
require("cmpl")
require("colortheme")
require("tools")
89 changes: 89 additions & 0 deletions lua/basic.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
-- utf8
vim.g.encoding = "UTF-8"
vim.o.fileencoding = "utf-8"
-- jkhl 移动时光标周围保留8行
vim.o.scrolloff = 8
vim.o.sidescrolloff = 8
-- 使用相对行号
vim.wo.number = true
-- vim.wo.relativenumber = true
-- 高亮所在行
vim.wo.cursorline = true
-- 显示左侧图标指示列
vim.wo.signcolumn = "yes"
-- 右侧参考线,超过表示代码太长了,考虑换行
vim.wo.colorcolumn = "80"
-- 缩进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 = 500
-- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒,可根据需要设置
-- 遇到问题详见:https://github.com/nshen/learn-neovim-lua/issues/1
vim.o.timeoutlen = 500
-- split window 从下边和右边出现
vim.o.splitbelow = true
vim.o.splitright = true
-- 自动补全不自动选中
vim.g.completeopt = "menu,menuone,noselect,noinsert"
-- 样式
vim.o.termguicolors = true
vim.opt.termguicolors = true
-- 是否显示不可见字符
vim.o.list = false
-- 不可见字符的显示,这里只把空格显示为一个点
vim.o.listchars = "space:·,tab:··"
-- 补全增强
vim.o.wildmenu = true
-- Dont' pass messages to |ins-completin menu|
vim.o.shortmess = vim.o.shortmess .. "c"
-- 补全最多显示10行
vim.o.pumheight = 10
-- 永远显示 tabline
vim.o.showtabline = 2
-- 使用增强状态栏插件后不再需要 vim 的模式提示
vim.o.showmode = true
-- 配置剪切板
vim.opt.clipboard = "unnamedplus"
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true
35 changes: 35 additions & 0 deletions lua/cmpl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- 代码补全插件

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,
},
sources = {
{ name = "nvim_lsp" },
{ name = "vsnip" },
{ name = "cmp-async-path" },
},
mapping = cmp.mapping.preset.insert({
-- ['<CR>'] = cmp.mapping.confirm({ select = true }),
['<C-Space>'] = cmp.mapping.complete(),
}),
})

-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = require("cmp_nvim_lsp").default_capabilities()

-- The following example advertise capabilities to `clangd`.
require("lspconfig").clangd.setup({
capabilities = capabilities,
})

require("Comment").setup()

local mm = "k"
32 changes: 32 additions & 0 deletions lua/colortheme.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Default options:
require("kanagawa").setup({
compile = false, -- enable compiling the colorscheme
undercurl = true, -- enable undercurls
commentStyle = { italic = true },
functionStyle = {},
keywordStyle = { italic = true },
statementStyle = { bold = true },
typeStyle = {},
transparent = false, -- do not set background color
dimInactive = false, -- dim inactive window `:h hl-NormalNC`
terminalColors = true, -- define vim.g.terminal_color_{0,17}
colors = { -- add/modify theme and palette colors
palette = {},
theme = { wave = {}, lotus = {}, dragon = {}, all = {} },
},
overrides = function(colors) -- add/modify highlights
return {}
end,
theme = "wave", -- Load "wave" theme when 'background' option is not set
background = { -- map the value of 'background' option to a theme
dark = "wave", -- try "dragon" !
light = "lotus",
},
})

-- setup must be called before loading
vim.cmd("colorscheme kanagawa")

-- bufferline setting
vim.opt.termguicolors = true
require("bufferline").setup({})
50 changes: 50 additions & 0 deletions lua/formatters.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Utilities for creating configurations
local util = require("formatter.util")

-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
require("formatter").setup({
-- Enable or disable logging
logging = true,
-- Set the log level
log_level = vim.log.levels.WARN,
-- All formatter configurations are opt-in
filetype = {
-- Formatter configurations for filetype "lua" go here
-- and will be executed in order
lua = {
-- "formatter.filetypes.lua" defines default configurations for the
-- "lua" filetype
require("formatter.filetypes.lua").stylua,

-- You can also define your own configuration
function()
-- Supports conditional formatting
if util.get_current_buffer_file_name() == "special.lua" then
return nil
end

-- Full specification of configurations is down below and in Vim help
-- files
return {
exe = "stylua",
args = {
"--search-parent-directories",
"--stdin-filepath",
util.escape_path(util.get_current_buffer_file_path()),
"--",
"-",
},
stdin = true,
}
end,
},

-- Use the special "*" filetype for defining formatter configurations on
-- any filetype
["*"] = {
-- "formatter.filetypes.any" defines default configurations for any
-- filetype
require("formatter.filetypes.any").remove_trailing_whitespace,
},
},
})
72 changes: 72 additions & 0 deletions lua/keybindings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
-- 插件快捷键

local function map(mode, lhs, rhs, opts)
local options = { noremap = true, silent = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end

-- Map Esc to kk
map("i", "kk", "<Esc>")

-- 切换窗口
map("n", "<C-h>", "<C-w>h")
map("n", "<C-j>", "<C-w>j")
map("n", "<C-k>", "<C-w>k")
map("n", "<C-l>", "<C-w>l")

-- Reload configuration without restart nvim
map("n", "<leader>r", ":so %<CR>")

-- nvim-tree
-- 打开关闭tree
map("n", "<C-b>", ":NvimTreeToggle<CR>")

-- formatter
map("n", "<leader-f>", ":Format<CR>")

-- auto comments
map("n", "<C-;>", "gcc")
-- map("v", "<C-_>", "gc")



-- 设置快捷键注册到which-key
local wk = require("which-key")
-- wk.register(mappings, opts)
wk.register({
["<leader>f"] = { name = "file options" },
["<leader>fg"] = { "<cmd>Format<CR>", "Format file" },
["<leader>s"] = { name = "telescope land"},
["<leader>sf"] = { "<cmd>lua require('telescope.builtin').find_files()<CR>", "find files" },
["<leader>sg"] = { "<cmd>lua require('telescope.builtin').live_grep()<cr>", "live grep" },
["<leader>sb"] = { "<cmd>lua require('telescope.builtin').buffers()<cr>", "buffers" },
["<leader>sh"] = { "<cmd>lua require('telescope.builtin').help_tags()<cr>", "help_tags" },
})


local pluginKeys = {}
-- 列表快捷键
pluginKeys.nvimTree = {
-- 打开文件或文件夹
{ key = { "<CR>", "o", "<2-LeftMouse>" }, action = "edit" },
-- 分屏打开文件
{ key = "v", action = "vsplit" },
{ key = "h", action = "split" },
-- 显示隐藏文件
{ key = "i", action = "toggle_custom" }, -- 对应 filters 中的 custom (node_modules)
{ key = ".", action = "toggle_dotfiles" }, -- Hide (dotfiles)
-- 文件操作
{ key = "<F5>", action = "refresh" },
{ key = "a", action = "create" },
{ key = "d", action = "remove" },
{ key = "r", action = "rename" },
{ key = "x", action = "cut" },
{ key = "c", action = "copy" },
{ key = "p", action = "paste" },
{ key = "s", action = "system_open" },
}

return pluginKeys
11 changes: 11 additions & 0 deletions lua/lsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require("mason").setup({
ui = {
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗",
},
},
})

require("mason-lspconfig").setup()
41 changes: 41 additions & 0 deletions lua/nvimtree.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

vim.g.nvim_tree_icons = {
default = "",
symlink = "",
git = {
unstaged = "",
staged = "S",
unmerged = "",
renamed = "➜",
deleted = "",
untracked = "U",
ignored = "◌",
},
folder = {
default = "",
open = "",
empty = "",
empty_open = "",
symlink = "",
},
}


local mapKey = require("keybindings")



require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
width = 30,
},
-- mapkeyings = mapKey.nvimTree,
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
})

Loading