+ :ZkOrphans :ZkGrep bracket & html matching

nix-components
pegasust 2022-08-31 07:39:47 -07:00
parent e7f3facc2c
commit fbbc1dea98
1 changed files with 235 additions and 197 deletions

View File

@ -65,7 +65,7 @@ Plug('nvim-treesitter/nvim-treesitter') -- language parser engine for highlighti
Plug('nvim-treesitter/nvim-treesitter-textobjects') -- more text objects Plug('nvim-treesitter/nvim-treesitter-textobjects') -- more text objects
Plug('nvim-telescope/telescope.nvim', { tag = '0.1.0' }) -- file browser Plug('nvim-telescope/telescope.nvim', { tag = '0.1.0' }) -- file browser
Plug('nvim-telescope/telescope-fzf-native.nvim', Plug('nvim-telescope/telescope-fzf-native.nvim',
{ ['do'] = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=release && cmake --build build --config Release && cmake --install build --prefix build' }) { ['do'] = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=release && cmake --build build --config Release && cmake --install build --prefix build' })
Plug('nvim-telescope/telescope-file-browser.nvim') Plug('nvim-telescope/telescope-file-browser.nvim')
-- cmp: auto-complete/suggestions -- cmp: auto-complete/suggestions
Plug('neovim/nvim-lspconfig') -- built-in LSP configurations Plug('neovim/nvim-lspconfig') -- built-in LSP configurations
@ -74,6 +74,8 @@ Plug('hrsh7th/cmp-buffer')
Plug('hrsh7th/nvim-cmp') Plug('hrsh7th/nvim-cmp')
Plug('onsails/lspkind-nvim') Plug('onsails/lspkind-nvim')
-- DevExp -- DevExp
Plug('windwp/nvim-autopairs') -- matches pairs like [] (),...
Plug('windwp/nvim-ts-autotag') -- matches tags <body>hello</body>
Plug('numToStr/Comment.nvim') -- "gc" to comment visual regions/lines Plug('numToStr/Comment.nvim') -- "gc" to comment visual regions/lines
Plug('lewis6991/gitsigns.nvim') -- add git info to sign columns Plug('lewis6991/gitsigns.nvim') -- add git info to sign columns
Plug('tpope/vim-fugitive') -- git commands in nvim Plug('tpope/vim-fugitive') -- git commands in nvim
@ -100,8 +102,8 @@ vim.cmd([[ colorscheme gruvbox ]])
-- plugin keymaps -- plugin keymaps
local function remap(mode, key_cmd, binded_fn, opts) local function remap(mode, key_cmd, binded_fn, opts)
opts = opts or { remap = true } opts = opts or { remap = true }
return vim.keymap.set(mode, key_cmd, binded_fn, opts) return vim.keymap.set(mode, key_cmd, binded_fn, opts)
end end
-- Comment.nvim -- Comment.nvim
@ -112,50 +114,50 @@ vim.opt.listchars:append "space:⋅"
vim.opt.listchars:append "eol:↴" vim.opt.listchars:append "eol:↴"
require("indent_blankline").setup { require("indent_blankline").setup {
show_end_of_line = true, show_end_of_line = true,
space_char_blankline = " ", space_char_blankline = " ",
} }
-- telescope -- telescope
local fb_actions = require "telescope".extensions.file_browser.actions local fb_actions = require "telescope".extensions.file_browser.actions
require('telescope').setup { require('telescope').setup {
defaults = { defaults = {
mappings = { mappings = {
i = { i = {
['<C-u>'] = false, ['<C-u>'] = false,
['<C-d>'] = false, ['<C-d>'] = false,
}, },
},
}, },
}, extensions = {
extensions = { fzf = {
fzf = { fuzzy = true, -- allow fuzzy matches
fuzzy = true, -- allow fuzzy matches override_generic_sorter = true,
override_generic_sorter = true, override_file_sorter = true,
override_file_sorter = true, case_mode = 'smart_case'
case_mode = 'smart_case' },
}, file_browser = {
file_browser = { theme = "ivy",
theme = "ivy", hiject_netrw = true, -- disables netrw and use file-browser instead
hiject_netrw = true, -- disables netrw and use file-browser instead mappings = {
mappings = { ["i"] = {}, -- disable any shortcut in insert mode for now
["i"] = {}, -- disable any shortcut in insert mode for now ["n"] = {
["n"] = { ["c"] = fb_actions.create,
["c"] = fb_actions.create, ["r"] = fb_actions.rename,
["r"] = fb_actions.rename, ["m"] = fb_actions.move,
["m"] = fb_actions.move, ["y"] = fb_actions.copy,
["y"] = fb_actions.copy, ["d"] = fb_actions.remove,
["d"] = fb_actions.remove, ["o"] = fb_actions.open,
["o"] = fb_actions.open, ["g"] = fb_actions.goto_parent_dir,
["g"] = fb_actions.goto_parent_dir, ["e"] = fb_actions.goto_home_dir,
["e"] = fb_actions.goto_home_dir, ["w"] = fb_actions.goto_cwd,
["w"] = fb_actions.goto_cwd, ["t"] = fb_actions.change_cwd,
["t"] = fb_actions.change_cwd, ["f"] = fb_actions.toggle_browser,
["f"] = fb_actions.toggle_browser, ["h"] = fb_actions.toggle_hidden,
["h"] = fb_actions.toggle_hidden, ["s"] = fb_actions.toggle_all,
["s"] = fb_actions.toggle_all, }
}
} }
}
} }
}
} }
pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'fzf')
@ -163,11 +165,11 @@ pcall(require('telescope').load_extension, 'file_browser')
remap('n', '<C-p>', '<cmd>Telescope<cr>', { desc = 'Open Telescope general search' }) remap('n', '<C-p>', '<cmd>Telescope<cr>', { desc = 'Open Telescope general search' })
remap('n', '<leader>fm', function() remap('n', '<leader>fm', function()
require("telescope").extensions.file_browser.file_browser() require("telescope").extensions.file_browser.file_browser()
end, { desc = '[F]ile [M]utation' }) end, { desc = '[F]ile [M]utation' })
remap('n', '<leader>ff', function() remap('n', '<leader>ff', function()
require('telescope.builtin').find_files({ require('telescope.builtin').find_files({
hidden = false, hidden = false,
no_ignore = false, no_ignore = false,
follow = false, follow = false,
@ -180,51 +182,61 @@ remap('n', '<leader>fa', function()
no_ignore = true, no_ignore = true,
follow = true, follow = true,
}) })
end, { desc = '[F]ind [A]ll files' }) end, { desc = '[F]ind [A]ll files' })
remap('n', '<leader>fg', function() remap('n', '<leader>fg', function()
require('telescope.builtin').live_grep() require('telescope.builtin').live_grep()
end, { desc = '[F]ind by [G]rep' }) end, { desc = '[F]ind by [G]rep' })
remap('n', '<leader>fb', function() remap('n', '<leader>fb', function()
require('telescope.builtin').buffers() require('telescope.builtin').buffers()
end, { desc = '[F]ind existing [B]uffers' }) end, { desc = '[F]ind existing [B]uffers' })
remap('n', '<leader>fh', function() remap('n', '<leader>fh', function()
require('telescope.builtin').help_tags() require('telescope.builtin').help_tags()
end, { desc = '[F]ind [H]elp' }) end, { desc = '[F]ind [H]elp' })
remap('n', '<leader>fd', function() remap('n', '<leader>fd', function()
require('telescope.builtin').diagnostics() require('telescope.builtin').diagnostics()
end, { desc = '[F]ind [D]iagnostics' }) end, { desc = '[F]ind [D]iagnostics' })
-- treesitter -- treesitter
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
ensure_installed = { 'lua', 'typescript', 'rust', 'go', 'python', 'prisma' }, ensure_installed = { 'lua', 'typescript', 'rust', 'go', 'python', 'prisma' },
highlight = { enable = true }, sync_install = false,
indent = { enable = true }, highlight = { enable = true },
incremental_selection = { indent = { enable = true },
enable = true, incremental_selection = {
keymaps = { enable = true,
init_selection = '<c-space>', keymaps = {
node_incremental = '<c-space>', init_selection = '<c-space>',
node_decremental = '<c-backspace>', node_incremental = '<c-space>',
scope_incremental = '<c-S>' node_decremental = '<c-backspace>',
} scope_incremental = '<c-S>'
}, }
textobjects = { },
select = { textobjects = {
enable = true, select = {
lookahead = true, enable = true,
keymaps = { lookahead = true,
['af'] = '@function.outer', keymaps = {
['if'] = '@function.inner', ['af'] = '@function.outer',
['ac'] = '@class.outer', ['if'] = '@function.inner',
['ic'] = '@class.inner', ['ac'] = '@class.outer',
}, ['ic'] = '@class.inner',
},
},
},
-- automatically close and modify HTML and TSX tags
autotag = {
enable = true,
}, },
},
} }
require('nvim-autopairs').setup {
check_ts = true,
}
-- harpoon: mark significant files & switch between them -- harpoon: mark significant files & switch between them
remap('n', '<leader>m', function() require('harpoon.mark').add_file() end) remap('n', '<leader>m', function() require('harpoon.mark').add_file() end)
local function harpoon_nav(key, nav_file_index, lead_keybind) local function harpoon_nav(key, nav_file_index, lead_keybind)
@ -233,6 +245,7 @@ local function harpoon_nav(key, nav_file_index, lead_keybind)
assert(type(nav_file_index) == "number" and nav_file_index >= 1, "expect 1-indexed number for file index") assert(type(nav_file_index) == "number" and nav_file_index >= 1, "expect 1-indexed number for file index")
return remap('n', lead_keybind .. key, function() require('harpoon.ui').nav_file(nav_file_index) end) return remap('n', lead_keybind .. key, function() require('harpoon.ui').nav_file(nav_file_index) end)
end end
-- remap letters to index. Inspired by alternating number of Dvorak programmer -- remap letters to index. Inspired by alternating number of Dvorak programmer
-- best practices: try to keep marked files to be around 4 -- best practices: try to keep marked files to be around 4
harpoon_nav('f', 1) harpoon_nav('f', 1)
@ -241,179 +254,204 @@ harpoon_nav('d', 3)
harpoon_nav('k', 4) harpoon_nav('k', 4)
remap('n', '<leader>hh', function() require('harpoon.ui').toggle_quick_menu() end) remap('n', '<leader>hh', function() require('harpoon.ui').toggle_quick_menu() end)
-- harpoon: navigate by numbers -- harpoon: navigate by numbers
harpoon_nav('1',1) harpoon_nav('1', 1)
harpoon_nav('2',2) harpoon_nav('2', 2)
harpoon_nav('3',3) harpoon_nav('3', 3)
harpoon_nav('4',4) harpoon_nav('4', 4)
harpoon_nav('5',5) harpoon_nav('5', 5)
harpoon_nav('6',6) harpoon_nav('6', 6)
harpoon_nav('7',7) harpoon_nav('7', 7)
harpoon_nav('8',8) harpoon_nav('8', 8)
harpoon_nav('9',9) harpoon_nav('9', 9)
harpoon_nav('0',10) harpoon_nav('0', 10)
-- LSP settings -- LSP settings
-- This function gets run when an LSP connects to a particular buffer. -- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr) local on_attach = function(_, bufnr)
-- NOTE: Remember that lua is a real programming language, and as such it is possible -- NOTE: Remember that lua is a real programming language, and as such it is possible
-- to define small helper and utility functions so you don't have to repeat yourself -- to define small helper and utility functions so you don't have to repeat yourself
-- many times. -- many times.
-- --
-- In this case, we create a function that lets us more easily define mappings specific -- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time. -- for LSP related items. It sets the mode, buffer and description for us each time.
local nmap = function(keys, func, desc) local nmap = function(keys, func, desc)
if desc then if desc then
desc = 'LSP: ' .. desc desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
end end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
end nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') -- symbols and gotos
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
nmap('gi', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
nmap('gr', require('telescope.builtin').lsp_references)
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- symbols and gotos -- documentations. See `:help K` for why this keymap
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('gi', vim.lsp.buf.implementation, '[G]oto [I]mplementation') nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
nmap('gr', require('telescope.builtin').lsp_references)
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- documentations. See `:help K` for why this keymap -- Lesser used LSP functionality
nmap('K', vim.lsp.buf.hover, 'Hover Documentation') nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
nmap('<leader>ja', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
-- Lesser used LSP functionality -- Create a command `:Format` local to the LSP buffer
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') vim.api.nvim_buf_create_user_command(bufnr, 'Format', vim.lsp.buf.format or vim.lsp.buf.formatting,
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') { desc = 'Format current buffer with LSP' })
nmap('<leader>ja', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', vim.lsp.buf.format or vim.lsp.buf.formatting,
{ desc = 'Format current buffer with LSP' })
end end
-- nvim-cmp supports additional completion capabilities -- nvim-cmp supports additional completion capabilities
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- default language servers -- default language servers
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', "prisma-language-server" } local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', "prisma-language-server" }
require("mason").setup({ require("mason").setup({
ui = { ui = {
icons = { icons = {
package_installed = "", package_installed = "",
package_pending = "", package_pending = "",
package_uninstalled = "" package_uninstalled = ""
}
} }
}
}) })
require('mason-lspconfig').setup({ require('mason-lspconfig').setup({
ensure_installed = servers, ensure_installed = servers,
automatic_installation = true automatic_installation = true
}) })
require('mason-lspconfig').setup_handlers({ require('mason-lspconfig').setup_handlers({
-- default handler -- default handler
function(server_name) function(server_name)
require('lspconfig')[server_name].setup { require('lspconfig')[server_name].setup {
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
}
end,
["sumneko_lua"] = function()
require('lspconfig').sumneko_lua.setup {
on_attach = on_attach,
capabilities = capabilities,
settings = {
Lua = {
runtime = {
version = "LuaJIT",
path = vim.split(package.path, ";"),
},
diagnostics = {
globals = { "vim" }
},
workspace = {
library = vim.api.nvim_get_runtime_file('', true)
},
telemetry = { enable = false }
} }
} end,
} ["sumneko_lua"] = function()
end require('lspconfig').sumneko_lua.setup {
on_attach = on_attach,
capabilities = capabilities,
settings = {
Lua = {
runtime = {
version = "LuaJIT",
path = vim.split(package.path, ";"),
},
diagnostics = {
globals = { "vim" }
},
workspace = {
library = vim.api.nvim_get_runtime_file('', true)
},
telemetry = { enable = false }
}
}
}
end
}) })
require('zk').setup({ require('zk').setup({
picker = "telescope", picker = "telescope",
lsp = { lsp = {
config = { config = {
cmd = {"zk", "lsp"}, cmd = { "zk", "lsp" },
name = "zk", name = "zk",
on_attach = on_attach, on_attach = on_attach,
}, },
auto_attach = { auto_attach = {
enable = true, enable = true,
filetypes = {"markdown"} filetypes = { "markdown" }
}, },
}, },
}) })
-- Custom ZkOrphans that determines unlinked notes
-- `:ZkOrphans {tags = {"work"}}`
require('zk.commands').add("ZkOrphans", function(options)
options = vim.tbl_extend("force", { orphan = true }, options or {})
-- zk.edit opens notes picker
require('zk').edit(options, { title = "Zk Orphans (unlinked notes)" })
end)
-- ZkGrep: opens file picker
-- In the case where `match_ctor` is falsy, create a prompt.
-- This is so that we distinguish between ZkGrep and ZkNotes
-- Params:
-- match_ctor: string | {match= :string,...} | "" | nil
require('zk.commands').add("ZkGrep", function(match_ctor)
-- handle polymorphic `match_ctor`
local grep_str = ""
local match
if match_ctor == nil or match_ctor == '' then
vim.fn.inputsave()
grep_str = vim.fn.input('Grep string: >')
vim.fn.inputrestore()
match = { match = grep_str }
end
require('zk').edit(match, { title = "Grep: '" .. grep_str .. "'" })
end)
-- nvim-cmp -- nvim-cmp
local cmp = require 'cmp' local cmp = require 'cmp'
local luasnip = require 'luasnip' local luasnip = require 'luasnip'
cmp.setup { cmp.setup {
snippet = { snippet = {
expand = function(args) expand = function(args)
luasnip.lsp_expand(args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert {
['<C-u>'] = cmp.mapping.scroll_docs(-4), ['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4), ['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(), ['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm { ['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, },
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
} }
-- Gitsigns -- Gitsigns
require('gitsigns').setup { require('gitsigns').setup {
signs = { signs = {
add = { text = '+' }, add = { text = '+' },
change = { text = '~' }, change = { text = '~' },
delete = { text = '_' }, delete = { text = '_' },
topdelete = { text = '' }, topdelete = { text = '' },
changedelete = { text = '~' }, changedelete = { text = '~' },
} }
} }
require('lualine').setup { require('lualine').setup {
options = { options = {
icons_enabled = true, icons_enabled = true,
}, },
} }