dotfiles/nvim.configlink/init.lua

707 lines
24 KiB
Lua
Raw Permalink Normal View History

2021-05-13 18:40:38 +00:00
-- Bootstrap the Packer plugin manager
local fn = vim.fn
2021-11-24 14:04:07 +00:00
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
2021-05-13 18:40:38 +00:00
if fn.empty(fn.glob(install_path)) > 0 then
2021-11-24 14:04:07 +00:00
packer_bootstrap = fn.system({
"git",
"clone",
"--depth",
"1",
"https://github.com/wbthomason/packer.nvim",
install_path,
})
2021-05-13 18:40:38 +00:00
end
-- Packer plugin installations
2021-11-24 14:04:07 +00:00
require("packer").startup(function(use)
2021-11-09 14:51:56 +00:00
-- Maintain plugin manager
2021-11-24 14:04:07 +00:00
use("wbthomason/packer.nvim")
2021-11-09 14:51:56 +00:00
-- Startup speed hacks
2021-11-24 14:04:07 +00:00
use({
"lewis6991/impatient.nvim",
2021-11-09 14:51:56 +00:00
config = function()
2021-11-24 14:04:07 +00:00
require("impatient")
end,
})
2021-11-09 14:51:56 +00:00
-- Important tweaks
2021-11-24 14:04:07 +00:00
use("tpope/vim-surround") --- Manipulate parentheses
use("tpope/vim-commentary") --- Use gc or gcc to add comments
2021-11-09 14:51:56 +00:00
-- Convenience tweaks
2021-11-24 14:04:07 +00:00
use("tpope/vim-eunuch") --- File manipulation in Vim
use("tpope/vim-vinegar") --- Fixes netrw file explorer
use("tpope/vim-fugitive") --- Git commands and syntax
use("tpope/vim-repeat") --- Actually repeat using .
use("christoomey/vim-tmux-navigator") --- Hotkeys for tmux panes
2021-11-09 14:51:56 +00:00
-- Colorscheme
2021-11-24 14:04:07 +00:00
use({
"morhetz/gruvbox",
2021-11-13 21:02:23 +00:00
config = function()
2021-11-24 14:04:07 +00:00
vim.cmd([[colorscheme gruvbox]])
end,
})
2021-11-09 14:51:56 +00:00
-- Git next to line numbers
2021-11-24 14:04:07 +00:00
use({
"lewis6991/gitsigns.nvim",
branch = "main",
requires = { "nvim-lua/plenary.nvim" },
2021-05-13 18:40:38 +00:00
config = function()
2021-11-24 14:04:07 +00:00
require("gitsigns").setup()
end,
})
2021-11-09 14:51:56 +00:00
-- Status bar
2021-11-24 14:04:07 +00:00
use({
"hoob3rt/lualine.nvim",
requires = { "kyazdani42/nvim-web-devicons", opt = true },
2021-11-09 14:51:56 +00:00
config = function()
2021-11-24 14:04:07 +00:00
require("lualine").setup({
2021-11-09 14:51:56 +00:00
options = {
2021-11-24 14:04:07 +00:00
theme = "gruvbox",
icons_enabled = true,
},
2021-11-09 14:51:56 +00:00
})
2021-11-24 14:04:07 +00:00
end,
})
2021-11-09 14:51:56 +00:00
-- Improve speed and filetype detection
2021-11-24 14:04:07 +00:00
use({
"nathom/filetype.nvim",
2021-11-09 14:51:56 +00:00
config = function()
-- Filetype for .env files
local envfiletype = function()
2021-11-24 14:04:07 +00:00
vim.bo.filetype = "text"
vim.bo.syntax = "sh"
2021-11-09 14:51:56 +00:00
end
-- Force filetype patterns that Vim doesn't know about
2021-11-24 14:04:07 +00:00
require("filetype").setup({
2021-11-09 14:51:56 +00:00
overrides = {
extensions = {
2021-11-24 14:04:07 +00:00
Brewfile = "brewfile",
muttrc = "muttrc",
tfvars = "terraform",
tf = "terraform",
2021-11-09 14:51:56 +00:00
},
literal = {
2021-11-24 14:04:07 +00:00
Caskfile = "brewfile",
[".gitignore"] = "gitignore",
2021-11-09 14:51:56 +00:00
},
complex = {
[".*git/config"] = "gitconfig",
["tmux.conf%..*link"] = "tmux",
["gitconfig%..*link"] = "gitconfig",
[".*ignore%..*link"] = "gitignore",
[".*%.toml%..*link"] = "toml",
},
function_extensions = {},
function_literal = {
[".envrc"] = envfiletype,
[".env"] = envfiletype,
[".env.dev"] = envfiletype,
[".env.prod"] = envfiletype,
[".env.example"] = envfiletype,
},
2021-11-24 14:04:07 +00:00
},
2021-11-09 14:51:56 +00:00
})
2021-11-24 14:04:07 +00:00
end,
})
2021-11-09 14:51:56 +00:00
-- Alignment tool
2021-11-24 14:04:07 +00:00
use("godlygeek/tabular")
2021-11-09 14:51:56 +00:00
-- Markdown renderer / wiki notes
2021-11-24 14:04:07 +00:00
use("vimwiki/vimwiki")
2021-11-09 14:51:56 +00:00
2021-11-15 16:17:17 +00:00
-- Markdown pretty view
2021-11-24 14:04:07 +00:00
use("ellisonleao/glow.nvim")
2021-11-15 16:17:17 +00:00
2021-11-09 14:51:56 +00:00
-- Snippet engine
2021-11-24 14:04:07 +00:00
use("L3MON4D3/LuaSnip")
2021-11-09 14:51:56 +00:00
-- =======================================================================
-- Language Server
-- =======================================================================
-- Language server engine
2021-11-24 14:04:07 +00:00
use({
"neovim/nvim-lspconfig",
requires = { "hrsh7th/cmp-nvim-lsp" },
2021-11-09 14:51:56 +00:00
config = function()
2021-11-24 14:04:07 +00:00
local capabilities = require("cmp_nvim_lsp").update_capabilities(
2021-11-09 14:51:56 +00:00
vim.lsp.protocol.make_client_capabilities()
)
2021-11-24 14:04:07 +00:00
require("lspconfig").rust_analyzer.setup({ capabilities = capabilities })
require("lspconfig").tflint.setup({ capabilities = capabilities })
require("lspconfig").terraformls.setup({ capabilities = capabilities })
require("lspconfig").pyright.setup({
2021-11-09 14:51:56 +00:00
cmd = { "poetry", "run", "pyright-langserver", "--stdio" },
capabilities = capabilities,
2021-11-24 14:04:07 +00:00
})
end,
})
2021-05-13 18:40:38 +00:00
2021-11-09 14:51:56 +00:00
-- Pretty highlights
2021-11-24 14:04:07 +00:00
use("folke/lsp-colors.nvim")
2021-11-09 14:51:56 +00:00
2021-11-24 14:03:18 +00:00
-- Linting
2021-11-24 14:04:07 +00:00
use({
"jose-elias-alvarez/null-ls.nvim",
2021-11-24 22:12:46 +00:00
branch = "main",
2021-11-24 14:03:18 +00:00
requires = {
2021-11-24 14:04:07 +00:00
"nvim-lua/plenary.nvim",
"neovim/nvim-lspconfig",
2021-11-24 14:03:18 +00:00
},
config = function()
2022-01-13 23:23:12 +00:00
require("null-ls").setup({
2021-11-24 14:04:07 +00:00
sources = {
2021-11-24 14:03:18 +00:00
require("null-ls").builtins.formatting.stylua,
2021-11-24 14:28:12 +00:00
require("null-ls").builtins.formatting.black.with({
command = "poetry",
args = { "run", "black", "--quiet", "--fast", "-" },
}),
2021-11-24 14:03:18 +00:00
require("null-ls").builtins.formatting.fish_indent,
2021-11-24 14:28:12 +00:00
-- require("null-ls").builtins.formatting.nixfmt,
2021-11-24 14:03:18 +00:00
require("null-ls").builtins.formatting.rustfmt,
2021-11-24 14:28:12 +00:00
require("null-ls").builtins.diagnostics.shellcheck,
2021-11-24 14:04:07 +00:00
require("null-ls").builtins.formatting.shfmt.with({
extra_args = { "-i", "4", "-ci" },
2021-11-24 14:03:18 +00:00
}),
require("null-ls").builtins.formatting.terraform_fmt,
-- require("null-ls").builtins.diagnostics.luacheck,
-- require("null-ls").builtins.diagnostics.markdownlint,
-- require("null-ls").builtins.diagnostics.pylint,
2021-11-24 14:04:07 +00:00
},
-- Format on save
on_attach = function(client)
if client.resolved_capabilities.document_formatting then
vim.cmd([[
augroup LspFormatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()
augroup END
]])
end
end,
2021-11-24 14:03:18 +00:00
})
2021-11-24 14:04:07 +00:00
end,
})
2021-11-24 14:03:18 +00:00
2021-11-09 14:51:56 +00:00
-- =======================================================================
-- Completion System
-- =======================================================================
-- Completion sources
2021-11-24 14:04:07 +00:00
use("hrsh7th/cmp-nvim-lsp") --- Language server completion plugin
use("hrsh7th/cmp-buffer") --- Generic text completion
use("hrsh7th/cmp-path") --- Local file completion
use("hrsh7th/cmp-cmdline") --- Command line completion
use("hrsh7th/cmp-nvim-lua") --- Nvim lua api completion
use("saadparwaiz1/cmp_luasnip") --- Luasnip completion
use("lukas-reineke/cmp-rg") --- Ripgrep completion
2021-11-09 14:51:56 +00:00
-- Completion engine
2021-11-24 14:04:07 +00:00
use({
"hrsh7th/nvim-cmp",
requires = { "L3MON4D3/LuaSnip" },
2021-11-09 14:51:56 +00:00
config = function()
2021-11-24 14:04:07 +00:00
local cmp = require("cmp")
2021-11-09 14:51:56 +00:00
cmp.setup({
snippet = {
expand = function(args)
2021-11-24 14:04:07 +00:00
require("luasnip").lsp_expand(args.body)
2021-11-09 14:51:56 +00:00
end,
},
mapping = {
2021-11-24 14:04:07 +00:00
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
["<Esc>"] = function(fallback)
2021-11-09 14:51:56 +00:00
cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
})
2021-11-24 14:04:07 +00:00
vim.cmd("stopinsert") --- Abort and leave insert mode
2021-11-09 14:51:56 +00:00
end,
-- ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
-- ['<S-Tab>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 's' }),
2021-11-24 14:04:07 +00:00
["<CR>"] = cmp.mapping.confirm({
2021-11-09 14:51:56 +00:00
behavior = cmp.ConfirmBehavior.Insert,
select = true,
2021-11-15 01:32:02 +00:00
}),
2021-11-24 14:04:07 +00:00
["<C-r>"] = cmp.mapping.confirm({
2021-11-15 01:32:02 +00:00
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
2021-11-24 14:04:07 +00:00
["<C-l>"] = cmp.mapping(function(fallback)
if require("luasnip").expand_or_jumpable() then
require("luasnip").expand_or_jump()
2021-11-15 01:32:02 +00:00
end
2021-11-24 14:04:07 +00:00
end, { "i", "s" }),
2021-11-09 14:51:56 +00:00
},
sources = {
2021-11-24 14:04:07 +00:00
{ name = "nvim_lua" },
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "luasnip" },
{ name = "buffer", keyword_length = 3, max_item_count = 10 },
2021-11-13 21:50:28 +00:00
{
2021-11-24 14:04:07 +00:00
name = "rg",
keyword_length = 6,
max_item_count = 10,
2021-12-01 13:08:58 +00:00
option = { additional_arguments = "--ignore-case" },
2021-11-13 21:50:28 +00:00
},
2021-11-09 14:51:56 +00:00
},
experimental = {
native_menu = false, --- Use cmp menu instead of Vim menu
2021-11-24 14:04:07 +00:00
ghost_text = true, --- Show preview auto-completion
2021-11-09 14:51:56 +00:00
},
})
-- Use buffer source for `/`
2021-11-24 14:04:07 +00:00
cmp.setup.cmdline("/", {
2021-11-09 14:51:56 +00:00
sources = {
2021-11-24 14:04:07 +00:00
{ name = "buffer", keyword_length = 5 },
},
2021-11-09 14:51:56 +00:00
})
-- Use cmdline & path source for ':'
2021-11-24 14:04:07 +00:00
cmp.setup.cmdline(":", {
2021-11-09 14:51:56 +00:00
sources = cmp.config.sources({
2021-11-24 14:04:07 +00:00
{ name = "path" },
2021-11-09 14:51:56 +00:00
}, {
2021-11-24 14:04:07 +00:00
{ name = "cmdline" },
}),
2021-11-08 04:11:17 +00:00
})
2021-11-24 14:04:07 +00:00
end,
})
2021-11-08 04:11:17 +00:00
2021-11-09 14:51:56 +00:00
-- =======================================================================
-- Syntax
-- =======================================================================
2021-11-08 04:11:17 +00:00
2021-11-09 14:51:56 +00:00
-- Syntax engine
2021-11-24 14:04:07 +00:00
use({
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
2021-11-09 14:51:56 +00:00
config = function()
2021-11-24 14:04:07 +00:00
require("nvim-treesitter.configs").setup({
2022-01-13 23:23:12 +00:00
ensure_installed = {
"hcl",
"python",
"lua",
"nix",
"fish",
"toml",
"yaml",
"json",
},
2021-11-09 14:51:56 +00:00
highlight = { enable = true },
indent = { enable = true },
2021-11-24 14:04:07 +00:00
})
end,
})
2021-11-08 04:11:17 +00:00
2021-11-09 14:51:56 +00:00
-- Additional syntax sources
2021-11-24 14:04:07 +00:00
use("bfontaine/Brewfile.vim") --- Brewfile syntax
use("chr4/nginx.vim") --- Nginx syntax
use("towolf/vim-helm") --- Helm syntax
use("rodjek/vim-puppet") --- Puppet syntax
2021-07-07 02:18:30 +00:00
2021-11-09 14:51:56 +00:00
-- =======================================================================
-- Fuzzy Launcher
-- =======================================================================
2021-11-08 04:11:17 +00:00
2021-11-24 14:04:07 +00:00
use({
"nvim-telescope/telescope.nvim",
requires = { "nvim-lua/plenary.nvim" },
2021-11-09 14:51:56 +00:00
config = function()
-- Telescope: quit instantly with escape
local actions = require("telescope.actions")
require("telescope").setup({
defaults = {
mappings = {
i = {
["<esc>"] = actions.close,
["<C-h>"] = "which_key",
},
2021-05-16 22:03:38 +00:00
},
},
2021-11-09 14:51:56 +00:00
pickers = {
2021-11-18 04:03:51 +00:00
find_files = { theme = "ivy" },
oldfiles = { theme = "ivy" },
2021-11-09 14:51:56 +00:00
buffers = { theme = "dropdown" },
},
extensions = {
fzy_native = {},
tmux = {},
zoxide = {},
neoclip = {},
2021-11-18 04:03:51 +00:00
project = {
2021-11-24 14:04:07 +00:00
base_dirs = { "~/dev/work" },
2021-11-18 04:03:51 +00:00
},
2021-11-09 14:51:56 +00:00
},
})
2021-11-24 14:04:07 +00:00
end,
})
2021-11-09 14:51:56 +00:00
-- Faster sorting
2021-11-24 14:04:07 +00:00
use("nvim-telescope/telescope-fzy-native.nvim")
2021-11-09 14:51:56 +00:00
-- Jump around tmux sessions
2021-11-24 14:04:07 +00:00
use("camgraff/telescope-tmux.nvim")
2021-11-09 14:51:56 +00:00
-- Jump directories
2021-11-24 14:04:07 +00:00
use({
"jvgrootveld/telescope-zoxide",
requires = { "nvim-lua/popup.nvim" },
})
2021-05-13 18:40:38 +00:00
2021-11-18 04:03:51 +00:00
-- Jump projects
2021-11-24 14:04:07 +00:00
use({
"nvim-telescope/telescope-project.nvim",
requires = { "nvim-telescope/telescope.nvim" },
2021-11-18 04:03:51 +00:00
config = function()
2021-11-24 14:04:07 +00:00
require("telescope").load_extension("project")
end,
})
2021-11-18 04:03:51 +00:00
2021-11-09 14:51:56 +00:00
-- Clipboard history
2021-11-24 14:04:07 +00:00
use({
2021-11-09 14:51:56 +00:00
"AckslD/nvim-neoclip.lua",
2021-11-24 14:04:07 +00:00
branch = "main",
2021-11-09 14:51:56 +00:00
requires = {
2021-11-24 14:04:07 +00:00
{ "tami5/sqlite.lua", module = "sqlite" },
{ "nvim-telescope/telescope.nvim" },
2021-11-09 14:51:56 +00:00
},
config = function()
2021-11-24 14:04:07 +00:00
require("neoclip").setup({
2021-11-09 14:51:56 +00:00
enable_persistant_history = true,
2021-11-24 14:04:07 +00:00
default_register = { "+", '"' },
2021-11-24 13:25:39 +00:00
keys = {
2022-01-13 23:23:12 +00:00
telescope = {
i = { paste = "<c-v>" },
},
2021-11-24 13:25:39 +00:00
},
2021-11-09 14:51:56 +00:00
})
2021-11-24 14:04:07 +00:00
require("telescope").load_extension("neoclip")
end,
})
2021-11-09 14:51:56 +00:00
2021-11-15 01:32:44 +00:00
-- Project bookmarks
2021-11-24 14:04:07 +00:00
use({
"ThePrimeagen/harpoon",
2021-11-18 04:03:51 +00:00
requires = {
2021-11-24 14:04:07 +00:00
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim",
},
})
2021-11-18 04:03:51 +00:00
-- TLDR Lookup
2021-11-24 14:04:07 +00:00
use({
"mrjones2014/tldr.nvim",
requires = { "nvim-telescope/telescope.nvim" },
})
2021-11-15 01:32:44 +00:00
2021-11-09 14:51:56 +00:00
-- =======================================================================
-- Install on initial bootstrap
if packer_bootstrap then
2021-11-24 14:04:07 +00:00
require("packer").sync()
2021-11-09 14:51:56 +00:00
end
end)
-- ===========================================================================
2021-05-13 18:40:38 +00:00
-- Settings
2021-11-09 14:51:56 +00:00
-- ===========================================================================
2021-11-24 14:04:07 +00:00
vim.o.termguicolors = true --- Set to truecolor
vim.o.hidden = true --- Don't unload buffers when leaving them
vim.wo.number = true --- Show line numbers
vim.wo.relativenumber = true --- Relative numbers instead of absolute
vim.o.list = true --- Reveal whitespace with dashes
vim.o.expandtab = true --- Tabs into spaces
vim.o.shiftwidth = 4 --- Amount to shift with > key
vim.o.softtabstop = 4 --- Amount to shift with <TAB> key
vim.o.ignorecase = true --- Ignore case when searching
vim.o.smartcase = true --- Check case when using capitals in search
vim.o.infercase = true --- Don't match cases when completing suggestions
vim.o.incsearch = true --- Search while typing
vim.o.visualbell = true --- No sounds
vim.o.scrolljump = 1 --- Number of lines to scroll
vim.o.scrolloff = 3 --- Margin of lines to see while scrolling
vim.o.splitright = true --- Vertical splits on the right side
vim.o.splitbelow = true --- Horizontal splits on the bottom side
vim.o.pastetoggle = "<F3>" --- Use F3 to enter raw paste mode
2021-11-09 14:51:56 +00:00
vim.o.clipboard = "unnamedplus" --- Uses system clipboard for yanking
2021-11-24 14:04:07 +00:00
vim.o.updatetime = 300 --- Faster diagnostics
vim.o.mouse = "nv" --- Mouse interaction / scrolling
2021-05-13 18:40:38 +00:00
-- Neovim features
2021-11-24 14:04:07 +00:00
vim.o.inccommand = "split" --- Live preview search and replace
2021-11-09 14:51:56 +00:00
vim.o.completeopt = "menu,menuone,noselect" --- Required for nvim-cmp completion
2021-11-08 04:11:17 +00:00
-- Required until 0.6.0: do not source the default filetype.vim
vim.g.did_load_filetypes = 1
2021-05-13 18:40:38 +00:00
-- Remember last position when reopening file
2021-11-24 14:04:07 +00:00
vim.api.nvim_exec(
[[
2021-11-08 04:11:17 +00:00
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
2021-11-24 14:04:07 +00:00
]],
false
)
2021-05-13 18:40:38 +00:00
-- Better backup, swap and undo storage
2021-11-24 14:04:07 +00:00
vim.o.backup = true --- Easier to recover and more secure
2021-11-09 14:51:56 +00:00
vim.bo.swapfile = false --- Instead of swaps, create backups
2021-11-24 14:04:07 +00:00
vim.bo.undofile = true --- Keeps undos after quit
2021-05-13 18:40:38 +00:00
-- Create backup directories if they don't exist
2021-11-08 04:11:17 +00:00
-- Should be fixed in 0.6 by https://github.com/neovim/neovim/pull/15433
2021-11-24 14:04:07 +00:00
vim.o.backupdir = vim.fn.stdpath("cache") .. "/backup"
vim.api.nvim_exec(
[[
2021-05-13 18:40:38 +00:00
if !isdirectory(&backupdir)
call mkdir(&backupdir, "p")
endif
2021-11-24 14:04:07 +00:00
]],
false
)
2021-05-13 18:40:38 +00:00
-- LaTeX options
2021-11-24 14:04:07 +00:00
vim.api.nvim_exec(
[[
2021-05-13 18:40:38 +00:00
au FileType tex inoremap ;bf \textbf{}<Esc>i
au BufWritePost *.tex silent! execute "!pdflatex -output-directory=%:p:h % >/dev/null 2>&1" | redraw!
2021-11-24 14:04:07 +00:00
]],
false
)
2021-05-13 18:40:38 +00:00
-- Highlight when yanking
2021-11-24 14:04:07 +00:00
vim.api.nvim_exec(
[[
2021-05-13 18:40:38 +00:00
au TextYankPost * silent! lua vim.highlight.on_yank { timeout = 250 }
2021-11-24 14:04:07 +00:00
]],
false
)
2021-05-13 18:40:38 +00:00
-- Netrw
2021-11-24 14:04:07 +00:00
vim.g.netrw_liststyle = 3 -- Change style to 'tree' view
vim.g.netrw_banner = 0 -- Remove useless banner
vim.g.netrw_winsize = 15 -- Explore window takes % of page
2021-05-13 18:40:38 +00:00
vim.g.netrw_browse_split = 4 -- Open in previous window
2021-11-24 14:04:07 +00:00
vim.g.netrw_altv = 1 -- Always split left
2021-05-13 18:40:38 +00:00
-- VimWiki
vim.g.vimwiki_list = {
{
["path"] = "$NOTES_PATH",
["syntax"] = "markdown",
["index"] = "home",
2021-11-24 14:04:07 +00:00
["ext"] = ".md",
},
2021-05-13 18:40:38 +00:00
}
vim.g.vimwiki_key_mappings = {
["all_maps"] = 1,
["mouse"] = 1,
}
2021-11-24 14:04:07 +00:00
vim.g.vimwiki_auto_chdir = 1 -- Set local dir to Wiki when open
vim.g.vimwiki_create_link = 0 -- Don't automatically create new links
vim.g.vimwiki_listsyms = " x" -- Set checkbox symbol progression
2021-05-13 18:40:38 +00:00
vim.g.vimwiki_table_mappings = 0 -- VimWiki table keybinds interfere with tab completion
2021-11-24 14:04:07 +00:00
vim.api.nvim_exec(
[[
2021-05-13 18:40:38 +00:00
au FileType markdown inoremap ;tt <Esc>:AddTag<CR>
function! PInsert(item)
let @z=a:item
norm "zpx
endfunction
2021-05-23 16:35:33 +00:00
command! AddTag call fzf#run({'source': 'rg "#[A-Za-z/]+[ |\$]" -o --no-filename --no-line-number | sort | uniq', 'sink': function('PInsert')})
2021-11-24 14:04:07 +00:00
]],
false
)
2021-05-13 18:40:38 +00:00
2021-11-18 04:03:51 +00:00
-- ===========================================================================
-- Custom Functions
-- ===========================================================================
grep_notes = function()
2021-11-24 13:25:39 +00:00
local opts = {
prompt_title = "Search Notes",
2021-11-24 14:04:07 +00:00
cwd = "$NOTES_PATH",
2021-11-24 13:25:39 +00:00
}
2021-11-24 14:04:07 +00:00
require("telescope.builtin").live_grep(opts)
2021-11-18 04:03:51 +00:00
end
find_notes = function()
2021-11-24 13:25:39 +00:00
local opts = {
prompt_title = "Find Notes",
2021-11-24 14:04:07 +00:00
cwd = "$NOTES_PATH",
2021-11-24 13:25:39 +00:00
}
2021-11-24 14:04:07 +00:00
require("telescope.builtin").find_files(opts)
2021-11-18 04:03:51 +00:00
end
find_downloads = function()
2021-11-24 13:25:39 +00:00
local opts = {
prompt_title = "Find Downloads",
2021-11-24 14:04:07 +00:00
cwd = "~/Downloads",
2021-11-24 13:25:39 +00:00
}
2021-11-24 14:04:07 +00:00
require("telescope.builtin").file_browser(opts)
2021-11-18 04:03:51 +00:00
end
2021-11-24 13:25:39 +00:00
choose_project = function()
2021-11-24 14:04:07 +00:00
local opts = require("telescope.themes").get_ivy({
2021-11-24 13:25:39 +00:00
layout_config = {
bottom_pane = {
height = 10,
},
},
2021-11-24 14:04:07 +00:00
})
require("telescope").extensions.project.project(opts)
2021-11-24 13:25:39 +00:00
end
clipboard_history = function()
2021-11-24 14:04:07 +00:00
local opts = require("telescope.themes").get_cursor({
2021-11-24 13:25:39 +00:00
layout_config = {
cursor = {
width = 150,
},
},
2021-11-24 14:04:07 +00:00
})
require("telescope").extensions.neoclip.neoclip(opts)
2021-11-24 13:25:39 +00:00
end
command_history = function()
2021-11-24 14:04:07 +00:00
local opts = require("telescope.themes").get_ivy({
2021-11-24 13:25:39 +00:00
layout_config = {
bottom_pane = {
height = 15,
2021-11-24 14:04:07 +00:00
},
},
})
require("telescope.builtin").command_history(opts)
2021-11-24 13:25:39 +00:00
end
2021-11-09 14:51:56 +00:00
-- ===========================================================================
-- Key Mapping
-- ===========================================================================
2021-05-13 18:40:38 +00:00
2021-11-13 21:29:09 +00:00
-- Function to cut down config boilerplate
local key = function(mode, key_sequence, action, params)
params = params or {}
params["noremap"] = true
vim.api.nvim_set_keymap(mode, key_sequence, action, params)
end
2021-05-13 18:40:38 +00:00
-- Remap space as leader key
2021-11-24 14:04:07 +00:00
key("", "<Space>", "<Nop>", { silent = true })
2021-05-13 18:40:38 +00:00
vim.g.mapleader = " "
vim.g.maplocalleader = " "
2021-11-08 04:11:17 +00:00
-- Keep selection when changing indentation
2021-11-13 21:29:09 +00:00
key("v", "<", "<gv")
key("v", ">", ">gv")
2021-11-08 04:11:17 +00:00
2021-11-17 13:35:53 +00:00
-- Clear search register
2021-11-24 14:04:07 +00:00
key("n", "<CR>", ":noh<CR><CR>", { silent = true })
2021-05-13 18:40:38 +00:00
-- Shuffle lines around
2021-11-13 21:29:09 +00:00
key("n", "<A-j>", ":m .+1<CR>==")
key("n", "<A-k>", ":m .-2<CR>==")
key("i", "<A-j>", "<Esc>:m .+1<CR>==gi")
key("i", "<A-k>", "<Esc>:m .-2<CR>==gi")
key("v", "<A-j>", ":m '>+1<CR>gv=gv")
key("v", "<A-k>", ":m '<-2<CR>gv=gv")
2021-05-13 18:40:38 +00:00
2021-11-08 04:11:17 +00:00
-- Telescope (fuzzy finder)
2021-11-18 04:03:51 +00:00
key("n", "<Leader>k", ":Telescope keymaps<CR>")
2021-11-13 21:29:09 +00:00
key("n", "<Leader>/", ":Telescope live_grep<CR>")
key("n", "<Leader>ff", ":Telescope find_files<CR>")
2021-11-18 04:03:51 +00:00
key("n", "<Leader>fp", ":Telescope git_files<CR>")
key("n", "<Leader>fN", "<Cmd>lua find_notes()<CR>")
key("n", "<Leader>N", "<Cmd>lua grep_notes()<CR>")
key("n", "<Leader>fD", "<Cmd>lua find_downloads()<CR>")
2021-11-13 21:29:09 +00:00
key("n", "<Leader>fa", ":Telescope file_browser<CR>")
2021-11-17 13:35:53 +00:00
key("n", "<Leader>fw", ":Telescope grep_string<CR>")
2021-11-13 21:29:09 +00:00
key("n", "<Leader>wt", ":Telescope tmux sessions<CR>")
key("n", "<Leader>ww", ":Telescope tmux windows<CR>")
key("n", "<Leader>w/", ":Telescope tmux pane_contents<CR>")
key("n", "<Leader>fz", ":Telescope zoxide list<CR>")
key("n", "<Leader>b", ":Telescope buffers<CR>")
key("n", "<Leader>hh", ":Telescope help_tags<CR>")
key("n", "<Leader>fr", ":Telescope oldfiles<CR>")
key("n", "<Leader>cc", ":Telescope commands<CR>")
2021-11-24 13:25:39 +00:00
key("n", "<Leader>cr", "<Cmd>lua command_history()<CR>")
key("n", "<Leader>y", "<Cmd>lua clipboard_history()<CR>")
key("i", "<c-y>", "<Cmd>lua clipboard_history()<CR>")
2021-11-13 21:29:09 +00:00
key("n", "<Leader>s", ":Telescope current_buffer_fuzzy_find<CR>")
key("n", "<Leader>gc", ":Telescope git_commits<CR>")
key("n", "<Leader>gf", ":Telescope git_bcommits<CR>")
key("n", "<Leader>gb", ":Telescope git_branches<CR>")
key("n", "<Leader>gs", ":Telescope git_status<CR>")
2021-11-24 13:25:39 +00:00
key("n", "<C-p>", "<Cmd>lua choose_project()<CR>")
2021-11-08 04:11:17 +00:00
2021-11-15 01:32:44 +00:00
-- Harpoon
2021-11-24 13:25:39 +00:00
key("n", "<Leader>m", "<Cmd>lua require('harpoon.mark').add_file()<CR><Esc>")
key("n", "<Leader>`", "<Cmd>lua require('harpoon.ui').toggle_quick_menu()<CR><Esc>")
key("n", "<Leader>1", "<Cmd>lua require('harpoon.ui').nav_file(1)<CR><Esc>")
key("n", "<Leader>2", "<Cmd>lua require('harpoon.ui').nav_file(2)<CR><Esc>")
key("n", "<Leader>3", "<Cmd>lua require('harpoon.ui').nav_file(3)<CR><Esc>")
2021-11-15 01:32:44 +00:00
2021-11-08 04:11:17 +00:00
-- LSP
2021-11-24 14:04:07 +00:00
key("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", { silent = true })
key("n", "gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>", { silent = true })
key("n", "gh", "<Cmd>lua vim.lsp.buf.hover()<CR>", { silent = true })
key("n", "]e", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>", { silent = true })
key("n", "[e", "<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", { silent = true })
key("n", "<Leader>e", "<Cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", { silent = true })
2021-05-13 18:40:38 +00:00
-- File commands
2021-11-13 21:29:09 +00:00
key("n", "<Leader>q", ":quit<CR>")
key("n", "<Leader>Q", ":quitall<CR>")
key("n", "<Leader>fs", ":write<CR>")
2021-11-24 14:04:07 +00:00
key("n", "<Leader>fd", ":lcd %:p:h<CR>", { silent = true })
key("n", "<Leader>fu", ":lcd ..<CR>", { silent = true })
key("n", "<Leader><Tab>", ":b#<CR>", { silent = true })
key("n", "<Leader>gr", ":!gh repo view -w<CR><CR>", { silent = true })
key("n", "<Leader>tt", [[<Cmd>exe 'edit $NOTES_PATH/journal/'.strftime("%Y-%m-%d_%a").'.md'<CR>]])
2021-11-18 04:02:29 +00:00
key("n", "<Leader>jj", ":!journal<CR>:e<CR>")
2021-05-13 18:40:38 +00:00
-- Window commands
2021-11-13 21:29:09 +00:00
key("n", "<Leader>wv", ":vsplit<CR>")
key("n", "<Leader>wh", ":split<CR>")
key("n", "<Leader>wm", ":only<CR>")
2021-05-13 18:40:38 +00:00
-- Tabularize
2021-11-13 21:29:09 +00:00
key("", "<Leader>ta", ":Tabularize /")
key("", "<Leader>t#", ":Tabularize /#<CR>")
2021-11-24 13:25:39 +00:00
key("", "<Leader>tl", ":Tabularize /---<CR>")
2021-05-13 18:40:38 +00:00
2021-08-04 15:39:27 +00:00
-- Vimrc editing
2021-11-13 21:29:09 +00:00
key("n", "<Leader>fv", ":edit $MYVIMRC<CR>")
key("n", "<Leader>rr", ":luafile $MYVIMRC<CR>")
2021-11-18 04:02:29 +00:00
key("n", "<Leader>rp", ":luafile $MYVIMRC<CR>:PackerInstall<CR>:")
2021-11-13 21:29:09 +00:00
key("n", "<Leader>rc", ":luafile $MYVIMRC<CR>:PackerCompile<CR>")
2021-08-04 15:39:27 +00:00
-- Keep cursor in place
2021-11-24 14:04:07 +00:00
key("n", "n", "nzz")
key("n", "N", "Nzz")
key("n", "J", "mzJ`z") --- Mark and jump back to it
2021-08-04 15:39:27 +00:00
-- Add undo breakpoints
2021-11-24 14:04:07 +00:00
key("i", ",", ",<C-g>u")
key("i", ".", ".<C-g>u")
key("i", "!", "!<C-g>u")
key("i", "?", "?<C-g>u")
2021-11-09 14:51:56 +00:00
-- Other
2021-11-24 14:04:07 +00:00
key("t", "<A-CR>", "<C-\\><C-n>") --- Exit terminal mode
key("n", "<A-CR>", ":noh<CR>", { silent = true }) --- Clear search in VimWiki
key("n", "Y", "y$") --- Copy to end of line
2021-11-17 13:35:53 +00:00
key("v", "<C-r>", "y<Esc>:%s/<C-r>+//gc<left><left><left>") --- Substitute selected
2021-11-24 14:04:07 +00:00
key("v", "D", "y'>gp") --- Duplicate selected