Skip to content

Commit

Permalink
add neovim config
Browse files Browse the repository at this point in the history
  • Loading branch information
QuakeWang committed Aug 13, 2023
1 parent 46a3b02 commit 0f72494
Show file tree
Hide file tree
Showing 53 changed files with 2,891 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# nvim
Neovim config
# Neovim configuration

Always a WIP.
4 changes: 4 additions & 0 deletions ftplugin/bash.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vim.opt_local.shiftwidth = 4
vim.opt_local.tabstop = 4
vim.opt.cmdheight = 1

32 changes: 32 additions & 0 deletions ftplugin/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local status_ok, which_key = pcall(require, "which-key")
if not status_ok then
return
end

local opts = {
mode = "n", -- NORMAL mode
prefix = "<leader>",
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
silent = true, -- use `silent` when creating keymaps
noremap = true, -- use `noremap` when creating keymaps
nowait = true, -- use `nowait` when creating keymaps
}
local mappings = {
l = {
f = { "<cmd>GoFmt<cr>", "Format (GoFmt)" },
},
g = {
name = "+Go",
s = {
name = "+Stuct",
j = { "<cmd> GoTagAdd json <CR>", "Add json tag" },
y = { "<cmd> GoTagAdd yaml <CR>", "Add yaml tag" },
J = { "<cmd> GoTagRm json <CR>", "Remove json tag" },
Y = { "<cmd> GoTagRm yaml <CR>", "Remove yaml tag" },
},
t = { "<cmd>GoMod tidy<cr>", "go mod tidy" },
e = { "<cmd>GoIfErr<cr>", "Generate if err" },
},
}

which_key.register(mappings, opts)
49 changes: 49 additions & 0 deletions ftplugin/rust.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local status_ok, which_key = pcall(require, "which-key")
if not status_ok then
return
end

local opts = {
mode = "n", -- NORMAL mode
prefix = "<leader>",
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
silent = true, -- use `silent` when creating keymaps
noremap = true, -- use `noremap` when creating keymaps
nowait = true, -- use `nowait` when creating keymaps
}

local mappings = {
-- R = {
-- name = "+Rust",
-- j = { "<cmd>lua require('rust-tools').join_lines.join_lines()<CR>", "Join Lines" },
-- r = { "<cmd>RustRunnables<Cr>", "Runnables" },
-- t = { "<cmd>lua _CARGO_TEST()<cr>", "Cargo Test" },
-- m = { "<cmd>RustExpandMacro<Cr>", "Expand Macro" },
-- c = { "<cmd>RustOpenCargo<Cr>", "Open Cargo" },
-- p = { "<cmd>RustParentModule<Cr>", "Parent Module" },
-- d = { "<cmd>RustDebuggables<Cr>", "Debuggables" },
-- v = { "<cmd>RustViewCrateGraph<Cr>", "View Crate Graph" },
-- R = {
-- "<cmd>lua require('rust-tools/workspace_refresh')._reload_workspace_from_cargo_toml()<Cr>",
-- "Reload Workspace",
-- },
-- },
C = {
name = "+Rust Crates",
o = { "<cmd>lua require('crates').show_popup()<CR>", "Show popup" },
r = { "<cmd>lua require('crates').reload()<CR>", "Reload" },
v = { "<cmd>lua require('crates').show_versions_popup()<CR>", "Show Versions" },
f = { "<cmd>lua require('crates').show_features_popup()<CR>", "Show Features" },
d = { "<cmd>lua require('crates').show_dependencies_popup()<CR>", "Show Dependencies Popup" },
u = { "<cmd>lua require('crates').update_crate()<CR>", "Update Crate" },
a = { "<cmd>lua require('crates').update_all_crates()<CR>", "Update All Crates" },
U = { "<cmd>lua require('crates').upgrade_crate<CR>", "Upgrade Crate" },
A = { "<cmd>lua require('crates').upgrade_all_crates(true)<CR>", "Upgrade All Crates" },
H = { "<cmd>lua require('crates').open_homepage()<CR>", "Open Homepage" },
R = { "<cmd>lua require('crates').open_repository()<CR>", "Open Repository" },
D = { "<cmd>lua require('crates').open_documentation()<CR>", "Open Documentation" },
C = { "<cmd>lua require('crates').open_crates_io()<CR>", "Open Crate.io" },
}
}

