1
Fork 0

A lot of neovim config updates

This commit is contained in:
Matei Adriel 2022-10-09 03:28:51 +02:00
parent d3ab72c6c8
commit 98e8510ae7
21 changed files with 874 additions and 152 deletions

View file

@ -0,0 +1,22 @@
local function makeEnv(cond)
return {
active = cond,
unless = function(f)
if not cond() then f()
end
end,
when = function(f)
if cond() then f()
end
end
}
end
return {
vscode = makeEnv(function()
return vim.g.vscode ~= nil
end),
firevim = makeEnv(function()
return vim.g.started_by_firenvim ~= nil
end)
}

View file

@ -1,15 +0,0 @@
local M = {}
function M.when(f)
if vim.g.vscode ~= nil then
f()
end
end
function M.unless(f)
if vim.g.vscode == nil then
f()
end
end
return M

View file

@ -2,6 +2,7 @@ local M = {}
function M.setup()
-- Import my other files
require("impatient") -- should make startups take less
require("my.paq").setup()
require("my.theme").setup()
require("my.options").setup()

View file

@ -21,25 +21,48 @@ function M.mapSilent(mode, lhs, rhs, opts)
end
-- Performs a basic move operation
function M.move(from, to)
vim.keymap.set("n", to, from)
function M.move(from, to, opts)
vim.keymap.set("n", to, from, opts)
vim.keymap.set("n", from, "<Nop>")
end
function M.setup()
M.move("q", "yq")
M.move("q", "yq", { desc = "Record macro" })
M.move("Q", "yQ")
M.move("<C-^>", "<Leader>a", { desc = "Go to previous file" })
vim.keymap.set("n", "Q", ":wqa<cr>") -- Save and quit
vim.keymap.set("n", "Q", ":wqa<cr>", { desc = "Save all files and quit" })
vim.keymap.set("n", "<leader>rw", ":%s/<C-r><C-w>/", {
desc = "Replace word in file"
})
-- Create chords
if arpeggio ~= nil then
arpeggio.chord("n", "vs", "<C-w>v") -- Create vertical split
arpeggio.chord("n", "ji", ":w<cr>") -- Saving
arpeggio.chordSilent("n", "ji", ":silent :write<cr>") -- Saving
arpeggio.chord("i", "jk", "<Esc>") -- Remap Esc to jk
arpeggio.chord("nv", "<Leader>a", "<C-6><cr>") -- Rebind switching to the last pane using leader+a
arpeggio.chord("nv", "cp", "\"+") -- Press cp to use the global clipboard
arpeggio.chord("n", "rw", ":%s/<C-r><C-w>/") -- Press rw to rename word under cursor
end
local status, wk = pcall(require, "which-key")
if status then
wk.register({
["<leader>"] = {
f = {
name = "Files"
},
g = {
name = "Go to"
},
r = {
name = "Rename / Replace"
},
["<leader>"] = {
name = "Easymotion"
},
v = "which_key_ignore"
}
})
end
return M

View file

