1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

3 Commits

Author SHA1 Message Date
Martin
f8cddbcbef Merge 4d289d16b3 into 01bc4b40d3 2024-02-02 03:52:33 +08:00
martin
4d289d16b3 update nvim-ufo 2024-01-24 22:50:18 +08:00
martin
90a0645d42 add nvim-ufo for folding 2024-01-19 15:44:08 +08:00
14 changed files with 118 additions and 44 deletions

View File

@@ -64,7 +64,7 @@ and how to set up on different platforms (Linux, macOS, and Windows).
+ Better escaping from insert mode via [better-escape.vim](https://github.com/nvim-zh/better-escape.vim). + Better escaping from insert mode via [better-escape.vim](https://github.com/nvim-zh/better-escape.vim).
+ Ultra-fast project-wide fuzzy searching via [LeaderF](https://github.com/Yggdroot/LeaderF). + Ultra-fast project-wide fuzzy searching via [LeaderF](https://github.com/Yggdroot/LeaderF).
+ Faster code commenting via [vim-commentary](https://github.com/tpope/vim-commentary). + Faster code commenting via [vim-commentary](https://github.com/tpope/vim-commentary).
+ Faster matching pair insertion and jump via [nvim-autopairs](https://github.com/windwp/nvim-autopairs). + Faster matching pair insertion and jump via [delimitMate](https://github.com/Raimondi/delimitMate).
+ Smarter and faster matching pair management (add, replace or delete) via [vim-sandwich](https://github.com/machakann/vim-sandwich). + Smarter and faster matching pair management (add, replace or delete) via [vim-sandwich](https://github.com/machakann/vim-sandwich).
+ Fast buffer jump via [hop.nvim](https://github.com/phaazon/hop.nvim). + Fast buffer jump via [hop.nvim](https://github.com/phaazon/hop.nvim).
+ Powerful snippet insertion via [Ultisnips](https://github.com/SirVer/ultisnips). + Powerful snippet insertion via [Ultisnips](https://github.com/SirVer/ultisnips).

View File

@@ -34,3 +34,6 @@ function s:create_term_buf(_type, size) abort
endif endif
execute 'resize ' . a:size execute 'resize ' . a:size
endfunction endfunction
" For delimitMate
let b:delimitMate_matchpairs = "(:),[:],{:}"

View File

@@ -1,6 +1,2 @@
" let the initial folding state be that all folds are closed. " let the initial folding state be that all folds are closed.
set foldlevel=0 setlocal foldlevel=0
" Use nvim-treesitter for folding
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()

View File

@@ -4,6 +4,5 @@ set formatoptions-=r
nnoremap <buffer><silent> <F9> :luafile %<CR> nnoremap <buffer><silent> <F9> :luafile %<CR>
" Use nvim-treesitter for folding " For delimitMate
set foldmethod=expr let b:delimitMate_matchpairs = "(:),[:],{:}"
set foldexpr=nvim_treesitter#foldexpr()

View File

@@ -13,6 +13,5 @@ set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " number of spaces to use for autoindent set shiftwidth=4 " number of spaces to use for autoindent
set expandtab " expand tab to spaces so that tabs are spaces set expandtab " expand tab to spaces so that tabs are spaces
" Use nvim-treesitter for folding " For delimitMate
set foldmethod=expr let b:delimitMate_matchpairs = "(:),[:],{:}"
set foldexpr=nvim_treesitter#foldexpr()

View File

@@ -14,13 +14,11 @@ vim.loader.enable()
local version = vim.version local version = vim.version
-- check if we have the latest stable version of nvim -- check if we have the latest stable version of nvim
local expected_ver = "0.10.0" local expected_ver = "0.9.5"
local ev = version.parse(expected_ver) local ev = version.parse(expected_ver)
local actual_ver = version() local actual_ver = version()
local result = version.cmp(ev, {actual_ver.major, actual_ver.minor, actual_ver.patch}) if version.cmp(ev, actual_ver) ~= 0 then
if result ~= 0 then
local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch) local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch)
local msg = string.format("Expect nvim %s, but got %s instead. Use at your own risk!", expected_ver, _ver) local msg = string.format("Expect nvim %s, but got %s instead. Use at your own risk!", expected_ver, _ver)
vim.api.nvim_err_writeln(msg) vim.api.nvim_err_writeln(msg)

View File

@@ -2,11 +2,11 @@ local gs = require("gitsigns")
gs.setup { gs.setup {
signs = { signs = {
add = { text = "+" }, add = { hl = "GitSignsAdd", text = "+", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" },
change = { text = "~" }, change = { hl = "GitSignsChange", text = "~", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
delete = { text = "_" }, delete = { hl = "GitSignsDelete", text = "_", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
topdelete = { text = "" }, topdelete = { hl = "GitSignsDelete", text = "", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
changedelete = { text = "" }, changedelete = { hl = "GitSignsChange", text = "", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
}, },
word_diff = true, word_diff = true,
on_attach = function(bufnr) on_attach = function(bufnr)

View File

@@ -234,7 +234,7 @@ if utils.executable("lua-language-server") then
-- see also https://github.com/LuaLS/lua-language-server/wiki/Libraries#link-to-workspace . -- see also https://github.com/LuaLS/lua-language-server/wiki/Libraries#link-to-workspace .
-- Lua-dev.nvim also has similar settings for lua ls, https://github.com/folke/neodev.nvim/blob/main/lua/neodev/luals.lua . -- Lua-dev.nvim also has similar settings for lua ls, https://github.com/folke/neodev.nvim/blob/main/lua/neodev/luals.lua .
library = { library = {
vim.env.VIMRUNTIME, fn.stdpath("data") .. "/lazy/emmylua-nvim",
fn.stdpath("config"), fn.stdpath("config"),
}, },
maxPreload = 2000, maxPreload = 2000,

View File

@@ -4,7 +4,6 @@ hop.setup {
case_insensitive = true, case_insensitive = true,
char2_fallback_key = "<CR>", char2_fallback_key = "<CR>",
quit_key = "<Esc>", quit_key = "<Esc>",
match_mappings = { "zh_sc" }
} }
keymap.set({ "n", "v", "o" }, "f", "", { keymap.set({ "n", "v", "o" }, "f", "", {
@@ -18,7 +17,7 @@ keymap.set({ "n", "v", "o" }, "f", "", {
vim.api.nvim_create_autocmd("ColorScheme", { vim.api.nvim_create_autocmd("ColorScheme", {
pattern = "*", pattern = "*",
callback = function() callback = function ()
vim.cmd([[ vim.cmd([[
hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff

View File

@@ -172,6 +172,7 @@ require("lualine").setup {
}, },
lualine_y = { lualine_y = {
"location", "location",
"progress",
}, },
lualine_z = { lualine_z = {
{ {

22
lua/config/ufo.lua Normal file
View File

@@ -0,0 +1,22 @@
local keymap = vim.keymap
-- disable foldcolumn, see https://github.com/kevinhwang91/nvim-ufo/issues/4
vim.o.foldcolumn = '0'
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true -- Don't set nofoldenable in ftplugin
-- treesitter as a main provider instead
-- Only depend on `nvim-treesitter/queries/filetype/folds.scm`,
-- performance and stability are better than `foldmethod=nvim_treesitter#foldexpr()`
require('ufo').setup({
provider_selector = function(bufnr, filetype, buftype)
return {'treesitter', 'indent'}
end
})
local ufo = require('ufo')
keymap.set('n', 'zR', ufo.openAllFolds, { desc = 'Open all folds' })
keymap.set('n', 'zM', ufo.closeAllFolds, { desc = 'Close all folds' })
keymap.set('n', 'zr', ufo.openFoldsExceptKinds, { desc = 'Fold less' })
keymap.set('n', 'zm', ufo.closeFoldsWith, { desc = 'Fold more' })

View File

@@ -1,6 +1,60 @@
require("which-key").setup { require("which-key").setup {
preset = "modern", plugins = {
marks = true, -- shows a list of your marks on ' and `
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
spelling = {
enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
suggestions = 9, -- how many suggestions should be shown in the list?
},
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
-- No actual key bindings are created
presets = {
operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion
motions = true, -- adds help for motions
text_objects = true, -- help for text objects triggered after entering an operator
windows = true, -- default bindings on <c-w>
nav = true, -- misc bindings to work with windows
z = true, -- bindings for folds, spelling and others prefixed with z
g = true, -- bindings for prefixed with g
},
},
-- add operators that will trigger motion and text object completion
-- to enable all native operators, set the preset / operators plugin above
operators = { gc = "Comments" },
key_labels = {
-- override the label used to display some keys. It doesn't effect WK in any other way.
-- For example:
-- ["<space>"] = "SPC",
-- ["<cr>"] = "RET",
-- ["<tab>"] = "TAB",
},
icons = { icons = {
mappings = false breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
} separator = "", -- symbol used between a key and it's label
group = "+", -- symbol prepended to a group
},
window = {
border = "none", -- none, single, double, shadow
position = "bottom", -- bottom, top
margin = { 0, 0, 0, 0 }, -- extra window margin [top, right, bottom, left]
padding = { 1, 0, 1, 0 }, -- extra window padding [top, right, bottom, left]
},
layout = {
height = { min = 1, max = 25 }, -- min and max height of the columns
width = { min = 20, max = 50 }, -- min and max width of the columns
spacing = 1, -- spacing between columns
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 = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "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 = {"<leader>"} -- or specify a list manually
triggers_blacklist = {
-- list of mode / prefixes that should never be hooked by WhichKey
-- this is mostly relevant for key maps that start with a native binding
-- most people should not need to change this
n = { "o", "O" },
},
} }

View File

@@ -1,6 +1,6 @@
local keymap = vim.keymap local keymap = vim.keymap
local api = vim.api local api = vim.api
local uv = vim.uv local uv = vim.loop
-- Save key strokes (now we do not need to press shift to enter command mode). -- Save key strokes (now we do not need to press shift to enter command mode).
keymap.set({ "n", "x" }, ";", ":") keymap.set({ "n", "x" }, ";", ":")
@@ -170,7 +170,7 @@ keymap.set("n", "<Down>", "<C-W>j")
keymap.set({ "x", "o" }, "iu", "<cmd>call text_obj#URL()<cr>", { desc = "URL text object" }) keymap.set({ "x", "o" }, "iu", "<cmd>call text_obj#URL()<cr>", { desc = "URL text object" })
-- Text objects for entire buffer -- Text objects for entire buffer
keymap.set({ "x", "o" }, "iB", ":<C-U>call text_obj#Buffer()<cr>", { desc = "buffer text object" }) keymap.set({ "x", "o" }, "iB", "<cmd>call text_obj#Buffer()<cr>", { desc = "buffer text object" })
-- Do not move my cursor when joining lines. -- Do not move my cursor when joining lines.
keymap.set("n", "J", function() keymap.set("n", "J", function()
@@ -179,17 +179,17 @@ keymap.set("n", "J", function()
delmarks z delmarks z
]]) ]])
end, { end, {
desc = "join lines without moving cursor", desc = "join line",
}) })
keymap.set("n", "gJ", function() keymap.set("n", "gJ", function()
-- we must use `normal!`, otherwise it will trigger recursive mapping -- we must use `normal!`, otherwise it will trigger recursive mapping
vim.cmd([[ vim.cmd([[
normal! mzgJ`z normal! zmgJ`z
delmarks z delmarks z
]]) ]])
end, { end, {
desc = "join lines without moving cursor", desc = "join visual lines",
}) })
-- Break inserted text into smaller undo units when we insert some punctuation chars. -- Break inserted text into smaller undo units when we insert some punctuation chars.
@@ -217,7 +217,7 @@ keymap.set("n", "<leader>cb", function()
local timer = uv.new_timer() local timer = uv.new_timer()
timer:start(0, 100, vim.schedule_wrap(function() timer:start(0, 100, vim.schedule_wrap(function()
vim.cmd [[ vim.cmd[[
set cursorcolumn! set cursorcolumn!
set cursorline! set cursorline!
]] ]]
@@ -227,7 +227,5 @@ keymap.set("n", "<leader>cb", function()
end end
cnt = cnt + 1 cnt = cnt + 1
end) end))
) end)
end,
{ desc = "show cursor" })

View File

@@ -2,7 +2,7 @@ local utils = require("utils")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then
vim.fn.system { vim.fn.system {
"git", "git",
"clone", "clone",
@@ -50,7 +50,7 @@ local plugin_specs = {
{ {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
enabled = function() enabled = function()
if vim.g.is_mac then if vim.g.is_mac or vim.g.is_linux then
return true return true
end end
return false return false
@@ -221,11 +221,7 @@ local plugin_specs = {
}, event = "InsertEnter" }, }, event = "InsertEnter" },
-- Automatic insertion and deletion of a pair of characters -- Automatic insertion and deletion of a pair of characters
{ { "Raimondi/delimitMate", event = "InsertEnter" },
'windwp/nvim-autopairs',
event = "InsertEnter",
config = true
},
-- Comment plugin -- Comment plugin
{ "tpope/vim-commentary", event = "VeryLazy" }, { "tpope/vim-commentary", event = "VeryLazy" },
@@ -484,6 +480,7 @@ local plugin_specs = {
end, end,
}, },
{ "ii14/emmylua-nvim", ft = "lua" },
{ {
"j-hui/fidget.nvim", "j-hui/fidget.nvim",
event = "VeryLazy", event = "VeryLazy",
@@ -492,6 +489,14 @@ local plugin_specs = {
require("config.fidget-nvim") require("config.fidget-nvim")
end, end,
}, },
{
'kevinhwang91/nvim-ufo',
dependencies = {'kevinhwang91/promise-async'},
event = { "VeryLazy" },
config = function()
require("config.ufo")
end
}
} }
-- configuration for lazy itself. -- configuration for lazy itself.