which_key.register(mappings, opts)
4 changes: 4 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require("config.keymaps")
require("config.options")
require("config.autocmds")
require("config.lazy")
66 changes: 66 additions & 0 deletions lazy-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
"LuaSnip": { "branch": "master", "commit": "99a94cc35ec99bf06263d0346128e908a204575c" },
"alpha-nvim": { "branch": "main", "commit": "e4fc5e29b731bdf55d204c5c6a11dc3be70f3b65" },
"bufferline.nvim": { "branch": "main", "commit": "d24378edc14a675c820a303b4512af3bbc5761e9" },
"catppuccin": { "branch": "main", "commit": "490078b1593c6609e6a50ad5001e7902ea601824" },
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
"copilot-cmp": { "branch": "master", "commit": "d631b3afbf26bb17d6cf2b3cd8f3d79e7d5eeca1" },
"copilot.lua": { "branch": "master", "commit": "50ca36fd766db4d444094de81f5e131b6628f48f" },
"crates.nvim": { "branch": "main", "commit": "1dffccc0a95f656ebe00cacb4de282473430c5a1" },
"editorconfig-vim": { "branch": "master", "commit": "e014708e917b457e8f6c57f357d55dd3826880d4" },
"fidget.nvim": { "branch": "legacy", "commit": "90c22e47be057562ee9566bad313ad42d622c1d3" },
"flit.nvim": { "branch": "main", "commit": "498b3a4864e697f1ed1145e518c4c78c776c55d8" },
"gitsigns.nvim": { "branch": "main", "commit": "bae45ef449d8811061cc940459e70e883a3aa83a" },
"glance.nvim": { "branch": "master", "commit": "b78ef99ffda23fa42ce85de50e3fc13a5472ecfd" },
"gopher.nvim": { "branch": "main", "commit": "03cabf675ce129c28bd855969a3e569edcf63366" },
"gruvbox-material": { "branch": "master", "commit": "b5f8c6a6c1cda630c53b061b765068a0898d47a3" },
"indent-blankline.nvim": { "branch": "master", "commit": "4541d690816cb99a7fc248f1486aa87f3abce91c" },
"lazy.nvim": { "branch": "main", "commit": "dac844ed617dda4f9ec85eb88e9629ad2add5e05" },
"leap.nvim": { "branch": "main", "commit": "5efe985cf68fac3b6a6dfe7a75fbfaca8db2af9c" },
"lsp-zero.nvim": { "branch": "v2.x", "commit": "96974fe970c37bd3879ad8b6be4fe7ddfad75680" },
"lspkind.nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" },
"lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "e86a4c84ff35240639643ffed56ee1c4d55f538e" },
"mason.nvim": { "branch": "main", "commit": "74eac861b013786bf231b204b4ba9a7d380f4bd9" },
"mini.comment": { "branch": "main", "commit": "877acea5b2a32ff55f808fc0ebe9aa898648318c" },
"mini.pairs": { "branch": "main", "commit": "dfa9f6e2576bb8853be277d96b735af59d9be7c2" },
"neo-tree.nvim": { "branch": "main", "commit": "38293fe690981aba6cfef5e440f26d8b956d463e" },
"neodev.nvim": { "branch": "main", "commit": "9a5c0f0de5c15fba52d4fb83d425d3f4fa7abfa1" },
"neoscroll.nvim": { "branch": "master", "commit": "4bc0212e9f2a7bc7fe7a6bceb15b33e39f0f41fb" },
"neotest": { "branch": "master", "commit": "bec7be0f13ee19c85561943fc5f7b8daa4f4d465" },
"neotest-go": { "branch": "main", "commit": "f2580cad67ef0181403cf65858ab638ffd3ede9f" },
"nui.nvim": { "branch": "main", "commit": "9e3916e784660f55f47daa6f26053ad044db5d6a" },
"null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" },
"nvim-cmp": { "branch": "main", "commit": "51f1e11a89ec701221877532ee1a23557d291dd5" },
"nvim-dap": { "branch": "master", "commit": "1c63f37f95cd4fb54512898168138d9a75d1516a" },
"nvim-dap-go": { "branch": "main", "commit": "208f0e685b48a98bec2cdd8648559c4274b84ca2" },
"nvim-dap-ui": { "branch": "master", "commit": "85b16ac2309d85c88577cd8ee1733ce52be8227e" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "57f1dbd0458dd84a286b27768c142e1567f3ce3b" },
"nvim-lspconfig": { "branch": "master", "commit": "a981d4447b92c54a4d464eb1a76b799bc3f9a771" },
"nvim-spectre": { "branch": "master", "commit": "5b39919a2947b1266b3aa34d0b0b14c35523bc69" },
"nvim-surround": { "branch": "main", "commit": "0d6882635817a2677749a330127d12ac30a4f3c8" },
"nvim-treesitter": { "branch": "master", "commit": "63260da18bf273c76b8e2ea0db84eb901cab49ce" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "9e519b6146512c8e2e702faf8ac48420f4f5deec" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "e9062e2dfb9854e6a927370f2d720de354c88524" },
"nvim-web-devicons": { "branch": "master", "commit": "ab899311f8ae00a47eae8e0879506cead8eb1561" },
"plenary.nvim": { "branch": "master", "commit": "267282a9ce242bbb0c5dc31445b6d353bed978bb" },
"refactoring.nvim": { "branch": "master", "commit": "5359e74291164fcaeaaecdea9ba753ad54eb53d0" },
"rust-tools.nvim": { "branch": "master", "commit": "0cc8adab23117783a0292a0c8a2fbed1005dc645" },
"schemastore.nvim": { "branch": "main", "commit": "6a36e79d9d1c2649063128e407c33e257cf85baf" },
"splitjoin.nvim": { "branch": "main", "commit": "3dd4973ffcc8240b8bc8668babfdd66517144a4a" },
"sqlite.lua": { "branch": "master", "commit": "b7e28c8463254c46a8e61c52d27d6a2040492fc3" },
"telescope-dap.nvim": { "branch": "master", "commit": "313d2ea12ae59a1ca51b62bf01fc941a983d9c9c" },
"telescope-frecency.nvim": { "branch": "master", "commit": "2ac311a2666edb447db5139b326777c44adc1e2a" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "9bc8237565ded606e6c366a71c64c0af25cd7a50" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "62ea5e58c7bbe191297b983a9e7e89420f581369" },
"telescope-zoxide": { "branch": "main", "commit": "68966349aa1b8e9ade403e18479ecf79447389a7" },
"telescope.nvim": { "branch": "master", "commit": "2d92125620417fbea82ec30303823e3cd69e90e8" },
"todo-comments.nvim": { "branch": "main", "commit": "3094ead8edfa9040de2421deddec55d3762f64d1" },
"toggleterm.nvim": { "branch": "main", "commit": "b90a1381e9b5b8596f49070ee86c71db267ac868" },
"trouble.nvim": { "branch": "main", "commit": "40aad004f53ae1d1ba91bcc5c29d59f07c5f01d3" },
"undotree": { "branch": "master", "commit": "0e11ba7325efbbb3f3bebe06213afa3e7ec75131" },
"vim-illuminate": { "branch": "master", "commit": "5ed17582a8e97bf0a0c617c3cf762e98f87b9859" },
"vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" },
"which-key.nvim": { "branch": "main", "commit": "7ccf476ebe0445a741b64e36c78a682c1c6118b7" }
}
127 changes: 127 additions & 0 deletions lua/config/autocmds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
local api = vim.api