@ -3,40 +3,46 @@ local helpers = require("my.helpers")
local M = {}
function M.setup()
local opt = vim.opt -- to set options
local opt = vim.opt -- to set options
-- Basic options
opt.joinspaces = false -- No double spaces with join
opt.list = true -- Show some invisible characters
-- Disable filetype.vim
vim.g.do_filetype_lua = true
vim.g.did_load_filetypes = false
opt.number = true -- Show line numbers
opt.relativenumber = true -- Relative line numbers
-- Basic options
opt.joinspaces = false -- No double spaces with join
opt.list = true -- Show some invisible characters
opt.cmdheight = 0 -- Hide command line when it's not getting used
-- TODO: only do this for specific filestypes
opt.expandtab = true -- Use spaces for the tab char
-- Line numbers
opt.number = true -- Show line numbers
opt.relativenumber = true -- Relative line numbers
opt.scrolloff = 4 -- Lines of context
opt.shiftround = true -- Round indent
opt.shiftwidth = 2 -- Size of an indent
opt.termguicolors = true -- True color support
-- TODO: only do this for specific filestypes
opt.expandtab = true -- Use spaces for the tab char
opt.ignorecase = true -- Ignore case
opt.smartcase = true -- Do not ignore case with capitals
opt.scrolloff = 4 -- Lines of context
opt.shiftround = true -- Round indent
opt.shiftwidth = 2 -- Size of an indent
opt.termguicolors = true -- True color support
opt.smartindent = true -- Insert indents automatically
opt.ignorecase = true -- Ignore case
opt.smartcase = true -- Do not ignore case with capitals
opt.splitbelow = true -- Put new windows below current
opt.splitright = true -- Put new windows right of current
opt.smartindent = true -- Insert indents automatically
opt.wrap = false -- Disable line wrap
opt.wildmode = {'list', 'longest'} -- Command-line completion mode
opt.completeopt = {"menu", "menuone", "noselect"}
opt.splitbelow = true -- Put new windows below current
opt.splitright = true -- Put new windows right of current
-- Set leader
helpers.global("mapleader", " ")
opt.wrap = false -- Disable line wrap (by default)
opt.wildmode = { 'list', 'longest' } -- Command-line completion mode
opt.completeopt = { "menu", "menuone", "noselect" }
-- Import other options
require("my.options.folding").setup()
-- Set leader
helpers.global("mapleader", " ")
-- Import other options
require("my.options.folding").setup()
end
return M

View file

@ -47,7 +47,7 @@ function M.setup()
"ShinKage/idris2-nvim", -- idris2 support
"udalov/kotlin-vim", -- kotlin support
"haringsrob/nvim_context_vt", -- show context on closing parenthesis
"vuki656/package-info.nvim", -- shows latest versions in package.json
-- "vuki656/package-info.nvim", -- shows latest versions in package.json
"j-hui/fidget.nvim", -- show progress for lsp stuff
"stevearc/dressing.nvim", -- better ui I guess
"rktjmp/paperplanes.nvim", -- export to pastebin like services
@ -55,16 +55,16 @@ function M.setup()
"jbyuki/venn.nvim", -- draw ascii diagrams
"hrsh7th/cmp-omni", -- omnifunc source for cmp
"ekickx/clipboard-image.nvim", -- paste images from clipbaord
"glacambre/firenvim", -- vim inside chrome
"lewis6991/impatient.nvim", -- faster startup times
"tpope/vim-abolish", -- abbreviations on steroids
"mrjones2014/smart-splits.nvim", -- the name says it all
-- Git stuff
"ruifm/gitlinker.nvim", -- generate permalinks for code
"TimUntersberger/neogit" -- magit clone
-- "TimUntersberger/neogit" -- magit clone
}
-- This might get installed by nix!
if os.getenv("NVIM_INSTALL_TREESITTER") then
table.insert(base, 2, { "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" })
end
table.insert(base, 2, { "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" })
for _, v in ipairs(themePackages) do

View file

@ -0,0 +1,13 @@
local M = {}
function M.abolish(from, to)
vim.cmd(":Abolish " .. from .. " " .. to)
end
function M.abolishMany(many)
for _, entry in pairs(many) do
M.abolish(entry[1], entry[2])
end
end
return M

View file

@ -10,17 +10,17 @@ function M.chord(mode, lhs, rhs, opts)
M.chord(c, lhs, rhs, opts)
end
else
local options = helpers.mergeTables(opts, { noremap = true })
local options = helpers.mergeTables(opts or {}, { noremap = true })
local settings = options.settings or ""
if options.silent then settings = settings .. "s" end
arpeggio(mode, settings, options.noremap, lhs, rhs)
arpeggio(mode, settings, not options.noremap, lhs, rhs)
end
end
function M.chordSilent(mode, lhs, rhs, opts)
local options = helpers.mergeTables(opts, { silent = true })
local options = helpers.mergeTables(opts or {}, { silent = true })
M.chord(mode, lhs, rhs, options)
end

View file

@ -22,7 +22,7 @@ function M.setup()
},
}
vim.keymap.set("n", "<leader>p", ":PasteImg<cr>")
vim.keymap.set("n", "<leader>p", ":PasteImg<cr>", { desc = "Paste image from clipboard" })
end
return M

View file

