diff --git a/lua/G.lua b/lua/G.lua index c878293..fa1563b 100644 --- a/lua/G.lua +++ b/lua/G.lua @@ -1,55 +1,55 @@ local G = {} -G.g = vim.g -G.b = vim.b -G.o = vim.o -G.fn = vim.fn -G.api = vim.api -G.opt = vim.opt -G.loop = vim.loop -G.lb = vim.lsp.buf -G.dic = vim.diagnostic -G.cgp = vim.nvim_create_augroup +G.g = vim.g +G.b = vim.b +G.o = vim.o +G.fn = vim.fn +G.api = vim.api +G.opt = vim.opt +G.loop = vim.loop +G.lb = vim.lsp.buf +G.dic = vim.diagnostic +G.cgp = vim.nvim_create_augroup function G.map(maps) - for _,map in pairs(maps) do - if #map == 3 then - vim.keymap.set(map[1], map[2], map[3], {noremap = true}) - elseif #map == 4 then - vim.keymap.set(map[1], map[2], map[3], map[4]) - else - print("太多变量了") - end - --G.api.nvim_set_keymap(map[1], map[2], map[3], map[4]) + for _, map in pairs(maps) do + if #map == 3 then + vim.keymap.set(map[1], map[2], map[3], { noremap = true }) + elseif #map == 4 then + vim.keymap.set(map[1], map[2], map[3], map[4]) + else + print("太多变量了") end + --G.api.nvim_set_keymap(map[1], map[2], map[3], map[4]) + end end function G.delmap(maps) - for _,map in pairs(maps) do - if #map == 2 then - vim.keymap.del(map[1], map[2], {}) - elseif #map == 3 then - vim.keymap.del(map[1], map[2], map[3]) - else - print("太多变量了") - end + for _, map in pairs(maps) do + if #map == 2 then + vim.keymap.del(map[1], map[2], {}) + elseif #map == 3 then + vim.keymap.del(map[1], map[2], map[3]) + else + print("太多变量了") end + end end function G.cmd(cmd) - G.api.nvim_command(cmd) + G.api.nvim_command(cmd) end function G.exec(c) - G.api.nvim_exec(c) + G.api.nvim_exec(c) end function G.eval(c) - return G.api.nvim_eval(c) + return G.api.nvim_eval(c) end function G.au(even, opts) - return G.api.nvim_create_autocmd(even, opts) + return G.api.nvim_create_autocmd(even, opts) end G.g.mapleader = ' ' diff --git a/lua/keymap.lua b/lua/keymap.lua index ebfc582..7a972c2 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -1,45 +1,44 @@ -local opt = {noremap = true} +local opt = { noremap = true } -- base G.map({ -{'n', 'nh', ':nohlsearch', opt}, -{'n', 'rp', ':%s/',opt}, + { 'n', 'nh', ':nohlsearch', opt }, + { 'n', 'rp', ':%s/', opt }, -{'v', 'L', '$', opt}, -{'v', 'H', '^', opt}, -{'n', 'L', '$', opt}, -{'n', 'H', '^', opt}, -{'v', '>', '>gv', opt}, -{'v', '<', '', '>gv', opt }, + { 'v', '<', '', '>>', opt}, -{'n', '<', '<<', opt}, -{'n', '?', ':set hlsearch?', opt}, -{'n', '/', ':set hlsearch/', opt}, + { 'n', '>', '>>', opt }, + { 'n', '<', '<<', opt }, + { 'n', '?', ':set hlsearch?', opt }, + { 'n', '/', ':set hlsearch/', opt }, -{'n', '', ':tabn', opt}, -{'n', '', ':tabp', opt}, + { 'n', '', ':tabn', opt }, + { 'n', '', ':tabp', opt }, -{'n', '', 'j', opt}, -{'n', '', 'h', opt}, -{'n', '', 'k', opt}, -{'n', '', 'l', opt}, + { 'n', '', 'j', opt }, + { 'n', '', 'h', opt }, + { 'n', '', 'k', opt }, + { 'n', '', 'l', opt }, -{'n', '', ':q', opt}, -{'n', '', ':w !sudo tee %', opt}, -{'n', '', ':q!', opt}, + { 'n', '', ':q', opt }, + { 'n', '', ':w !sudo tee %', opt }, + { 'n', '', ':q!', opt }, -{'n', 'y', 'ggyG', opt}, -{'n', 'p', 'ggpG', opt}, -{'n', 'v', 'ggVG', opt}, + { 'n', 'y', 'ggyG', opt }, + { 'n', 'p', 'ggpG', opt }, + { 'n', 'v', 'ggVG', opt }, -{'n', '', ':res -5', opt}, -{'n', '', ':res +5', opt}, -{'n', '', ':vertical resize -5', opt}, -{'n', '', ':vertical resize +5', opt}, + { 'n', '', ':res -5', opt }, + { 'n', '', ':res +5', opt }, + { 'n', '', ':vertical resize -5', opt }, + { 'n', '', ':vertical resize +5', opt }, }) - diff --git a/lua/options.lua b/lua/options.lua index 3227312..ed023f0 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,38 +1,38 @@ -- -G.opt.ttimeout = true -G.opt.ttimeoutlen = 100 +G.opt.ttimeout = true +G.opt.ttimeoutlen = 100 -- 行号 -G.opt.nu = true -G.opt.rnu = true -G.opt.scrolloff = 999 +G.opt.nu = true +G.opt.rnu = true +G.opt.scrolloff = 999 -- 自动保存 -G.opt.autowrite = true -G.opt.autowriteall = true +G.opt.autowrite = true +G.opt.autowriteall = true -- tab键 -G.opt.sw = 2 -G.opt.ts = 2 -G.opt.softtabstop = 2 -G.opt.smarttab = true -G.opt.expandtab = true -G.opt.autoindent = true +G.opt.sw = 2 +G.opt.ts = 2 +G.opt.softtabstop = 2 +G.opt.smarttab = true +G.opt.expandtab = true +G.opt.autoindent = true -- 光标 -G.opt.cursorline = true +G.opt.cursorline = true -- 分屏 -G.opt.splitright = true -G.opt.splitbelow = true +G.opt.splitright = true +G.opt.splitbelow = true -- 搜索 -G.opt.ignorecase = true -G.opt.incsearch = true +G.opt.ignorecase = true +G.opt.incsearch = true -- 不换行 -G.opt.textwidth = 999 -G.opt.wrap = false +G.opt.textwidth = 999 +G.opt.wrap = false -- 文件判断 @@ -40,27 +40,27 @@ G.cmd("filetype plugin indent on") -- 取消换行注释 G.au({ "BufEnter" }, { - pattern = { "*" }, - callback = function() - -- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" } - G.opt.formatoptions = G.opt.formatoptions - - "o" -- O and o, don't continue comments - + "r" -- But do continue when pressing enter. - end, + pattern = { "*" }, + callback = function() + -- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" } + G.opt.formatoptions = G.opt.formatoptions + - "o" -- O and o, don't continue comments + + "r" -- But do continue when pressing enter. + end, }) G.au({ "InsertEnter" }, { - pattern = { "*" }, - callback = function() + pattern = { "*" }, + callback = function() G.opt.hlsearch = false - end, + end, }) G.au({ "VimEnter" }, { - pattern = { "*.code-snippets" }, - callback = function() + pattern = { "*.code-snippets" }, + callback = function() G.cmd("setfiletype json") - end, + end, }) -- G.au({ @@ -69,6 +69,3 @@ G.au({ "VimEnter" }, { -- if index -- } -- }) - - - diff --git a/lua/plugs.lua b/lua/plugs.lua index 416bd00..ee43984 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -7,7 +7,7 @@ return { build = ":TSUpdate html", dependencies = { "nvim-telescope/telescope.nvim", - "nvim-lua/plenary.nvim", -- telescope 所需 + "nvim-lua/plenary.nvim", -- telescope 所需 "MunifTanjim/nui.nvim", -- 可选 diff --git a/lua/plugs/edit-plugs.lua b/lua/plugs/edit-plugs.lua index f50bfe4..55aa04c 100644 --- a/lua/plugs/edit-plugs.lua +++ b/lua/plugs/edit-plugs.lua @@ -52,7 +52,7 @@ return { -- end -- }, { - -- hop + -- hop require("plugs.hop") } } diff --git a/lua/plugs/hop.lua b/lua/plugs/hop.lua index 40688a6..d67541b 100644 --- a/lua/plugs/hop.lua +++ b/lua/plugs/hop.lua @@ -2,49 +2,49 @@ return { "phaazon/hop.nvim", branch = "v2", keys = { - "f","F","t","T", + "f", "F", "t", "T", "" }, lazy = true, - config = function () - require("hop").setup{keys = 'asdfghjkl;'} + config = function() + require("hop").setup { keys = 'asdfghjkl;' } local hop = require('hop') local directions = require('hop.hint').HintDirection G.map({ - {"n", "", ":HopChar2MW", {noremap = true}}, - {"n", "f", - function () + { "n", "", ":HopChar2MW", { noremap = true } }, + { "n", "f", + function() hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true }) - end, {noremap = true} + end, { noremap = true } }, - {"n", "F", - function () + { "n", "F", + function() hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true }) - end, {noremap = true} + end, { noremap = true } }, - {"n", "t", - function () + { "n", "t", + function() hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true, hint_offset = -1 }) - end, {noremap = true} + end, { noremap = true } }, - {"n", "T", - function () + { "n", "T", + function() hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true, hint_offset = -1 }) - end, {noremap = true} + end, { noremap = true } }, }) end diff --git a/lua/plugs/nvimtree.lua b/lua/plugs/nvimtree.lua index 9a459c9..c2f2607 100644 --- a/lua/plugs/nvimtree.lua +++ b/lua/plugs/nvimtree.lua @@ -7,8 +7,7 @@ return { "" }, config = function() - - require 'nvim-web-devicons'.setup{} + require 'nvim-web-devicons'.setup {} require 'nvim-tree'.setup { sort_by = "case_sensitive", diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua index 4e574d6..013bed5 100644 --- a/lua/plugs/theme.lua +++ b/lua/plugs/theme.lua @@ -1,83 +1,82 @@ return { { 'folke/tokyonight.nvim', - config = function () + config = function() G.cmd("colorscheme tokyonight") -- 主题 - G.opt.background = 'dark' -- 背景 + G.opt.background = 'dark' -- 背景 end }, { -- line插件 'kdheepak/tabline.nvim', 'nvim-lualine/lualine.nvim', - config = function() - require('lualine').setup { - options = { - icons_enabled = true, - theme = 'auto', - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } + config = function() + require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + disabled_filetypes = { + statusline = {}, + winbar = {}, }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {{ - 'filename', - file_status = false, - path = 1 - }}, - lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_y = {'progress'}, - lualine_z = {} - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {'filename'}, - lualine_x = {'location'}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} - } - require('tabline').setup { - -- Defaults configuration options - enable = true, - options = { - -- If lualine is installed tabline will use separators configured in lualine by default. - -- These options can be used to override those settings. - section_separators = {' ', ' '}, - component_separators = {'', ''}, - max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 - show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named - show_devicons = true, -- this shows devicons in buffer section - show_bufnr = false, -- this appends [bufnr] to buffer section, - show_filename_only = true, -- shows base filename only instead of relative path in filename - modified_icon = "+ ", -- change the default modified icon - modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified - show_tabs_only = false, -- this shows only tabs instead of tabs + buffers - }, - G.cmd[[ + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = { { + 'filename', + file_status = false, + path = 1 + } }, + lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_y = { 'progress' }, + lualine_z = {} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} + } + require('tabline').setup { + -- Defaults configuration options + enable = true, + options = { + -- If lualine is installed tabline will use separators configured in lualine by default. + -- These options can be used to override those settings. + section_separators = { ' ', ' ' }, + component_separators = { '', '' }, + max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 + show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named + show_devicons = true, -- this shows devicons in buffer section + show_bufnr = false, -- this appends [bufnr] to buffer section, + show_filename_only = true, -- shows base filename only instead of relative path in filename + modified_icon = "+ ", -- change the default modified icon + modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified + show_tabs_only = false, -- this shows only tabs instead of tabs + buffers + }, + G.cmd [[ set guioptions-=e " Use showtabline in gui vim set sessionoptions+=tabpages,globals " store tabpages and globals in session ]] - } + } end, }, } - diff --git a/lua/plugs/toggleterm.lua b/lua/plugs/toggleterm.lua index 78b4781..e50069d 100644 --- a/lua/plugs/toggleterm.lua +++ b/lua/plugs/toggleterm.lua @@ -1,22 +1,22 @@ return { -- amongst your other plugins - { 'akinsho/toggleterm.nvim', + { + 'akinsho/toggleterm.nvim', version = "*", - config = function () - require("toggleterm").setup{ + config = function() + require("toggleterm").setup { -- size can be a number or function which is passed the current terminal size = 10, open_mapping = [[]], hide_numbers = true, -- hide the number column in toggleterm buffers shade_filetypes = {}, shade_terminals = true, - shading_factor = 1, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + shading_factor = 1, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light start_in_insert = true, insert_mappings = true, -- whether or not the open mapping applies in insert mode persist_size = true, direction = 'horizontal', } - end }, diff --git a/lua/vscode.lua b/lua/vscode.lua index d60af1f..5c91e6a 100644 --- a/lua/vscode.lua +++ b/lua/vscode.lua @@ -1,4 +1,4 @@ -require'lazy'.setup({ +require 'lazy'.setup({ require("plugs.hop"), require('plugs.edit-plugs'), diff --git a/snippets/c.json b/snippets/c.json new file mode 100644 index 0000000..94d29ce --- /dev/null +++ b/snippets/c.json @@ -0,0 +1,26 @@ +{ + "for": { + "prefix": "for", + "body": [ + " for(int $1 = $2; $1 < $3; $1+=$4) {", + " $5", + " }" + ] + }, + "for1": { + "prefix": "for1", + "body": [ + " for(int $1 = $2; $1 < $3; $1++) {", + " $4", + " }" + ] + }, + "fori": { + "prefix": "fori", + "body": [ + " for(int i = $1; i < $2; i++) {", + " $3", + " }" + ] + } +} diff --git a/snippets/json.json b/snippets/json.json new file mode 100644 index 0000000..59098d5 --- /dev/null +++ b/snippets/json.json @@ -0,0 +1,13 @@ +{ + "mod": { + "prefix": "mod", + "body": [ + " \"$1\": {", + " \"prefix\": \"$1\",", + " \"body\": [", + " $2", + " ]", + " }" + ] + } +} diff --git a/snippets/lua.json b/snippets/lua.json index fd8e4ce..0db3279 100644 --- a/snippets/lua.json +++ b/snippets/lua.json @@ -1,32 +1,3 @@ { - "Class_Array_tree": { - "prefix": "Class_Array_tree", - "body": [ - "", - "template ", - "class Array_tree {", - " public:", - " Array_tree() {}", - " Array_tree(int n) { this->n = n, tree = vector(n + 1); }", - " void add(int id, T key) {", - " for (int i = id; i <= n; i += lowbit(i)) tree[i] += key;", - " }", - "", - " T get_sum(int id) {", - " T sum = 0;", - " for (int i = id; i; i -= lowbit(i)) sum += tree[i];", - " return sum;", - " }", - "", - " T get_sum(int l, int r) { return get_sum(r) - get_sum(l - 1); }", - "", - " private:", - " int n;", - " vector tree;", - " int lowbit(int x) { return x & -x; }", - "};", - "" - ] - } -} + }