local colors = {
fg = "#76787d",
bg = "#252829",
}

-- don't auto comment new line
api.nvim_create_autocmd("BufEnter", { command = [[set formatoptions-=cro]] })

--- Remove all trailing whitespace on save
local TrimWhiteSpaceGrp = api.nvim_create_augroup("TrimWhiteSpaceGrp", { clear = true })
api.nvim_create_autocmd("BufWritePre", {
command = [[:%s/\s\+$//e]],
group = TrimWhiteSpaceGrp,
})

-- wrap words "softly" (no carriage return) in mail buffer
api.nvim_create_autocmd("Filetype", {
pattern = "mail",
callback = function()
vim.opt.textwidth = 0
vim.opt.wrapmargin = 0
vim.opt.wrap = true
vim.opt.linebreak = true
vim.opt.columns = 80
vim.opt.colorcolumn = "80"
end,
})

-- Highlight on yank
api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank()
end,
})

-- go to last loc when opening a buffer
api.nvim_create_autocmd("BufReadPost", {
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
})

api.nvim_create_autocmd("FileType", { pattern = "man", command = [[nnoremap <buffer><silent> q :quit<CR>]] })

-- show cursor line only in active window
local cursorGrp = api.nvim_create_augroup("CursorLine", { clear = true })
api.nvim_create_autocmd({ "InsertLeave", "WinEnter" }, {
pattern = "*",
command = "set cursorline",
group = cursorGrp,
})
api.nvim_create_autocmd(
{ "InsertEnter", "WinLeave" },
{ pattern = "*", command = "set nocursorline", group = cursorGrp }
)

