From 2d25c86d3ce4b0e79f3af2ad5e406c6ac1acdb78 Mon Sep 17 00:00:00 2001 From: gameloader Date: Fri, 7 Oct 2022 19:27:54 +0800 Subject: [PATCH] add table-mode and toggleterm,change readme --- init.lua | 2 + lua/basic.lua | 126 +++++++++++++++---------------- lua/keybindings.lua | 14 ++++ lua/plugin-config/comment.lua | 98 +++++++++++++----------- lua/plugin-config/table-mode.lua | 5 ++ lua/plugin-config/toggleterm.lua | 8 ++ lua/plugins.lua | 15 ++++ readme.md | 84 +++++++++++++++++++++ 8 files changed, 242 insertions(+), 110 deletions(-) create mode 100644 lua/plugin-config/table-mode.lua create mode 100644 lua/plugin-config/toggleterm.lua diff --git a/init.lua b/init.lua index 3985ce2..f840f19 100644 --- a/init.lua +++ b/init.lua @@ -14,8 +14,10 @@ require("plugin-config/mason") require("plugin-config/lualine") require("plugin-config/notify") require("plugin-config/nvim-autopairs") +require("plugin-config/table-mode") require("plugin-config/project") require("plugin-config/dashboard") +require("plugin-config/toggleterm") require("plugin-config/coderunner") require("plugin-config/lazygit") -- require("plugin-config/neogit") diff --git a/lua/basic.lua b/lua/basic.lua index df5777b..66d3b23 100644 --- a/lua/basic.lua +++ b/lua/basic.lua @@ -1,72 +1,68 @@ local M = {} M.load_default_options = function() - - local set_options = { - backup = false, -- creates a backup file - clipboard = "unnamedplus", -- allows neovim to access the system clipboard - cmdheight = 1, -- more space in the neovim command line for displaying messages - completeopt = { "menuone", "noselect" }, - conceallevel = 0, -- so that `` is visible in markdown files - fileencoding = "utf-8", -- the encoding written to a file - foldmethod = "manual", -- folding, set to "expr" for treesitter based folding - foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding - guifont = "monospace:h17", -- the font used in graphical neovim applications - background = "light", -- set the background to light or dark - hidden = true, -- required to keep multiple buffers and open multiple buffers - hlsearch = true, -- highlight all matches on previous search pattern - ignorecase = true, -- ignore case in search patterns - mouse = "a", -- allow the mouse to be used in neovim - pumheight = 10, -- pop up menu height - showmode = false, -- we don't need to see things like -- INSERT -- anymore - showtabline = 2, -- always show tabs - smartcase = true, -- smart case - smartindent = true, -- make indenting smarter again - splitbelow = true, -- force all horizontal splits to go below current window - splitright = true, -- force all vertical splits to go to the right of current window - swapfile = false, -- creates a swapfile - termguicolors = true, -- set term gui colors (most terminals support this) - timeoutlen = 1000, -- time to wait for a mapped sequence to complete (in milliseconds) - title = true, -- set the title of window to the value of the titlestring - -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to - undodir = undodir, -- set an undo directory - undofile = true, -- enable persistent undo - updatetime = 100, -- faster completion - writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited - expandtab = true, -- convert tabs to spaces - shiftwidth = 2, -- the number of spaces inserted for each indentation - tabstop = 2, -- insert 2 spaces for a tab - cursorline = true, -- highlight the current line - number = true, -- set numbered lines - numberwidth = 4, -- set number column width to 2 {default 4} - signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time - wrap = true, -- display lines as one long line - -- shadafile = join_paths(get_cache_dir(), "lvim.shada"), - scrolloff = 8, -- minimal number of screen lines to keep above and below the cursor. - sidescrolloff = 8, -- minimal number of screen lines to keep left and right of the cursor. - showcmd = false, - ruler = false, - laststatus = 3, - } + local set_options = { + backup = false, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 1, -- more space in the neovim command line for displaying messages + completeopt = { "menuone", "noselect" }, + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a file + foldmethod = "manual", -- folding, set to "expr" for treesitter based folding + foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding + guifont = "monospace:h17", -- the font used in graphical neovim applications + background = "light", -- set the background to light or dark + hidden = true, -- required to keep multiple buffers and open multiple buffers + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = true, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = false, -- creates a swapfile + termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 1000, -- time to wait for a mapped sequence to complete (in milliseconds) + title = true, -- set the title of window to the value of the titlestring + -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to + undodir = undodir, -- set an undo directory + undofile = true, -- enable persistent undo + updatetime = 100, -- faster completion + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = true, -- convert tabs to spaces + shiftwidth = 2, -- the number of spaces inserted for each indentation + tabstop = 2, -- insert 2 spaces for a tab + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = true, -- display lines as one long line + -- shadafile = join_paths(get_cache_dir(), "lvim.shada"), + scrolloff = 8, -- minimal number of screen lines to keep above and below the cursor. + sidescrolloff = 8, -- minimal number of screen lines to keep left and right of the cursor. + showcmd = false, + ruler = false, + laststatus = 3, + } - for k, v in pairs(set_options) do - vim.opt[k] = v - end + for k, v in pairs(set_options) do + vim.opt[k] = v + end + local let_options = { + -- disable netrw at the very start of your init.lua (strongly advised) + loaded = 1, + loaded_netrwPlugin = 1, + -- set leaderkey to space + mapleader = " ", + } - local let_options = { - -- disable netrw at the very start of your init.lua (strongly advised) - loaded = 1, - loaded_netrwPlugin = 1, - -- set leaderkey to space - mapleader = " ", - } + for k, v in pairs(let_options) do + vim.g[k] = v + end +end - for k, v in pairs(let_options) do - vim.g[k] = v - end - end - - - - return M +return M diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 75b4f1d..08edb90 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -18,6 +18,20 @@ wk.register({ -- 代码相关 map("n", ",", ":RunCode", opt) +-- markdown related +-- markdown 相关 +wk.register({ + ["m"] = { ":MarkdownPreview", "Markdown preview" }, +}) + +-- markdown table +-- markdown 表格 +wk.register({ + ["t"] = { + name = "+Table", + }, +}) + -- git related -- git 相关 wk.register({ diff --git a/lua/plugin-config/comment.lua b/lua/plugin-config/comment.lua index f6911bb..2b004a3 100644 --- a/lua/plugin-config/comment.lua +++ b/lua/plugin-config/comment.lua @@ -1,45 +1,53 @@ -require('Comment').setup{ - ---Add a space b/w comment and the line - padding = true, - ---Whether the cursor should stay at its position - sticky = true, - ---Lines to be ignored while (un)comment - ignore = "^$", - ---LHS of toggle mappings in NORMAL mode - toggler = { - ---Line-comment toggle keymap - line = 'gcc', - ---Block-comment toggle keymap - block = 'gbc', - }, - ---LHS of operator-pending mappings in NORMAL and VISUAL mode - opleader = { - ---Line-comment keymap - line = 'gc', - ---Block-comment keymap - block = 'gb', - }, - ---LHS of extra mappings - extra = { - ---Add comment on the line above - above = 'gcO', - ---Add comment on the line below - below = 'gco', - ---Add comment at the end of line - eol = 'gcA', - }, - ---Enable keybindings - ---NOTE: If given `false` then the plugin won't create any mappings - mappings = { - ---Operator-pending mapping; `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}` - basic = true, - ---Extra mapping; `gco`, `gcO`, `gcA` - extra = true, - ---Extended mapping; `g>` `g<` `g>[count]{motion}` `g<[count]{motion}` - extended = false, - }, - ---Function to call before (un)comment - pre_hook = nil, - ---Function to call after (un)comment - post_hook = nil, - } +require("Comment").setup({ + ---Add a space b/w comment and the line + padding = true, + ---Whether the cursor should stay at its position + sticky = true, + ---Lines to be ignored while (un)comment + ignore = "^$", + ---LHS of toggle mappings in NORMAL mode + toggler = { + ---Line-comment toggle keymap + line = "gcc", + ---Block-comment toggle keymap + block = "gbc", + }, + ---LHS of operator-pending mappings in NORMAL and VISUAL mode + opleader = { + ---Line-comment keymap + line = "gc", + ---Block-comment keymap + block = "gb", + }, + ---LHS of extra mappings + extra = { + ---Add comment on the line above + above = "gcO", + ---Add comment on the line below + below = "gco", + ---Add comment at the end of line + eol = "gcA", + }, + ---Enable keybindings + ---NOTE: If given `false` then the plugin won't create any mappings + mappings = { + ---Operator-pending mapping; `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}` + basic = true, + ---Extra mapping; `gco`, `gcO`, `gcA` + extra = true, + ---Extended mapping; `g>` `g<` `g>[count]{motion}` `g<[count]{motion}` + extended = false, + }, + ---Function to call before (un)comment + pre_hook = nil, + ---Function to call after (un)comment + post_hook = nil, +}) + +-- cancel auto next line comment +-- 取消换行后自动添加注释 +vim.api.nvim_create_autocmd("BufEnter", { + callback = function() + vim.opt.formatoptions = vim.opt.formatoptions - { "o" } + end, +}) diff --git a/lua/plugin-config/table-mode.lua b/lua/plugin-config/table-mode.lua new file mode 100644 index 0000000..de51054 --- /dev/null +++ b/lua/plugin-config/table-mode.lua @@ -0,0 +1,5 @@ +local let_table_settings = {} + +for k, v in pairs(let_table_settings) do + vim.g[k] = v +end diff --git a/lua/plugin-config/toggleterm.lua b/lua/plugin-config/toggleterm.lua new file mode 100644 index 0000000..ac6d584 --- /dev/null +++ b/lua/plugin-config/toggleterm.lua @@ -0,0 +1,8 @@ +require("toggleterm").setup({ + open_mapping = [[]], + insert_mapping = true, + start_in_insert = true, + autochdir = true, + auto_scroll = false, -- automatically scroll to the bottom on terminal output + direction = "horizontal", +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index f3b0bf0..d6dc059 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -14,6 +14,10 @@ return require("packer").startup(function() end, }) + -- a good terminal + -- 一个好的nvim内终端 + use({ "akinsho/toggleterm.nvim", tag = "*" }) + -- git plugin like magit -- 类似magit的插件neogit -- use({ "TimUntersberger/neogit", requires = "nvim-lua/plenary.nvim" }) @@ -22,6 +26,17 @@ return require("packer").startup(function() -- 使用lazygit接口 use("kdheepak/lazygit.nvim") + ----------------- markdown -------------------- + -- markdown preview + -- markdown自动预览 + use({ + "iamcco/markdown-preview.nvim", + }) + + -- markdown table + -- 优化markdown添加表格 + use("dhruvasagar/vim-table-mode") + -- nvim-tree for file manage use({ "kyazdani42/nvim-tree.lua", diff --git a/readme.md b/readme.md index e69de29..8445f0d 100644 --- a/readme.md +++ b/readme.md @@ -0,0 +1,84 @@ +# Neovim 配置 + +这次决定从头开始打造自己的编辑器,其中所有的功能都是自行组装 + +使用的插件列表如下 + +| name | decription | +|---------------------------------|---------------------------------------------------------------------| +| nvim-telescope/telescope.nvim | 查找,过滤,预览文件 | +| kdheepak/lazygit.nvim | 与lazygit进行集成,需要自行安装lazygit,用法可参考lazygit的github页面 | +| nvim-treesitter/nvim-treesitter | 高性能的语法高亮 | +| folke/which-key.nvim | 快捷键弹窗查看和更方便的快捷键设置 | +| akinsho/bufferline.nvim | 顶部标签栏 | +| hrsh7th/nvim-cmp | 优秀的补全插件 | +| hrsh7th/cmp-path | 补全路径 | +| hrsh7th/cmp-buffer | 缓冲区内重复单词补全 | +| hrsh7th/cmp-nvim-lsp | 补全与lsp的集成 | +| kyazdani42/nvim-tree.lua | 文件查看器,不用多说 | +| numToStr/Comment.nvim | 强大的注释插件 | +| windwp/nvim-autopairs | 括号自动补全 | +| ahmedkhalf/project.nvim | 出色的项目管理工具,可与telescope集成 | +| jose-elias-alvarez/null-ls.nvim | 代码格式化工具,还可提供其他与lsp集成的功能 | +| neovim/nvim-lspconfig | 快速的lsp配置工具 | +| williamboman/mason.nvim | lsp-installer作者的新作,方便管理lsp dap linter formatter等 | +| rafamadriz/friendly-snippets | 自定义各种语言的一些代码模板 | +| nvim-lualine/lualine.nvim | 底部状态栏 | +| wbthomason/packer.nvim | 大名鼎鼎的包管理工具 | +| rcarriga/nvim-notify | 现代化的消息弹窗提示 | +| akinsho/toggleterm.nvim | 优秀的nvim集成终端 | +| mfussenegger/nvim-dap | neovim 的dap实现 | + + +## 快捷键 + \键被配置为空格 +### 常用 +| key | function | +|----------------|-------------------------------------------| +| n | 打开nvim-tree文件浏览 | +| f | 打开telescope进行文件查找 | +| Ctrl-h | 切换到左标签栏 | +| Ctrl-l | 切换到右标签栏 | +| \q | 退出neovim | +| \s | 保存当前文件 | +| \S | 保存所有文件 | +| \ | 切换回上一个buffer,用于两buffer间来回切换 | + +### Packer +| key | function | +|-------------|------------------------| +| \pi | 包同步PackerSync | +| \pc | 包清理PackerClean | +| \ps | 包状态查看PackerStatus | + +### lsp +| key | function | +|-------------|---------------------------------| +| \li | 安装当前文件语言对应的lsp服务 | +| \lI | 打开Mason安装lsp dap 等任意服务 | +| \ll | 打开Mason查看安装的服务 | +| \lu | 卸载当前语言对应的lsp | + +### git +| key | function | +|------------|-----------------| +| \g | 打开lazygit界面 | + +### dap +| key | function | +|-------------|-----------| +| \db | 打断点 | +| \de | 停止debug | +| \dc | 清理断点 | +| \dr | 开始debug | +| \ | step into | +| \ | step over | + + + + + + + + +