diff --git a/.stylua.toml b/.stylua.toml index f608111..4b13416 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -3,4 +3,4 @@ line_endings = "Unix" indent_type = "Spaces" indent_width = 2 quote_style = "AutoPreferDouble" -no_call_parentheses = true +call_parentheses= "NoSingleTable" diff --git a/core/colorschemes.lua b/core/colorschemes.lua index a3cae78..1afacf0 100644 --- a/core/colorschemes.lua +++ b/core/colorschemes.lua @@ -1,6 +1,6 @@ --- This module will load a random colorscheme on nvim startup process. -local utils = require('utils') +local utils = require("utils") local M = {} @@ -8,16 +8,16 @@ local M = {} -- the same as the colorscheme name itself. M.colorscheme2dir = { gruvbox8 = "vim-gruvbox8", - onedark = 'onedark.nvim', - edge = 'edge', - sonokai = 'sonokai', - gruvbox_material = 'gruvbox-material', - nord = 'nord.nvim', - doom_one = 'doom-one.nvim', - everforest = 'everforest', - nightfox = 'nightfox.nvim', - kanagawa = 'kanagawa.nvim', - catppuccin = 'catppuccin' + onedark = "onedark.nvim", + edge = "edge", + sonokai = "sonokai", + gruvbox_material = "gruvbox-material", + nord = "nord.nvim", + doom_one = "doom-one.nvim", + everforest = "everforest", + nightfox = "nightfox.nvim", + kanagawa = "kanagawa.nvim", + catppuccin = "catppuccin", } M.gruvbox8 = function() @@ -28,57 +28,55 @@ M.gruvbox8 = function() vim.g.gruvbox_filetype_hi_groups = 1 vim.g.gruvbox_plugin_hi_groups = 1 - vim.cmd [[colorscheme gruvbox8_hard]] + vim.cmd([[colorscheme gruvbox8_hard]]) end M.onedark = function() - vim.cmd [[colorscheme onedark]] + vim.cmd([[colorscheme onedark]]) end M.edge = function() vim.g.edge_enable_italic = 1 vim.g.edge_better_performance = 1 - vim.cmd [[colorscheme edge]] + vim.cmd([[colorscheme edge]]) end M.sonokai = function() vim.g.sonokai_enable_italic = 1 vim.g.sonokai_better_performance = 1 - vim.cmd [[colorscheme sonokai]] + vim.cmd([[colorscheme sonokai]]) end M.gruvbox_material = function() vim.g.gruvbox_material_enable_italic = 1 vim.g.gruvbox_material_better_performance = 1 - vim.cmd [[colorscheme gruvbox-material]] + vim.cmd([[colorscheme gruvbox-material]]) end M.nord = function() - vim.cmd [[colorscheme nord]] + vim.cmd([[colorscheme nord]]) end M.doom_one = function() - - vim.cmd [[colorscheme doom-one]] + vim.cmd([[colorscheme doom-one]]) end M.everforest = function() vim.g.everforest_enable_italic = 1 vim.g.everforest_better_performance = 1 - vim.cmd [[colorscheme everforest]] + vim.cmd([[colorscheme everforest]]) end M.nightfox = function() - vim.cmd [[colorscheme nordfox]] + vim.cmd([[colorscheme nordfox]]) end - M.kanagawa = function() - vim.cmd [[colorscheme kanagawa]] + vim.cmd([[colorscheme kanagawa]]) end M.catppuccin = function() @@ -87,17 +85,16 @@ M.catppuccin = function() require("catppuccin").setup() - vim.cmd [[colorscheme catppuccin]] + vim.cmd([[colorscheme catppuccin]]) end - --- Use a random colorscheme from the pre-defined list of colorschemes. -M.rand_colorscheme = function () +M.rand_colorscheme = function() local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme2dir)) if not vim.tbl_contains(vim.tbl_keys(M), colorscheme) then local msg = "Invalid colorscheme: " .. colorscheme - vim.notify(msg, vim.log.levels.ERROR, { title = 'nvim-config' }) + vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" }) return end @@ -107,7 +104,7 @@ M.rand_colorscheme = function () if not status then local msg = string.format("Colorscheme %s is not installed. Run PackerSync to install.", colorscheme) - vim.notify(msg, vim.log.levels.ERROR, { title = 'nvim-config' }) + vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" }) return end @@ -115,10 +112,10 @@ M.rand_colorscheme = function () -- Load the colorscheme and its settings M[colorscheme]() - if vim.g.logging_level == 'debug' then + if vim.g.logging_level == "debug" then local msg = "Colorscheme: " .. colorscheme - vim.notify(msg, vim.log.levels.DEBUG, { title = 'nvim-config' }) + vim.notify(msg, vim.log.levels.DEBUG, { title = "nvim-config" }) end end diff --git a/core/mappings.lua b/core/mappings.lua index 82a3a2b..380d42d 100644 --- a/core/mappings.lua +++ b/core/mappings.lua @@ -11,30 +11,30 @@ keymap.set("i", "", "viwUea") keymap.set("i", "", "b~lea") -- Paste non-linewise text above or below current line, see https://stackoverflow.com/a/1346777/6064933 -keymap.set("n", "p", "m`op``", { desc = "paste below current line", }) -keymap.set("n", "P", "m`Op``", { desc = "paste above current line", }) +keymap.set("n", "p", "m`op``", { desc = "paste below current line" }) +keymap.set("n", "P", "m`Op``", { desc = "paste above current line" }) -- Shortcut for faster save and quit -keymap.set("n", "w", "update", { silent = true, desc = "save buffer", }) +keymap.set("n", "w", "update", { silent = true, desc = "save buffer" }) -- Saves the file if modified and quit keymap.set("n", "q", "x", { silent = true, desc = "quit current window" }) -- Quit all opened buffers -keymap.set("n", "Q", "qa!", { silent = true, desc = "quit nvim", }) +keymap.set("n", "Q", "qa!", { silent = true, desc = "quit nvim" }) -- Navigation in the location and quickfix list -keymap.set("n", "[l", "lpreviouszv", { silent = true, desc = "previous location item", }) -keymap.set("n", "]l", "lnextzv", { silent = true, desc = "next location item", }) +keymap.set("n", "[l", "lpreviouszv", { silent = true, desc = "previous location item" }) +keymap.set("n", "]l", "lnextzv", { silent = true, desc = "next location item" }) -keymap.set("n", "[L", "lfirstzv", { silent = true, desc = "first location item", }) -keymap.set("n", "]L", "llastzv", { silent = true, desc = "last location item", }) +keymap.set("n", "[L", "lfirstzv", { silent = true, desc = "first location item" }) +keymap.set("n", "]L", "llastzv", { silent = true, desc = "last location item" }) -keymap.set("n", "[q", "cpreviouszv", { silent = true, desc = "previous qf item", }) -keymap.set("n", "]q", "cnextzv", { silent = true, desc = "next qf item", }) +keymap.set("n", "[q", "cpreviouszv", { silent = true, desc = "previous qf item" }) +keymap.set("n", "]q", "cnextzv", { silent = true, desc = "next qf item" }) -keymap.set("n", "[Q", "cfirstzv", { silent = true, desc = "first qf item", }) -keymap.set("n", "]Q", "clastzv", { silent = true, desc = "last qf item", }) +keymap.set("n", "[Q", "cfirstzv", { silent = true, desc = "first qf item" }) +keymap.set("n", "]Q", "clastzv", { silent = true, desc = "last qf item" }) -- Close location list or quickfix list if they are present, see https://superuser.com/q/355325/736190 keymap.set("n", [[\x]], "windo lclose cclose ", { @@ -89,10 +89,10 @@ keymap.set("n", "sv", "", { silent = true, desc = "reload init.lua", callback = function() - vim.cmd [[ + vim.cmd([[ update $MYVIMRC source $MYVIMRC - ]] + ]]) vim.notify("Nvim config successfully reloaded!", vim.log.levels.INFO, { title = "nvim-config" }) end, }) @@ -111,14 +111,14 @@ keymap.set("n", "/", [[/\v]]) -- Change current working directory locally and print cwd after that, -- see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file -keymap.set("n", "cd", "lcd %:p:hpwd", { desc = "change cwd", }) +keymap.set("n", "cd", "lcd %:p:hpwd", { desc = "change cwd" }) -- Use Esc to quit builtin terminal keymap.set("t", "", [[]]) -- Toggle spell checking -keymap.set("n", "", "set spell!", { desc = "toggle spell", }) -keymap.set("i", "", "set spell!", { desc = "toggle spell", }) +keymap.set("n", "", "set spell!", { desc = "toggle spell" }) +keymap.set("i", "", "set spell!", { desc = "toggle spell" }) -- Change text without putting it into the vim register, -- see https://stackoverflow.com/q/54255/6064933 @@ -128,25 +128,25 @@ keymap.set("n", "cc", '"_cc') keymap.set("x", "c", '"_c') -- Remove trailing whitespace characters -keymap.set("n", "", "StripTrailingWhitespace", { desc = "remove trailing space", }) +keymap.set("n", "", "StripTrailingWhitespace", { desc = "remove trailing space" }) -- check the syntax group of current cursor position -keymap.set("n", "st", "call utils#SynGroup()", { desc = "check syntax group", }) +keymap.set("n", "st", "call utils#SynGroup()", { desc = "check syntax group" }) -- Copy entire buffer. -keymap.set("n", "y", "%yank", { desc = "yank entire buffer", }) +keymap.set("n", "y", "%yank", { desc = "yank entire buffer" }) -- Toggle cursor column -keymap.set("n", "cl", "call utils#ToggleCursorCol()", { desc = "toggle cursor column", }) +keymap.set("n", "cl", "call utils#ToggleCursorCol()", { desc = "toggle cursor column" }) -- Move current line up and down -keymap.set("n", "", 'call utils#SwitchLine(line("."), "up")', { desc = "move line up", }) -keymap.set("n", "", 'call utils#SwitchLine(line("."), "down")', { desc = "move line down", }) +keymap.set("n", "", 'call utils#SwitchLine(line("."), "up")', { desc = "move line up" }) +keymap.set("n", "", 'call utils#SwitchLine(line("."), "down")', { desc = "move line down" }) -- Move current visual-line selection up and down -keymap.set("x", "", 'call utils#MoveSelection("up")', { desc = "move selection up", }) +keymap.set("x", "", 'call utils#MoveSelection("up")', { desc = "move selection up" }) -keymap.set("x", "", 'call utils#MoveSelection("down")', { desc = "move selection down", }) +keymap.set("x", "", 'call utils#MoveSelection("down")', { desc = "move selection down" }) -- Replace visual selection with text in register, but not contaminate the register, -- see also https://stackoverflow.com/q/10723700/6064933. @@ -167,19 +167,19 @@ keymap.set("n", "", "k") keymap.set("n", "", "j") -- Text objects for URL -keymap.set({ "x", "o" }, "iu", "call text_obj#URL()", { desc = "URL text object", }) +keymap.set({ "x", "o" }, "iu", "call text_obj#URL()", { desc = "URL text object" }) -- Text objects for entire buffer -keymap.set({ "x", "o" }, "iB", "call text_obj#Buffer()", { desc = "buffer text object", }) +keymap.set({ "x", "o" }, "iB", "call text_obj#Buffer()", { desc = "buffer text object" }) -- Do not move my cursor when joining lines. keymap.set("n", "J", "", { desc = "join line", callback = function() - vim.cmd [[ + vim.cmd([[ normal! mzJ`z delmarks z - ]] + ]]) end, }) @@ -187,42 +187,42 @@ keymap.set("n", "gJ", "mzgJ`z", { desc = "join visual lines", callback = function() -- we must use `normal!`, otherwise it will trigger recursive mapping - vim.cmd [[ + vim.cmd([[ normal! zmgJ`z delmarks z - ]] - end + ]]) + end, }) -- Break inserted text into smaller undo units when we insert some punctuation chars. -local undo_ch = { ',', '.', '!', '?', ';', ':' } +local undo_ch = { ",", ".", "!", "?", ";", ":" } for _, ch in ipairs(undo_ch) do - keymap.set('i', ch, ch .. 'u') + keymap.set("i", ch, ch .. "u") end -- insert semicolon in the end -keymap.set('i', '', 'miA;`ii') +keymap.set("i", "", "miA;`ii") -- Keep cursor position after yanking -keymap.set('n', 'y', 'myy') +keymap.set("n", "y", "myy") -api.nvim_create_autocmd('TextYankPost', { - pattern = '*', +api.nvim_create_autocmd("TextYankPost", { + pattern = "*", group = api.nvim_create_augroup("restore_after_yank", { clear = true }), callback = function() - vim.cmd [[ + vim.cmd([[ silent! normal! `y silent! delmarks y - ]] - end + ]]) + end, }) -- Go to the beginning and end of current line in insert mode quickly -keymap.set('i', '', '') -keymap.set('i', '', '') +keymap.set("i", "", "") +keymap.set("i", "", "") -- Go to beginning of command in command-line mode -keymap.set('c', '', '') +keymap.set("c", "", "") -- Delete the character to the right of the cursor -keymap.set('i', '', '') +keymap.set("i", "", "") diff --git a/init.lua b/init.lua index de5909b..658d3ce 100644 --- a/init.lua +++ b/init.lua @@ -9,7 +9,7 @@ -- Blog: https://jdhao.github.io/ local api = vim.api -local utils = require "utils" +local utils = require("utils") -- check if we have the latest stable version of nvim local expected_ver = "0.7.2" @@ -22,17 +22,17 @@ if nvim_ver ~= expected_ver then end local core_conf_files = { - "globals.vim", -- some global settings - "options.vim", -- setting options in nvim - "autocommands.vim", -- various autocommands - "mappings.lua", -- all the user-defined mappings - "plugins.vim", -- all the plugins installed and their configurations - "colorschemes.lua", -- colorscheme settings + "globals.vim", -- some global settings + "options.vim", -- setting options in nvim + "autocommands.vim", -- various autocommands + "mappings.lua", -- all the user-defined mappings + "plugins.vim", -- all the plugins installed and their configurations + "colorschemes.lua", -- colorscheme settings } -- source all the core config files for _, name in ipairs(core_conf_files) do - local path = string.format("%s/core/%s", vim.fn.stdpath('config'), name) + local path = string.format("%s/core/%s", vim.fn.stdpath("config"), name) local source_cmd = "source " .. path vim.cmd(source_cmd) end diff --git a/lua/config/bqf.lua b/lua/config/bqf.lua index bf4bf58..c62a513 100644 --- a/lua/config/bqf.lua +++ b/lua/config/bqf.lua @@ -1,6 +1,6 @@ -require("bqf").setup({ +require("bqf").setup { auto_resize_height = false, preview = { auto_preview = false, - } -}) + }, +} diff --git a/lua/config/bufferline.lua b/lua/config/bufferline.lua index b68cfa8..9089a83 100644 --- a/lua/config/bufferline.lua +++ b/lua/config/bufferline.lua @@ -1,4 +1,4 @@ -require("bufferline").setup({ +require("bufferline").setup { options = { numbers = "buffer_id", close_command = "bdelete! %d", @@ -6,8 +6,8 @@ require("bufferline").setup({ left_mouse_command = "buffer %d", middle_mouse_command = nil, indicator = { - icon = '▎', -- this should be omitted if indicator style is not 'icon' - style = 'icon', + icon = "▎", -- this should be omitted if indicator style is not 'icon' + style = "icon", }, buffer_close_icon = "", modified_icon = "●", @@ -43,4 +43,4 @@ require("bufferline").setup({ always_show_bufferline = true, sort_by = "id", }, -}) +} diff --git a/lua/config/dashboard-nvim.lua b/lua/config/dashboard-nvim.lua index 5dff685..9329953 100644 --- a/lua/config/dashboard-nvim.lua +++ b/lua/config/dashboard-nvim.lua @@ -52,8 +52,8 @@ dashboard.custom_center = { desc = "Quit Nvim ", -- desc = "Quit Nvim ", action = "qa", - shortcut = "q " - } + shortcut = "q ", + }, } vim.cmd([[ diff --git a/lua/config/fidget-nvim.lua b/lua/config/fidget-nvim.lua index 5225f06..945f564 100644 --- a/lua/config/fidget-nvim.lua +++ b/lua/config/fidget-nvim.lua @@ -1 +1 @@ -require"fidget".setup{} +require("fidget").setup {} diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua index 40a9208..13ffaff 100644 --- a/lua/config/fugitive.lua +++ b/lua/config/fugitive.lua @@ -1,8 +1,8 @@ local keymap = vim.keymap -keymap.set('n', 'gs', 'Git', { desc = 'Git status' }) -keymap.set('n', 'gw', 'Gwrite', { desc = 'Git add' }) -keymap.set('n', 'gc', 'Git commit', { desc = 'Git commit' }) -keymap.set('n', 'gd', 'Gdiffsplit', { desc = 'Git diff' }) -keymap.set('n', 'gpl', 'Git pull', { desc = 'Git pull' }) -keymap.set('n', 'gpu', '15 split|term git push', { desc = 'Git push' }) +keymap.set("n", "gs", "Git", { desc = "Git status" }) +keymap.set("n", "gw", "Gwrite", { desc = "Git add" }) +keymap.set("n", "gc", "Git commit", { desc = "Git commit" }) +keymap.set("n", "gd", "Gdiffsplit", { desc = "Git diff" }) +keymap.set("n", "gpl", "Git pull", { desc = "Git pull" }) +keymap.set("n", "gpu", "15 split|term git push", { desc = "Git push" }) diff --git a/lua/config/git-linker.lua b/lua/config/git-linker.lua index f19210b..e2f7607 100644 --- a/lua/config/git-linker.lua +++ b/lua/config/git-linker.lua @@ -1,15 +1,15 @@ local keymap = vim.keymap -local gitlinker = require('gitlinker') +local gitlinker = require("gitlinker") -gitlinker.setup({ +gitlinker.setup { mappings = nil, -}) +} -keymap.set({ 'n', 'v' }, 'gl', '', { +keymap.set({ "n", "v" }, "gl", "", { silent = true, desc = "get git permlink", callback = function() local mode = string.lower(vim.fn.mode()) gitlinker.get_buf_range_url(mode) - end + end, }) diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua index 0543412..81f6b57 100644 --- a/lua/config/gitsigns.lua +++ b/lua/config/gitsigns.lua @@ -1,4 +1,4 @@ -local gs = require "gitsigns" +local gs = require("gitsigns") gs.setup { signs = { @@ -25,7 +25,7 @@ gs.setup { gs.next_hunk() end) return "" - end, { expr = true, desc = 'next hunk' }) + end, { expr = true, desc = "next hunk" }) map("n", "[c", function() if vim.wo.diff then @@ -35,10 +35,12 @@ gs.setup { gs.prev_hunk() end) return "" - end, { expr = true, desc = 'previous hunk' }) + end, { expr = true, desc = "previous hunk" }) -- Actions map("n", "hp", gs.preview_hunk) - map("n", "hb", function() gs.blame_line { full = true } end) + map("n", "hb", function() + gs.blame_line { full = true } + end) end, } diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index f5c76ad..13541c4 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -1,12 +1,12 @@ local api = vim.api local keymap = vim.keymap -local hlslens = require('hlslens') +local hlslens = require("hlslens") -hlslens.setup({ +hlslens.setup { calm_down = true, nearest_only = true, -}) +} local activate_hlslens = function(direction) local cmd = string.format("normal! %s%szzzv", vim.v.count1, direction) @@ -22,13 +22,17 @@ local activate_hlslens = function(direction) hlslens.start() end -keymap.set('n', 'n', '', { - callback = function() activate_hlslens('n') end +keymap.set("n", "n", "", { + callback = function() + activate_hlslens("n") + end, }) -keymap.set('n', 'N', '', { - callback = function() activate_hlslens('N') end +keymap.set("n", "N", "", { + callback = function() + activate_hlslens("N") + end, }) -keymap.set('n', '*', "(asterisk-z*)lua require('hlslens').start()") -keymap.set('n', '#', "(asterisk-z#)lua require('hlslens').start()") +keymap.set("n", "*", "(asterisk-z*)lua require('hlslens').start()") +keymap.set("n", "#", "(asterisk-z#)lua require('hlslens').start()") diff --git a/lua/config/indent-blankline.lua b/lua/config/indent-blankline.lua index 597b508..3c4a33d 100644 --- a/lua/config/indent-blankline.lua +++ b/lua/config/indent-blankline.lua @@ -1,7 +1,7 @@ local api = vim.api local exclude_ft = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha" } -require("indent_blankline").setup({ +require("indent_blankline").setup { -- U+2502 may also be a good choice, it will be on the middle of cursor. -- U+250A is also a good choice char = "▏", @@ -9,13 +9,13 @@ require("indent_blankline").setup({ disable_with_nolist = true, buftype_exclude = { "terminal" }, filetype_exclude = exclude_ft, -}) +} local gid = api.nvim_create_augroup("indent_blankline", { clear = true }) api.nvim_create_autocmd("InsertEnter", { pattern = "*", group = gid, - command = "IndentBlanklineDisable" + command = "IndentBlanklineDisable", }) api.nvim_create_autocmd("InsertLeave", { @@ -23,7 +23,7 @@ api.nvim_create_autocmd("InsertLeave", { group = gid, callback = function() if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then - vim.cmd [[IndentBlanklineEnable]] + vim.cmd([[IndentBlanklineEnable]]) end - end + end, }) diff --git a/lua/config/iron.lua b/lua/config/iron.lua index 74d7046..67f5d81 100644 --- a/lua/config/iron.lua +++ b/lua/config/iron.lua @@ -1,7 +1,7 @@ local iron = require("iron") -iron.core.set_config({ +iron.core.set_config { preferred = { python = "ipython", }, repl_open_cmd = "vertical 120 split", -}) +} diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 76436a4..0fad17a 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -14,37 +14,41 @@ local custom_attach = function(client, bufnr) keymap.set(mode, l, r, opts) end - map("n", "gd", vim.lsp.buf.definition, {desc = 'go to definition'}) + map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) map("n", "", vim.lsp.buf.definition) map("n", "K", vim.lsp.buf.hover) map("n", "", vim.lsp.buf.signature_help) - map("n", "rn", vim.lsp.buf.rename, { desc = 'varialbe rename' }) - map("n", "gr", vim.lsp.buf.references, { desc = 'show references' }) - map("n", "[d", vim.diagnostic.goto_prev, { desc = 'previous diagnostic' }) - map("n", "]d", vim.diagnostic.goto_next, { desc = 'next diagnostic' }) - map("n", "q", function() vim.diagnostic.setqflist({open = true}) end, { desc = 'put diagnostic to qf' }) - map("n", "ca", vim.lsp.buf.code_action, { desc = 'LSP code action' }) - map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = 'add workspace folder' } ) - map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = 'remove workspace folder' }) - map("n", "wl", function() inspect(vim.lsp.buf.list_workspace_folders()) end, { desc = 'list workspace folder' }) + map("n", "rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) + map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) + map("n", "[d", vim.diagnostic.goto_prev, { desc = "previous diagnostic" }) + map("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic" }) + map("n", "q", function() + vim.diagnostic.setqflist { open = true } + end, { desc = "put diagnostic to qf" }) + map("n", "ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) + map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) + map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) + map("n", "wl", function() + inspect(vim.lsp.buf.list_workspace_folders()) + end, { desc = "list workspace folder" }) -- Set some key bindings conditional on server capabilities if client.resolved_capabilities.document_formatting then - map("n", "f", vim.lsp.buf.formatting_sync, { desc = 'format code' }) + map("n", "f", vim.lsp.buf.formatting_sync, { desc = "format code" }) end if client.resolved_capabilities.document_range_formatting then - map("x", "f", vim.lsp.buf.range_formatting, { desc = 'range format' }) + map("x", "f", vim.lsp.buf.range_formatting, { desc = "range format" }) end api.nvim_create_autocmd("CursorHold", { - buffer=bufnr, + buffer = bufnr, callback = function() local float_opts = { focusable = false, close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = 'rounded', - source = 'always', -- show source in diagnostic popup window - prefix = ' ' + border = "rounded", + source = "always", -- show source in diagnostic popup window + prefix = " ", } if not vim.b.diagnostics_pos then @@ -52,14 +56,15 @@ local custom_attach = function(client, bufnr) end local cursor_pos = api.nvim_win_get_cursor(0) - if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) and - #vim.diagnostic.get() > 0 + if + (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) + and #vim.diagnostic.get() > 0 then - vim.diagnostic.open_float(nil, float_opts) + vim.diagnostic.open_float(nil, float_opts) end vim.b.diagnostics_pos = cursor_pos - end + end, }) -- The blow command will highlight the current variable and its usages in the buffer. @@ -76,20 +81,20 @@ local custom_attach = function(client, bufnr) ]]) end - if vim.g.logging_level == 'debug' then + if vim.g.logging_level == "debug" then local msg = string.format("Language server %s started!", client.name) - vim.notify(msg, vim.log.levels.DEBUG, {title = 'Nvim-config'}) + vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" }) end end local capabilities = lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = true local lspconfig = require("lspconfig") -if utils.executable('pylsp') then - lspconfig.pylsp.setup({ +if utils.executable("pylsp") then + lspconfig.pylsp.setup { on_attach = custom_attach, settings = { pylsp = { @@ -107,9 +112,9 @@ if utils.executable('pylsp') then debounce_text_changes = 200, }, capabilities = capabilities, - }) + } else - vim.notify("pylsp not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) + vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end -- if utils.executable('pyright') then @@ -121,43 +126,43 @@ end -- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) -- end -if utils.executable('clangd') then - lspconfig.clangd.setup({ +if utils.executable("clangd") then + lspconfig.clangd.setup { on_attach = custom_attach, capabilities = capabilities, filetypes = { "c", "cpp", "cc" }, flags = { debounce_text_changes = 500, }, - }) + } else - vim.notify("clangd not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) + vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end -- set up vim-language-server -if utils.executable('vim-language-server') then - lspconfig.vimls.setup({ +if utils.executable("vim-language-server") then + lspconfig.vimls.setup { on_attach = custom_attach, flags = { debounce_text_changes = 500, }, capabilities = capabilities, - }) + } else - vim.notify("vim-language-server not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) + vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end -- set up bash-language-server -if utils.executable('bash-language-server') then - lspconfig.bashls.setup({ +if utils.executable("bash-language-server") then + lspconfig.bashls.setup { on_attach = custom_attach, capabilities = capabilities, - }) + } end if utils.executable("lua-language-server") then -- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings . - lspconfig.sumneko_lua.setup({ + lspconfig.sumneko_lua.setup { on_attach = custom_attach, settings = { Lua = { @@ -174,8 +179,8 @@ if utils.executable("lua-language-server") then -- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace . -- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua . library = { - fn.stdpath('data') .. "/site/pack/packer/opt/emmylua-nvim", - fn.stdpath('config'), + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), }, maxPreload = 2000, preloadFileSize = 50000, @@ -183,7 +188,7 @@ if utils.executable("lua-language-server") then }, }, capabilities = capabilities, - }) + } end -- Change diagnostic signs. @@ -193,12 +198,12 @@ fn.sign_define("DiagnosticSignInformation", { text = "", texthl = "Diagnostic fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) -- global config for diagnostic -vim.diagnostic.config({ +vim.diagnostic.config { underline = false, virtual_text = false, signs = true, severity_sort = true, -}) +} -- lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, { -- underline = false, diff --git a/lua/config/neoscroll.lua b/lua/config/neoscroll.lua index 45b7c08..6d9701b 100644 --- a/lua/config/neoscroll.lua +++ b/lua/config/neoscroll.lua @@ -1,6 +1,6 @@ -require("neoscroll").setup({ +require("neoscroll").setup { easing_function = "quadratic", -}) +} local t = {} -- Syntax: t[keys] = {function, {function arguments}} diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index e7fed19..188c985 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -1,54 +1,54 @@ -- Setup nvim-cmp. -local cmp = require'cmp' -local lspkind = require'lspkind' +local cmp = require("cmp") +local lspkind = require("lspkind") -cmp.setup({ +cmp.setup { snippet = { expand = function(args) -- For `ultisnips` user. vim.fn["UltiSnips#Anon"](args.body) end, }, - mapping = cmp.mapping.preset.insert({ - [''] = function(fallback) - if cmp.visible() then - cmp.select_next_item() - else - fallback() - end - end, - [''] = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - }), + mapping = cmp.mapping.preset.insert { + [""] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, + [""] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, + [""] = cmp.mapping.confirm { select = true }, + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + }, sources = { - { name = 'nvim_lsp' }, -- For nvim-lsp - { name = 'ultisnips' }, -- For ultisnips user. - { name = 'path' }, -- for path completion - { name = 'buffer', keyword_length = 2 }, -- for buffer word completion - { name = 'omni' }, - { name = 'emoji', insert = true, } -- emoji completion + { name = "nvim_lsp" }, -- For nvim-lsp + { name = "ultisnips" }, -- For ultisnips user. + { name = "path" }, -- for path completion + { name = "buffer", keyword_length = 2 }, -- for buffer word completion + { name = "omni" }, + { name = "emoji", insert = true }, -- emoji completion }, completion = { keyword_length = 1, - completeopt = "menu,noselect" + completeopt = "menu,noselect", }, view = { - entries = 'custom', + entries = "custom", }, formatting = { - format = lspkind.cmp_format({ + format = lspkind.cmp_format { mode = "symbol_text", - menu = ({ + menu = { nvim_lsp = "[LSP]", ultisnips = "[US]", nvim_lua = "[Lua]", @@ -56,13 +56,13 @@ cmp.setup({ buffer = "[Buffer]", emoji = "[Emoji]", omni = "[Omni]", - }), - }), + }, + }, }, -}) +} -- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu -vim.cmd[[ +vim.cmd([[ highlight! link CmpItemMenu Comment " gray highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080 @@ -80,4 +80,4 @@ vim.cmd[[ highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4 highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4 highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4 -]] +]]) diff --git a/lua/config/nvim-notify.lua b/lua/config/nvim-notify.lua index d64228f..4fcd02e 100644 --- a/lua/config/nvim-notify.lua +++ b/lua/config/nvim-notify.lua @@ -1,10 +1,10 @@ local nvim_notify = require("notify") -nvim_notify.setup({ +nvim_notify.setup { -- Animation style stages = "fade_in_slide_out", -- Default timeout for notifications timeout = 1500, background_colour = "#2E3440", -}) +} vim.notify = nvim_notify diff --git a/lua/config/nvim-tree.lua b/lua/config/nvim-tree.lua index c34c1d5..737911f 100644 --- a/lua/config/nvim-tree.lua +++ b/lua/config/nvim-tree.lua @@ -1,7 +1,7 @@ local keymap = vim.keymap local nvim_tree = require("nvim-tree") -nvim_tree.setup({ +nvim_tree.setup { auto_reload_on_write = true, disable_netrw = false, hijack_cursor = false, @@ -112,9 +112,8 @@ nvim_tree.setup({ profile = false, }, }, -}) +} -keymap.set('n', 's', function() - return require('nvim-tree').toggle(false, true) -end, - { silent = true, desc = "toggle nvim-tree" }) +keymap.set("n", "s", function() + return require("nvim-tree").toggle(false, true) +end, { silent = true, desc = "toggle nvim-tree" }) diff --git a/lua/config/nvim_hop.lua b/lua/config/nvim_hop.lua index b774046..b1df219 100644 --- a/lua/config/nvim_hop.lua +++ b/lua/config/nvim_hop.lua @@ -1,14 +1,14 @@ -vim.cmd [[hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]] -vim.cmd [[hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]] -vim.cmd [[hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]] +vim.cmd([[hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]]) +vim.cmd([[hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]]) +vim.cmd([[hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]]) local keymap = vim.keymap -local hop = require "hop" -hop.setup({ +local hop = require("hop") +hop.setup { case_insensitive = true, char2_fallback_key = "", quit_key = "", -}) +} keymap.set({ "n", "v", "o" }, "f", "", { silent = true, diff --git a/lua/config/statusline.lua b/lua/config/statusline.lua index bb018ce..846d561 100644 --- a/lua/config/statusline.lua +++ b/lua/config/statusline.lua @@ -11,9 +11,9 @@ end local function ime_state() if vim.g.is_mac then -- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11 - local layout = fn.libcall(vim.g.XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '') - if layout == '0' then - return '[CN]' + local layout = fn.libcall(vim.g.XkbSwitchLib, "Xkb_Switch_getXkbLayout", "") + if layout == "0" then + return "[CN]" end end @@ -27,7 +27,7 @@ local function trailing_space() local line_num = nil - for i=1, fn.line('$') do + for i = 1, fn.line("$") do local linetext = fn.getline(i) -- To prevent invalid escape error, we wrap the regex string with `[[]]`. local idx = fn.match(linetext, [[\v\s+$]]) @@ -53,24 +53,26 @@ local function mixed_indent() local space_pat = [[\v^ +]] local tab_pat = [[\v^\t+]] - local space_indent = fn.search(space_pat, 'nwc') - local tab_indent = fn.search(tab_pat, 'nwc') + local space_indent = fn.search(space_pat, "nwc") + local tab_indent = fn.search(tab_pat, "nwc") local mixed = (space_indent > 0 and tab_indent > 0) local mixed_same_line if not mixed then - mixed_same_line = fn.search([[\v^(\t+ | +\t)]], 'nwc') + mixed_same_line = fn.search([[\v^(\t+ | +\t)]], "nwc") mixed = mixed_same_line > 0 end - if not mixed then return '' end - if mixed_same_line ~= nil and mixed_same_line > 0 then - return 'MI:'..mixed_same_line + if not mixed then + return "" end - local space_indent_cnt = fn.searchcount({pattern=space_pat, max_count=1e3}).total - local tab_indent_cnt = fn.searchcount({pattern=tab_pat, max_count=1e3}).total + if mixed_same_line ~= nil and mixed_same_line > 0 then + return "MI:" .. mixed_same_line + end + local space_indent_cnt = fn.searchcount({ pattern = space_pat, max_count = 1e3 }).total + local tab_indent_cnt = fn.searchcount({ pattern = tab_pat, max_count = 1e3 }).total if space_indent_cnt > tab_indent_cnt then - return 'MI:'..tab_indent + return "MI:" .. tab_indent else - return 'MI:'..space_indent + return "MI:" .. space_indent end end @@ -89,7 +91,7 @@ local diff = function() return info end -require("lualine").setup({ +require("lualine").setup { options = { icons_enabled = true, theme = "auto", @@ -105,19 +107,19 @@ require("lualine").setup({ lualine_b = { "branch", { - 'diff', - source = diff - } + "diff", + source = diff, + }, }, lualine_c = { "filename", { ime_state, - color = {fg = 'black', bg = '#f46868'} + color = { fg = "black", bg = "#f46868" }, }, { spell, - color = {fg = 'black', bg = '#a7c080'} + color = { fg = "black", bg = "#a7c080" }, }, }, lualine_x = { @@ -137,15 +139,15 @@ require("lualine").setup({ "location", { "diagnostics", - sources = { "nvim_diagnostic" } + sources = { "nvim_diagnostic" }, }, { trailing_space, - color = "WarningMsg" + color = "WarningMsg", }, { mixed_indent, - color = "WarningMsg" + color = "WarningMsg", }, }, }, @@ -158,6 +160,5 @@ require("lualine").setup({ lualine_z = {}, }, tabline = {}, - extensions = {'quickfix', 'fugitive', 'nvim-tree'}, -}) - + extensions = { "quickfix", "fugitive", "nvim-tree" }, +} diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 11721ec..9f7a8a9 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,8 +1,8 @@ -require("nvim-treesitter.configs").setup({ - ensure_installed = {"python", "cpp", "lua", "vim"}, +require("nvim-treesitter.configs").setup { + ensure_installed = { "python", "cpp", "lua", "vim" }, ignore_install = {}, -- List of parsers to ignore installing highlight = { enable = true, -- false will disable the whole extension disable = {}, -- list of language that will be disabled }, -}) +} diff --git a/lua/config/which-key.lua b/lua/config/which-key.lua index 11e4c63..10c0c41 100644 --- a/lua/config/which-key.lua +++ b/lua/config/which-key.lua @@ -1,4 +1,4 @@ -require("which-key").setup({ +require("which-key").setup { plugins = { marks = true, -- shows a list of your marks on ' and ` registers = true, -- shows your registers on " in NORMAL or in INSERT mode @@ -46,7 +46,7 @@ require("which-key").setup({ align = "center", -- align columns left, center or right }, ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label - hidden = { "", "", "", "", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate + hidden = { "", "", "", "", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate show_help = true, -- show help message on the command line when the popup is visible triggers = "auto", -- automatically setup triggers -- triggers = {""} -- or specify a list manually @@ -57,4 +57,4 @@ require("which-key").setup({ -- most people should not need to change this n = { "o", "O" }, }, -}) +} diff --git a/lua/config/zen-mode.lua b/lua/config/zen-mode.lua index 8185ceb..b6d52ce 100644 --- a/lua/config/zen-mode.lua +++ b/lua/config/zen-mode.lua @@ -1,4 +1,4 @@ -require("zen-mode").setup({ +require("zen-mode").setup { window = { backdrop = 0.8, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal width = 120, @@ -12,4 +12,4 @@ require("zen-mode").setup({ list = false, -- disable whitespace characters }, }, -}) +} diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua index b9be923..9d85fda 100644 --- a/lua/custom-autocmd.lua +++ b/lua/custom-autocmd.lua @@ -3,7 +3,6 @@ local api = vim.api local utils = require("utils") - -- Display a message when the current file is not in utf-8 format. -- Note that we need to use `unsilent` command here because of this issue: -- https://github.com/vim/vim/issues/4379 @@ -11,10 +10,10 @@ api.nvim_create_autocmd({ "BufRead" }, { pattern = "*", group = api.nvim_create_augroup("non_utf8_file", { clear = true }), callback = function() - if vim.bo.fileencoding ~= 'utf-8' then + if vim.bo.fileencoding ~= "utf-8" then vim.notify("File not in UTF-8 format!", vim.log.levels.WARN, { title = "nvim-config" }) end - end + end, }) -- highlight yanked region, see `:h lua-highlight` @@ -23,7 +22,7 @@ api.nvim_create_autocmd({ "TextYankPost" }, { group = api.nvim_create_augroup("highlight_yank", { clear = true }), callback = function() vim.highlight.on_yank { higroup = "YankColor", timeout = 300 } - end + end, }) -- Auto-generate packer_compiled.lua file @@ -34,7 +33,7 @@ api.nvim_create_autocmd({ "BufWritePost" }, { local cmd = "source " .. ctx.file vim.cmd(cmd) vim.cmd("PackerCompile") - end + end, }) -- Auto-create dir when saving a file, in case some intermediate directory does not exist @@ -44,7 +43,7 @@ api.nvim_create_autocmd({ "BufWritePre" }, { callback = function(ctx) local dir = fn.fnamemodify(ctx.file, ":p:h") utils.may_create_dir(dir) - end + end, }) -- Automatically reload the file if it is changed outside of Nvim, see https://unix.stackexchange.com/a/383044/221410. @@ -57,17 +56,17 @@ api.nvim_create_autocmd({ "FileChangedShellPost" }, { group = "auto_read", callback = function() vim.notify("File changed on disk. Buffer reloaded!", vim.log.levels.WARN, { title = "nvim-config" }) - end + end, }) api.nvim_create_autocmd({ "FocusGained", "CursorHold" }, { pattern = "*", group = "auto_read", callback = function() - if fn.getcmdwintype() == '' then + if fn.getcmdwintype() == "" then vim.cmd("checktime") end - end + end, }) -- Resize all windows when we resize the terminal diff --git a/lua/plugins.lua b/lua/plugins.lua index 8d8cc0c..f09d6b9 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -26,16 +26,16 @@ end vim.cmd("packadd packer.nvim") local packer = require("packer") -local packer_util = require('packer.util') +local packer_util = require("packer.util") -packer.startup({ +packer.startup { function(use) -- it is recommended to put impatient.nvim before any other plugins - use { 'lewis6991/impatient.nvim', config = [[require('impatient')]] } + use { "lewis6991/impatient.nvim", config = [[require('impatient')]] } - use({ "wbthomason/packer.nvim", opt = true }) + use { "wbthomason/packer.nvim", opt = true } - use({ "onsails/lspkind-nvim", event = "VimEnter" }) + use { "onsails/lspkind-nvim", event = "VimEnter" } -- auto-completion engine use { "hrsh7th/nvim-cmp", after = "lspkind-nvim", config = [[require('config.nvim-cmp')]] } @@ -44,312 +44,328 @@ packer.startup({ use { "hrsh7th/cmp-path", after = "nvim-cmp" } use { "hrsh7th/cmp-buffer", after = "nvim-cmp" } use { "hrsh7th/cmp-omni", after = "nvim-cmp" } - use { "quangnguyen30192/cmp-nvim-ultisnips", after = { 'nvim-cmp', 'ultisnips' } } + use { "quangnguyen30192/cmp-nvim-ultisnips", after = { "nvim-cmp", "ultisnips" } } if vim.g.is_mac then - use { "hrsh7th/cmp-emoji", after = 'nvim-cmp' } + use { "hrsh7th/cmp-emoji", after = "nvim-cmp" } end -- nvim-lsp configuration (it relies on cmp-nvim-lsp, so it should be loaded after cmp-nvim-lsp). - use({ "neovim/nvim-lspconfig", after = "cmp-nvim-lsp", config = [[require('config.lsp')]] }) + use { "neovim/nvim-lspconfig", after = "cmp-nvim-lsp", config = [[require('config.lsp')]] } if vim.g.is_mac then - use({ "nvim-treesitter/nvim-treesitter", event = 'BufEnter', run = ":TSUpdate", - config = [[require('config.treesitter')]] }) + use { + "nvim-treesitter/nvim-treesitter", + event = "BufEnter", + run = ":TSUpdate", + config = [[require('config.treesitter')]], + } end -- Python indent (follows the PEP8 style) - use({ "Vimjas/vim-python-pep8-indent", ft = { "python" } }) + use { "Vimjas/vim-python-pep8-indent", ft = { "python" } } -- Python-related text object - use({ "jeetsukumaran/vim-pythonsense", ft = { "python" } }) + use { "jeetsukumaran/vim-pythonsense", ft = { "python" } } - use({ "machakann/vim-swap", event = "VimEnter" }) + use { "machakann/vim-swap", event = "VimEnter" } -- IDE for Lisp if utils.executable("sbcl") then -- use 'kovisoft/slimv' - use({ "vlime/vlime", rtp = "vim/", ft = { "lisp" } }) + use { "vlime/vlime", rtp = "vim/", ft = { "lisp" } } end -- Super fast buffer jump use { - 'phaazon/hop.nvim', + "phaazon/hop.nvim", event = "VimEnter", config = function() - vim.defer_fn(function() require('config.nvim_hop') end, 2000) - end + vim.defer_fn(function() + require("config.nvim_hop") + end, 2000) + end, } -- Show match number and index for searching use { - 'kevinhwang91/nvim-hlslens', - branch = 'main', - keys = { { 'n', '*' }, { 'n', '#' }, { 'n', 'n' }, { 'n', 'N' } }, - config = [[require('config.hlslens')]] + "kevinhwang91/nvim-hlslens", + branch = "main", + keys = { { "n", "*" }, { "n", "#" }, { "n", "n" }, { "n", "N" } }, + config = [[require('config.hlslens')]], } -- Stay after pressing * and search selected text - use({ "haya14busa/vim-asterisk", event = 'VimEnter' }) + use { "haya14busa/vim-asterisk", event = "VimEnter" } -- File search, tag search and more if vim.g.is_win then - use({ "Yggdroot/LeaderF", cmd = "Leaderf" }) + use { "Yggdroot/LeaderF", cmd = "Leaderf" } else - use({ "Yggdroot/LeaderF", cmd = "Leaderf", run = ":LeaderfInstallCExtension" }) + use { "Yggdroot/LeaderF", cmd = "Leaderf", run = ":LeaderfInstallCExtension" } end use { - 'nvim-telescope/telescope.nvim', cmd = 'Telescope', - requires = { { 'nvim-lua/plenary.nvim' } } + "nvim-telescope/telescope.nvim", + cmd = "Telescope", + requires = { { "nvim-lua/plenary.nvim" } }, } -- search emoji and other symbols - use { 'nvim-telescope/telescope-symbols.nvim', after = 'telescope.nvim' } + use { "nvim-telescope/telescope-symbols.nvim", after = "telescope.nvim" } -- A list of colorscheme plugin you may want to try. Find what suits you. - use({ "lifepillar/vim-gruvbox8", opt = true }) - use({ "navarasu/onedark.nvim", opt = true }) - use({ "sainnhe/edge", opt = true }) - use({ "sainnhe/sonokai", opt = true }) - use({ "sainnhe/gruvbox-material", opt = true }) - use({ "shaunsingh/nord.nvim", opt = true }) - use({ "NTBBloodbath/doom-one.nvim", opt = true }) - use({ "sainnhe/everforest", opt = true }) - use({ "EdenEast/nightfox.nvim", opt = true }) - use({ "rebelot/kanagawa.nvim", opt = true }) - use({ "catppuccin/nvim", as = "catppuccin", opt = true }) + use { "lifepillar/vim-gruvbox8", opt = true } + use { "navarasu/onedark.nvim", opt = true } + use { "sainnhe/edge", opt = true } + use { "sainnhe/sonokai", opt = true } + use { "sainnhe/gruvbox-material", opt = true } + use { "shaunsingh/nord.nvim", opt = true } + use { "NTBBloodbath/doom-one.nvim", opt = true } + use { "sainnhe/everforest", opt = true } + use { "EdenEast/nightfox.nvim", opt = true } + use { "rebelot/kanagawa.nvim", opt = true } + use { "catppuccin/nvim", as = "catppuccin", opt = true } - use { 'kyazdani42/nvim-web-devicons', event = 'VimEnter' } + use { "kyazdani42/nvim-web-devicons", event = "VimEnter" } use { - 'nvim-lualine/lualine.nvim', - event = 'VimEnter', - config = [[require('config.statusline')]] + "nvim-lualine/lualine.nvim", + event = "VimEnter", + config = [[require('config.statusline')]], } - use({ "akinsho/bufferline.nvim", event = "VimEnter", config = [[require('config.bufferline')]] }) + use { "akinsho/bufferline.nvim", event = "VimEnter", config = [[require('config.bufferline')]] } -- fancy start screen - use { 'glepnir/dashboard-nvim', event = "VimEnter", config = [[require('config.dashboard-nvim')]] } + use { "glepnir/dashboard-nvim", event = "VimEnter", config = [[require('config.dashboard-nvim')]] } - use({ + use { "lukas-reineke/indent-blankline.nvim", - event = 'VimEnter', - config = [[require('config.indent-blankline')]] - }) + event = "VimEnter", + config = [[require('config.indent-blankline')]], + } -- Highlight URLs inside vim - use({ "itchyny/vim-highlighturl", event = "VimEnter" }) + use { "itchyny/vim-highlighturl", event = "VimEnter" } -- notification plugin - use({ + use { "rcarriga/nvim-notify", event = "BufEnter", config = function() - vim.defer_fn(function() require('config.nvim-notify') end, 2000) - end - }) + vim.defer_fn(function() + require("config.nvim-notify") + end, 2000) + end, + } -- For Windows and Mac, we can open an URL in the browser. For Linux, it may -- not be possible since we maybe in a server which disables GUI. if vim.g.is_win or vim.g.is_mac then -- open URL in browser - use({ "tyru/open-browser.vim", event = "VimEnter" }) + use { "tyru/open-browser.vim", event = "VimEnter" } end -- Only install these plugins if ctags are installed on the system if utils.executable("ctags") then -- show file tags in vim window - use({ "liuchengxu/vista.vim", cmd = "Vista" }) + use { "liuchengxu/vista.vim", cmd = "Vista" } end -- Snippet engine and snippet template - use({ "SirVer/ultisnips", event = 'InsertEnter' }) - use({ "honza/vim-snippets", after = 'ultisnips' }) + use { "SirVer/ultisnips", event = "InsertEnter" } + use { "honza/vim-snippets", after = "ultisnips" } -- Automatic insertion and deletion of a pair of characters - use({ "Raimondi/delimitMate", event = "InsertEnter" }) + use { "Raimondi/delimitMate", event = "InsertEnter" } -- Comment plugin - use({ "tpope/vim-commentary", event = "VimEnter" }) + use { "tpope/vim-commentary", event = "VimEnter" } -- Multiple cursor plugin like Sublime Text? -- use 'mg979/vim-visual-multi' -- Autosave files on certain events - use({ "907th/vim-auto-save", event = "InsertEnter" }) + use { "907th/vim-auto-save", event = "InsertEnter" } -- Show undo history visually - use({ "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } }) + use { "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } } -- Manage your yank history if vim.g.is_win or vim.g.is_mac then - use({ "svermeulen/vim-yoink", event = "VimEnter" }) + use { "svermeulen/vim-yoink", event = "VimEnter" } end -- Handy unix command inside Vim (Rename, Move etc.) - use({ "tpope/vim-eunuch", cmd = { "Rename", "Delete" } }) + use { "tpope/vim-eunuch", cmd = { "Rename", "Delete" } } -- Repeat vim motions - use({ "tpope/vim-repeat", event = "VimEnter" }) + use { "tpope/vim-repeat", event = "VimEnter" } - use({ "nvim-zh/better-escape.vim", event = { "InsertEnter" } }) + use { "nvim-zh/better-escape.vim", event = { "InsertEnter" } } if vim.g.is_mac then - use({ "lyokha/vim-xkbswitch", event = { "InsertEnter" } }) + use { "lyokha/vim-xkbswitch", event = { "InsertEnter" } } elseif vim.g.is_win then - use({ "Neur1n/neuims", event = { "InsertEnter" } }) + use { "Neur1n/neuims", event = { "InsertEnter" } } end -- Auto format tools - use({ "sbdchd/neoformat", cmd = { "Neoformat" } }) + use { "sbdchd/neoformat", cmd = { "Neoformat" } } -- Git command inside vim - use({ "tpope/vim-fugitive", event = "User InGitRepo", config = [[require('config.fugitive')]] }) + use { "tpope/vim-fugitive", event = "User InGitRepo", config = [[require('config.fugitive')]] } -- Better git log display - use({ "rbong/vim-flog", requires = "tpope/vim-fugitive", cmd = { "Flog" } }) + use { "rbong/vim-flog", requires = "tpope/vim-fugitive", cmd = { "Flog" } } - use({ "christoomey/vim-conflicted", requires = "tpope/vim-fugitive", cmd = { "Conflicted" } }) + use { "christoomey/vim-conflicted", requires = "tpope/vim-fugitive", cmd = { "Conflicted" } } use { - 'ruifm/gitlinker.nvim', - requires = 'nvim-lua/plenary.nvim', + "ruifm/gitlinker.nvim", + requires = "nvim-lua/plenary.nvim", event = "User InGitRepo", - config = [[require('config.git-linker')]] + config = [[require('config.git-linker')]], } -- Show git change (change, delete, add) signs in vim sign column - use({ 'lewis6991/gitsigns.nvim', config = [[require('config.gitsigns')]] }) + use { "lewis6991/gitsigns.nvim", config = [[require('config.gitsigns')]] } -- Better git commit experience - use({ "rhysd/committia.vim", opt = true, setup = [[vim.cmd('packadd committia.vim')]] }) + use { "rhysd/committia.vim", opt = true, setup = [[vim.cmd('packadd committia.vim')]] } - use({ "kevinhwang91/nvim-bqf", ft = "qf", config = [[require('config.bqf')]] }) + use { "kevinhwang91/nvim-bqf", ft = "qf", config = [[require('config.bqf')]] } -- Another markdown plugin - use({ "plasticboy/vim-markdown", ft = { "markdown" } }) + use { "plasticboy/vim-markdown", ft = { "markdown" } } -- Faster footnote generation - use({ "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } }) + use { "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } } -- Vim tabular plugin for manipulate tabular, required by markdown plugins - use({ "godlygeek/tabular", cmd = { "Tabularize" } }) + use { "godlygeek/tabular", cmd = { "Tabularize" } } -- Markdown JSON header highlight plugin - use({ "elzr/vim-json", ft = { "json", "markdown" } }) + use { "elzr/vim-json", ft = { "json", "markdown" } } -- Markdown previewing (only for Mac and Windows) if vim.g.is_win or vim.g.is_mac then - use({ + use { "iamcco/markdown-preview.nvim", run = function() fn["mkdp#util#install"]() end, ft = { "markdown" }, - }) + } end - use({ 'folke/zen-mode.nvim', cmd = 'ZenMode', config = [[require('config.zen-mode')]] }) + use { "folke/zen-mode.nvim", cmd = "ZenMode", config = [[require('config.zen-mode')]] } if vim.g.is_mac then - use({ "rhysd/vim-grammarous", ft = { "markdown" } }) + use { "rhysd/vim-grammarous", ft = { "markdown" } } end - use({ "chrisbra/unicode.vim", event = "VimEnter" }) + use { "chrisbra/unicode.vim", event = "VimEnter" } -- Additional powerful text object for vim, this plugin should be studied -- carefully to use its full power - use({ "wellle/targets.vim", event = "VimEnter" }) + use { "wellle/targets.vim", event = "VimEnter" } -- Plugin to manipulate character pairs quickly - use({ "machakann/vim-sandwich", event = "VimEnter" }) + use { "machakann/vim-sandwich", event = "VimEnter" } -- Add indent object for vim (useful for languages like Python) - use({ "michaeljsmith/vim-indent-object", event = "VimEnter" }) + use { "michaeljsmith/vim-indent-object", event = "VimEnter" } -- Only use these plugin on Windows and Mac and when LaTeX is installed if vim.g.is_win or vim.g.is_mac and utils.executable("latex") then - use({ "lervag/vimtex", ft = { "tex" } }) + use { "lervag/vimtex", ft = { "tex" } } end -- Since tmux is only available on Linux and Mac, we only enable these plugins -- for Linux and Mac if utils.executable("tmux") then -- .tmux.conf syntax highlighting and setting check - use({ "tmux-plugins/vim-tmux", ft = { "tmux" } }) + use { "tmux-plugins/vim-tmux", ft = { "tmux" } } end -- Modern matchit implementation - use({ "andymass/vim-matchup", event = "VimEnter" }) + use { "andymass/vim-matchup", event = "VimEnter" } -- Smoothie motions - use({ + use { "karb94/neoscroll.nvim", event = "VimEnter", config = function() - vim.defer_fn(function() require('config.neoscroll') end, 2000) - end - }) + vim.defer_fn(function() + require("config.neoscroll") + end, 2000) + end, + } - use({ "tpope/vim-scriptease", cmd = { "Scriptnames", "Message", "Verbose" } }) + use { "tpope/vim-scriptease", cmd = { "Scriptnames", "Message", "Verbose" } } -- Asynchronous command execution - use({ "skywind3000/asyncrun.vim", opt = true, cmd = { "AsyncRun" } }) + use { "skywind3000/asyncrun.vim", opt = true, cmd = { "AsyncRun" } } - use({ "cespare/vim-toml", ft = { "toml" }, branch = "main" }) + use { "cespare/vim-toml", ft = { "toml" }, branch = "main" } -- Edit text area in browser using nvim if vim.g.is_win or vim.g.is_mac then - use({ + use { "glacambre/firenvim", - run = function() fn["firenvim#install"](0) end, + run = function() + fn["firenvim#install"](0) + end, opt = true, setup = [[vim.cmd('packadd firenvim')]], - }) + } end -- Debugger plugin if vim.g.is_win or vim.g.is_linux then - use({ "sakhnik/nvim-gdb", run = { "bash install.sh" }, opt = true, setup = [[vim.cmd('packadd nvim-gdb')]] }) + use { "sakhnik/nvim-gdb", run = { "bash install.sh" }, opt = true, setup = [[vim.cmd('packadd nvim-gdb')]] } end -- Session management plugin - use({ "tpope/vim-obsession", cmd = 'Obsession' }) + use { "tpope/vim-obsession", cmd = "Obsession" } if vim.g.is_linux then - use({ "ojroques/vim-oscyank", cmd = { 'OSCYank', 'OSCYankReg' } }) + use { "ojroques/vim-oscyank", cmd = { "OSCYank", "OSCYankReg" } } end -- The missing auto-completion for cmdline! - use({ "gelguy/wilder.nvim", opt = true, setup = [[vim.cmd('packadd wilder.nvim')]] }) + use { "gelguy/wilder.nvim", opt = true, setup = [[vim.cmd('packadd wilder.nvim')]] } -- showing keybindings - use { "folke/which-key.nvim", + use { + "folke/which-key.nvim", event = "VimEnter", config = function() - vim.defer_fn(function() require('config.which-key') end, 2000) - end + vim.defer_fn(function() + require("config.which-key") + end, 2000) + end, } -- show and trim trailing whitespaces - use { 'jdhao/whitespace.nvim', event = 'VimEnter' } + use { "jdhao/whitespace.nvim", event = "VimEnter" } -- file explorer use { - 'kyazdani42/nvim-tree.lua', - requires = { 'kyazdani42/nvim-web-devicons' }, - config = [[require('config.nvim-tree')]] + "kyazdani42/nvim-tree.lua", + requires = { "kyazdani42/nvim-web-devicons" }, + config = [[require('config.nvim-tree')]], } - use { 'ii14/emmylua-nvim', ft = 'lua' } + use { "ii14/emmylua-nvim", ft = "lua" } - use { 'j-hui/fidget.nvim', after = 'nvim-lspconfig', config = [[require('config.fidget-nvim')]] } + use { "j-hui/fidget.nvim", after = "nvim-lspconfig", config = [[require('config.fidget-nvim')]] } end, config = { max_jobs = 16, - compile_path = packer_util.join_paths(fn.stdpath('data'), 'site', 'lua', 'packer_compiled.lua'), + compile_path = packer_util.join_paths(fn.stdpath("data"), "site", "lua", "packer_compiled.lua"), }, -}) +} -- For fresh install, we need to install plugins. Otherwise, we just need to require `packer_compiled.lua`. if fresh_install then @@ -357,9 +373,9 @@ if fresh_install then -- So plugin installation should be done after the startup process. packer.sync() else - local status, _ = pcall(require, 'packer_compiled') + local status, _ = pcall(require, "packer_compiled") if not status then local msg = "File packer_compiled.lua not found: run PackerSync to fix!" - vim.notify(msg, vim.log.levels.ERROR, { title = 'nvim-config' }) + vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" }) end end diff --git a/lua/utils.lua b/lua/utils.lua index c2bb85f..d3198ac 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -20,7 +20,7 @@ function M.may_create_dir(dir) local res = fn.isdirectory(dir) if res == 0 then - fn.mkdir(dir, 'p') + fn.mkdir(dir, "p") end end @@ -31,7 +31,6 @@ function M.get_nvim_version() return nvim_ver_str end - --- Generate random integers in the range [Low, High], inclusive, --- adapted from https://stackoverflow.com/a/12739441/6064933 --- @low: the lower value for this range