commit 0911e75418206d37618316f943176440a5f7d295 Author: Ting-Jun Wang Date: Sat Nov 4 15:16:31 2023 +0800 feat: basic editor diff --git a/init.vim b/init.vim new file mode 100644 index 0000000..f15430b --- /dev/null +++ b/init.vim @@ -0,0 +1,14 @@ +"# -- 基礎設定" +lua require('basic') + +"# -- 快捷鍵" +lua require('keybindings') + +"# -- Lazy nvim 插件" +lua require('lazynvim-init') + + +"set theme" +set background=dark +colorscheme kanagawa + diff --git a/lua/basic.lua b/lua/basic.lua new file mode 100644 index 0000000..cbbd613 --- /dev/null +++ b/lua/basic.lua @@ -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 + +-- 光标在行首尾时可以跳到下一行 +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" diff --git a/lua/keybindings.lua b/lua/keybindings.lua new file mode 100644 index 0000000..c6a307c --- /dev/null +++ b/lua/keybindings.lua @@ -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', '', ':NvimTreeToggle', opt) +map('i', '', '', opt) +map('n', '', '', opt) +map('v', '', '', opt) + + diff --git a/lua/lazynvim-init.lua b/lua/lazynvim-init.lua new file mode 100644 index 0000000..150350d --- /dev/null +++ b/lua/lazynvim-init.lua @@ -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") + diff --git a/lua/plugins/alpha-nvim.lua b/lua/plugins/alpha-nvim.lua new file mode 100644 index 0000000..cdc8a8a --- /dev/null +++ b/lua/plugins/alpha-nvim.lua @@ -0,0 +1,8 @@ +return { + { + "goolord/alpha-nvim", + config = function () + require'alpha'.setup(require'alpha.themes.dashboard'.config) + end + } +} diff --git a/lua/plugins/kanagawa.lua b/lua/plugins/kanagawa.lua new file mode 100644 index 0000000..29e6c7f --- /dev/null +++ b/lua/plugins/kanagawa.lua @@ -0,0 +1,10 @@ +return { + { + "rebelot/kanagawa.nvim", + lazy = false, + } +} + + + + diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..7633865 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,14 @@ +-- lualine +return { + { + "nvim-lualine/lualine.nvim", + lazy = false, + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + config = function() + require("lualine").setup({}) + end, + + } +} diff --git a/lua/plugins/mason.lua b/lua/plugins/mason.lua new file mode 100644 index 0000000..64ddbbc --- /dev/null +++ b/lua/plugins/mason.lua @@ -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 +} diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua new file mode 100644 index 0000000..f7cbca3 --- /dev/null +++ b/lua/plugins/nvim-autopairs.lua @@ -0,0 +1,8 @@ +return { + 'windwp/nvim-autopairs', + event = "InsertEnter", + config = function() + require('nvim-autopairs').setup({}) + end +} + diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..1a8d431 --- /dev/null +++ b/lua/plugins/nvim-cmp.lua @@ -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 + [''] = cmp.mapping.confirm({select = false}), + + -- Ctrl+Space to trigger completion menu + [''] = cmp.mapping.complete(), + + [''] = cmp.mapping.select_prev_item({behavior = 'select'}), + [''] = cmp.mapping.select_next_item({behavior = 'select'}), + + }) + }) + end + } +} diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..cb13492 --- /dev/null +++ b/lua/plugins/nvim-tree.lua @@ -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, + } +}