-- Enable spell checking for certain file types
api.nvim_create_autocmd(
{ "BufRead", "BufNewFile" },
-- { pattern = { "*.txt", "*.md", "*.tex" }, command = [[setlocal spell<cr> setlocal spelllang=en,de<cr>]] }
{
pattern = { "*.txt", "*.md", "*.tex" },
callback = function()
vim.opt.spell = true
vim.opt.spelllang = "en,de"
end,
}
)

-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(ev)
local opts = { buffer = ev.buf }
vim.keymap.set('n', '<leader>v', "<cmd>vsplit | lua vim.lsp.buf.definition()<CR>", opts)
end,
})


vim.api.nvim_create_autocmd('ColorScheme', {
callback = function()
-- change the background color of floating windows and borders.
vim.cmd('highlight NormalFloat guibg=none guifg=none')
vim.cmd('highlight FloatBorder guifg=' .. colors.fg .. ' guibg=none')
vim.cmd('highlight NormalNC guibg=none guifg=none')

-- change neotree background colors
-- Default: NeoTreeNormal xxx ctermfg=223 ctermbg=232 guifg=#d4be98 guibg=#141617
vim.cmd('highlight NeoTreeNormal guibg=#1d2021')
vim.cmd('highlight NeoTreeFloatNormal guifg=#1d2021 guibg=#141617')
vim.cmd('highlight NeoTreeFloatBorder guifg=#958272 guibg=#1d2021')
vim.cmd('highlight NeoTreeEndOfBuffer guibg=#1d2021') -- 1d2021
end,
})

-- close some filetypes with <q>
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("close_with_q", { clear = true }),
pattern = {
"PlenaryTestPopup",
"help",
"lspinfo",
"man",
"notify",
"qf",
"spectre_panel",
"startuptime",
"tsplayground",
"neotest-output",
"checkhealth",
"neotest-summary",
"neotest-output-panel",
},
callback = function(event)
vim.bo[event.buf].buflisted = false
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
end,
})

-- resize neovim split when terminal is resized
vim.api.nvim_command('autocmd VimResized * wincmd =')
41 changes: 41 additions & 0 deletions lua/config/colors.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local M = {}

-- good for material-gruvbox
local colors = {
fg = "#76787d",
bg = "#252829",
}


-- local colors = {
-- fg = "#958272",
-- bg = "#212121",
-- }

-- solarized light
-- local colors = {
-- fg = "#7e9496",
-- bg = "#efe7d2",
-- }

-- everforest
-- local colors = {
-- fg = "#76787d",
-- bg = "#21292e",
-- }

-- local colors = {
-- fg = "#76787d",
-- bg = "#2b303b"
-- }

-- good for github light
-- local colors = {
-- fg = "#24292e",
-- bg = "#f1f1f1",
-- }


M.colors = colors

return M
Loading

0 comments on commit 0f72494

Please sign in to comment.