@ -1,10 +1,27 @@
local M = {}
function M.setup()
vim.keymap.set("n", "qf", "<Plug>(easymotion-bd-f)")
vim.keymap.set("n", "qj", "<Plug>(easymotion-overwin-f2)")
vim.keymap.set("n", "qw", "<Plug>(easymotion-bd-w)")
vim.keymap.set("n", "qL", "<Plug>(easymotion-bd-L)")
local opts = function(desc)
return {
desc = desc,
silent = true
}
end
-- vim.keymap.set("n", "q", "<Plug>(easymotion-prefix)")
vim.keymap.set("n", "qf", "<Plug>(easymotion-bd-f)", opts("Hop to char"))
vim.keymap.set("n", "qj", "<Plug>(easymotion-overwin-f2)", opts("Hop to char pair"))
vim.keymap.set("n", "qw", ":silent <Plug>(easymotion-bd-w)", opts("Hop to word"))
vim.keymap.set("n", "qL", "silent <Plug>(easymotion-bd-L)", opts("Hop to line (?)"))
local status, wk = pcall(require, "which-key")
if status then
wk.register({
q = {
name = "Easymotion"
}
})
end
end
return M

View file

@ -0,0 +1,15 @@
local M = {}
function M.setup()
vim.g.firenvim_config = {
localSettings = {
['.*'] = {
filename = '/tmp/firevim_{hostname}_{pathname%10}_{timestamp%32}.{extension}',
}
}
}
print("Initialized firenvim")
end
return M

View file

@ -0,0 +1,101 @@
local Hydra = require('hydra')
local pcmd = require('hydra.keymap-util').pcmd
local splits = require('smart-splits')
local M = {}
local venn_hint = [[
Arrow^^^^^^ Select region with <C-v>
^ ^ _K_ ^ ^ _f_: surround it with box
_H_ ^ ^ _L_
^ ^ _J_ ^ ^ _<Esc>_
]]
local window_hint = [[
^^^^^^^^^^^^ Move ^^ Size ^^ ^^ Split
^^^^^^^^^^^^------------- ^^-----------^^ ^^---------------
^ ^ _k_ ^ ^ ^ ^ _K_ ^ ^ ^ _<C-k>_ ^ _s_: horizontally
_h_ ^ ^ _l_ _H_ ^ ^ _L_ _<C-h>_ _<C-l>_ _v_: vertically
^ ^ _j_ ^ ^ ^ ^ _J_ ^ ^ ^ _<C-j>_ ^ _q_: close
focus^^^^^^ window^^^^^^ ^_=_: equalize^ _o_: close remaining
]]
function M.setup()
Hydra({
name = 'Draw Diagram',
hint = venn_hint,
config = {
color = 'pink',
invoke_on_body = true,
hint = {
border = 'rounded'
},
on_enter = function()
vim.o.virtualedit = 'all'
end,
},
mode = 'n',
body = '<leader>v',
heads = {
{ 'H', '<C-v>h:VBox<CR>' },
{ 'J', '<C-v>j:VBox<CR>' },
{ 'K', '<C-v>k:VBox<CR>' },
{ 'L', '<C-v>l:VBox<CR>' },
{ 'f', ':VBox<CR>', { mode = 'v' } },
{ '<Esc>', nil, { exit = true } },
}
})
vim.keymap.set("n", "<C-w>", "<Nop>")
Hydra({
name = 'Windows',
hint = window_hint,
config = {
invoke_on_body = true,
hint = {
border = 'rounded',
offset = -1
}
},
mode = 'n',
body = '<C-w>',
heads = {
{ 'h', '<C-w>h' },
{ 'j', '<C-w>j' },
{ 'k', "<C-w>k" },
{ 'l', '<C-w>l' },
{ 'H', '<C-w>H' },
{ 'J', '<C-w>J' },
{ 'K', '<C-w>K' },
{ 'L', '<C-w>L' },
{ '<C-h>', function() splits.resize_left(2) end },
{ '<C-j>', function() splits.resize_down(2) end },
{ '<C-k>', function() splits.resize_up(2) end },
{ '<C-l>', function() splits.resize_right(2) end },
{ '=', '<C-w>=', { desc = 'equalize' } },
{ 's', pcmd('split', 'E36') },
{ '<C-s>', pcmd('split', 'E36'), { desc = false } },
{ 'v', pcmd('vsplit', 'E36') },
{ '<C-v>', pcmd('vsplit', 'E36'), { desc = false } },
{ 'w', '<C-w>w', { exit = true, desc = false } },
{ '<C-w>', '<C-w>w', { exit = true, desc = false } },
{ 'o', '<C-w>o', { exit = true, desc = 'remain only' } },
{ '<C-o>', '<C-w>o', { exit = true, desc = false } },
{ 'q', pcmd('close', 'E444'), { desc = 'close window' } },
{ '<C-q>', pcmd('close', 'E444'), { desc = false } },
{ '<Esc>', nil, { exit = true, desc = false } }
}
})
end
return M

