feat: basic editor

This commit is contained in:
Ting-Jun Wang 2023-11-04 15:16:31 +08:00
commit 0911e75418
Signed by: snsd0805
GPG Key ID: D175E969960C4B16
11 changed files with 282 additions and 0 deletions

14
init.vim Normal file
View File

@ -0,0 +1,14 @@
"# -- 基礎設定"
lua require('basic')
"# -- 快捷鍵"
lua require('keybindings')
"# -- Lazy nvim 插件"
lua require('lazynvim-init')
"set theme"
set background=dark
colorscheme kanagawa

116
lua/basic.lua Normal file
View File

@ -0,0 +1,116 @@
-- utf8
vim.g.encoding = "UTF-8"
vim.o.fileencoding = "utf-8"
-- jkhl 移动时光标周围保留8行
vim.o.scrolloff = 16
vim.o.sidescrolloff = 16
-- 使用相对行号
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
vim.o.hlsearch = true
-- 命令行高为2提供足够的显示空间
vim.o.cmdheight = 1
-- 当文件被外部程序修改时,自动加载
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毫秒可根据需要设置
-- 遇到问题详见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 = false
-- 配置剪切板
vim.opt.clipboard = "unnamedplus"

12
lua/keybindings.lua Normal file
View File

@ -0,0 +1,12 @@
local map = vim.api.nvim_set_keymap
local opt = {noremap = true, silent = true }
-- vim.g.mapleader = " "
-- vim.g.maplocalleader = " "
map('n', '<C-n>', ':NvimTreeToggle<CR>', opt)
map('i', '<C-c>', '<Esc>', opt)
map('n', '<C-c>', '<Esc>', opt)
map('v', '<C-c>', '<Esc>', opt)

16
lua/lazynvim-init.lua Normal file
View File

@ -0,0 +1,16 @@
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")

View File

@ -0,0 +1,8 @@
return {
{
"goolord/alpha-nvim",
config = function ()
require'alpha'.setup(require'alpha.themes.dashboard'.config)
end
}
}

10
lua/plugins/kanagawa.lua Normal file
View File

@ -0,0 +1,10 @@
return {
{
"rebelot/kanagawa.nvim",
lazy = false,
}
}

14
lua/plugins/lualine.lua Normal file
View File

@ -0,0 +1,14 @@
-- lualine
return {
{
"nvim-lualine/lualine.nvim",
lazy = false,
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
require("lualine").setup({})
end,
}
}

43
lua/plugins/mason.lua Normal file
View File

@ -0,0 +1,43 @@
return {
'VonHeikemen/lsp-zero.nvim',
dependencies = {
-- LSP Support
{'neovim/nvim-lspconfig'},
{'williamboman/mason.nvim'},
{'williamboman/mason-lspconfig.nvim'},
-- Autocompletion
{'hrsh7th/nvim-cmp'},
{'hrsh7th/cmp-buffer'},
{'hrsh7th/cmp-path'},
{'saadparwaiz1/cmp_luasnip'},
{'hrsh7th/cmp-nvim-lsp'},
{'hrsh7th/cmp-nvim-lua'},
-- Snippets
{'L3MON4D3/LuaSnip'},
{'rafamadriz/friendly-snippets'},
},
config = function()
local lsp_zero = require('lsp-zero')
lsp_zero.on_attach(function(client, bufnr)
-- see :help lsp-zero-keybindings
-- to learn the available actions
lsp_zero.default_keymaps({buffer = bufnr})
end)
require('mason').setup({})
require('mason-lspconfig').setup({
ensure_installed = {
'pyright',
'clangd'
},
handlers = {
lsp_zero.default_setup,
},
})
end
}

View File

@ -0,0 +1,8 @@
return {
'windwp/nvim-autopairs',
event = "InsertEnter",
config = function()
require('nvim-autopairs').setup({})
end
}

23
lua/plugins/nvim-cmp.lua Normal file
View File

@ -0,0 +1,23 @@
return {
{
'hrsh7th/nvim-cmp',
config = function()
local cmp = require('cmp')
local cmp_action = require('lsp-zero').cmp_action()
require('cmp').setup({
mapping = cmp.mapping.preset.insert({
-- `Enter` key to confirm completion
['<CR>'] = cmp.mapping.confirm({select = false}),
-- Ctrl+Space to trigger completion menu
['<C-Space>'] = cmp.mapping.complete(),
['<C-k>'] = cmp.mapping.select_prev_item({behavior = 'select'}),
['<C-j>'] = cmp.mapping.select_next_item({behavior = 'select'}),
})
})
end
}
}

18
lua/plugins/nvim-tree.lua Normal file
View File

@ -0,0 +1,18 @@
-- nvim tree
return {
{
"nvim-tree/nvim-tree.lua",
lazy = true,
cmd = {'NvimTreeOpen', 'NvimTreeToggle'},
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
require("nvim-tree").setup({
on_attach = my_on_attach
})
end,
}
}