View file

@ -1,36 +1,45 @@
local vscode = require("my.helpers.vscode")
local env = require("my.helpers.env")
local M = {}
function M.setup()
require "gitlinker".setup()
require('nvim_comment').setup()
require('fidget').setup()
require('dressing').setup()
vscode.unless(function()
require("presence"):setup({})
env.vscode.unless(function()
env.firevim.unless(function()
require("presence"):setup({})
require("my.plugins.nvim-tree").setup()
require("my.plugins.lualine").setup()
require("my.plugins.vimux").setup()
require("my.plugins.whichkey").setup()
end)
require("my.plugins.dashboard").setup()
require("my.plugins.treesitter").setup()
require("my.plugins.cmp").setup()
require("my.plugins.lspconfig").setup()
require("my.plugins.null-ls").setup()
require("my.plugins.nvim-tree").setup()
require("my.plugins.vimtex").setup()
require("my.plugins.lean").setup()
require("my.plugins.lualine").setup()
require("my.plugins.vimux").setup()
end)
if env.firevim.active() then
require("my.plugins.firevim").setup()
else
require("gitlinker").setup()
-- require("my.plugins.neogit").setup()
require("my.plugins.paperplanes").setup()
end
require("my.plugins.easymotion").setup()
require("my.plugins.autopairs").setup()
require("my.plugins.paperplanes").setup()
require("my.plugins.neogit").setup()
require("my.plugins.telescope").setup()
require("my.plugins.venn").setup()
require("my.plugins.hydra").setup()
require("my.plugins.clipboard-image").setup()
-- require("my.plugins.idris").setup()
-- require("which-key").setup()
-- require("my.plugins.slam").setup()
end
return M

View file

@ -1,11 +1,5 @@
local M = {}
local function map(buf, mode, lhs, rhs, opts)
local options = { noremap = true, silent = true }
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_buf_set_keymap(buf, mode, lhs, rhs, options)
end
function M.on_attach(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
@ -16,38 +10,34 @@ function M.on_attach(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePre", {
group = vim.api.nvim_create_augroup("LspFormatting", {}),
callback = function()
vim.lsp.buf.format({async = false})
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ async = false })
end
})
end
print("Setting up keybinds...")
local opts = function(desc)
return { noremap = true, silent = true, desc = desc }
end
-- Go to declaration / definition / implementation
map(bufnr, "n", 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>')
map(bufnr, "n", 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>')
map(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Go to declaration"))
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Go to definition"))
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Go to implementation"))
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Go to references"))
-- Hover
map(bufnr, 'n', 'J', "<cmd>lua vim.diagnostic.open_float()<CR>")
map(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>')
map(bufnr, 'n', 'L', '<cmd>lua vim.lsp.buf.signature_help()<CR>')
-- Workspace stuff
-- map(bufnr, 'n', '<leader>wa',
-- '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>')
-- map(bufnr, 'n', '<leader>wr',
-- '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>')
-- map(bufnr, 'n', '<leader>wl',
-- '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>')
vim.keymap.set("n", "J", vim.diagnostic.open_float, opts("Show diagnostic"))
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts("Hover"))
vim.keymap.set("n", "L", vim.lsp.buf.signature_help, opts("Signature help"))
-- Code actions
map(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>')
map(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>')
map(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>')
map(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>')
map(bufnr, 'n', '<leader>f',
'<cmd>lua vim.lsp.buf.format({async = true})<CR>')
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts("Rename"))
vim.keymap.set("n", "<leader>c", vim.lsp.buf.code_action, opts("Code actions"))
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format, opts("Format"))
print("Initialized language server!")
end

View file

@ -3,14 +3,18 @@ local lspconfig = require("my.plugins.lspconfig")
local M = {}
function M.setup()
local null_ls = require("null-ls")
local null_ls = require("null-ls")
local sources = {
null_ls.builtins.formatting.prettierd.with({extra_filetypes = {}}), -- format ts files
-- null_ls.builtins.formatting.lua_format -- format lua code
}
local sources = {
-- null_ls.builtins.formatting.prettierd.with({extra_filetypes = {}}), -- format ts files
null_ls.setup({sources = sources, on_attach = lspconfig.on_attach})
null_ls.builtins.formatting.prettier.with({ extra_filetypes = {} }), -- format ts files
-- null_ls.builtins.formatting.lua_format -- format lua code
}
null_ls.setup({
sources = sources, on_attach = lspconfig.on_attach
, debug = true })
end
return M

View file

@ -0,0 +1,11 @@
vim.opt.runtimepath:append("/home/adrielus/Projects/nvim-slam")
local slam = require("slam.")
local M = {}
function M.setup()
slam.set("n", "ty", ":echo \"slammin'\"<CR>")
slam.set("i", "ty", "<esc>")
end
return M

View file

@ -6,13 +6,19 @@ local function find_files_by_extension(extension)
return "find_files find_command=rg,--files,--glob=**/*." .. extension
end
local function with_theme(base, theme)
return base .. " theme=" .. theme
end
local defaultTheme = "ivy"
local keybinds = {
{ "<C-P>", "find_files" },
{ "<Leader>ft", find_files_by_extension("tex") },
{ "<Leader>fl", find_files_by_extension("lua") },
{ "<Leader>d", "diagnostics" },
{ "<C-F>", "live_grep" },
{ "<Leader>t", "builtin" },
{ "<C-P>", "find_files", "Find files" },
{ "<Leader>ft", find_files_by_extension("tex"), "Find tex files" },
{ "<Leader>fl", find_files_by_extension("lua"), "Find lua files" },
{ "<Leader>d", "diagnostics", "Diagnostics" },
{ "<C-F>", "live_grep", "Search in project" },
{ "<Leader>t", "builtin", "Show builtin pickers" },
}
local chords = {
@ -20,12 +26,16 @@ local chords = {
}
local function mkAction(action)
if not string.find(action, "theme=") then
action = with_theme(action, defaultTheme)
end
return ":Telescope " .. action .. "<cr>"
end
local function setupKeybinds()
for _, mapping in pairs(keybinds) do
vim.keymap.set("n", mapping[1], mkAction(mapping[2]))
vim.keymap.set("n", mapping[1], mkAction(mapping[2]), { desc = mapping[3] })
end
for _, mapping in pairs(chords) do

View file

@ -1,38 +0,0 @@
local M = {}
local hint = [[
Arrow^^^^^^ Select region with <C-v>
^ ^ _K_ ^ ^ _f_: surround it with box
_H_ ^ ^ _L_
^ ^ _J_ ^ ^ _<Esc>_
]]
function M.setup()
local Hydra = require('hydra')
Hydra({
name = 'Draw Diagram',
hint = hint,
config = {
color = 'pink',
invoke_on_body = true,
hint = {
border = 'rounded'
},
on_enter = function()
vim.o.virtualedit = 'all'
end,
},
mode = 'n',
body = '<leader>v',
heads = {
{ 'H', '<C-v>h:VBox<CR>' },
{ 'J', '<C-v>j:VBox<CR>' },
{ 'K', '<C-v>k:VBox<CR>' },
{ 'L', '<C-v>l:VBox<CR>' },
{ 'f', ':VBox<CR>', { mode = 'v' } },
{ '<Esc>', nil, { exit = true } },
}
})
end
return M

View file

@ -0,0 +1,9 @@
local M = {}
function M.setup()
require("which-key").setup({
triggers = { "<leader>", "d", "y", "q", "z", "g", "c" }
})
end
return M