lua augroups, set hlsearch, more dap stuff, etc

This commit is contained in:
Amanda Graven 2023-01-20 19:36:31 +01:00
parent 3d9cd7098a
commit 1452d6596a
Signed by: amanda
GPG key ID: F747582C5608F4CB

230
init.lua
View file

@ -11,23 +11,15 @@ local g = vim.g
local fn = vim.fn local fn = vim.fn
local opt = vim.opt local opt = vim.opt
-- Define functions for keymaps -- Whether to enable workman remappings
local function noremap(mode, key, mapping) local workman = false
-- no recursion, silent
local opts = { noremap = true, silent = true }
vim.api.nvim_set_keymap(mode, key, mapping, opts)
end
local function inoremap(key, mapping) noremap('i', key, mapping) end
-- Set font -- Set font
if fn.hostname() == 'sharpy' then
o.guifont = 'Iosevka Term Slab,Iosevka:h10' o.guifont = 'Iosevka Term Slab,Iosevka:h10'
else
o.guifont = 'Iosevka Term Slab Extended,Iosevka:h9'
end
if fn.hostname() == 'tappy' then if fn.hostname() == 'tappy' then
g.neovide_refresh_rate = 144 g.neovide_refresh_rate = 144
end end
opt.guicursor:append('a:blinkon1000') -- Blink cursor once a second for all modes opt.guicursor:append('a:blinkon1000') -- Blink cursor once a second for all modes
o.mouse = 'a' -- Enable mouse input o.mouse = 'a' -- Enable mouse input
o.termguicolors = true -- Enable 24bit terminal colors o.termguicolors = true -- Enable 24bit terminal colors
@ -38,7 +30,7 @@ o.clipboard = 'unnamedplus' -- Use system clipboard by default
o.hidden = true -- Allow buffers to not be attached to a window o.hidden = true -- Allow buffers to not be attached to a window
o.linebreak = true -- Enable word-wrapping at the end of visual lines o.linebreak = true -- Enable word-wrapping at the end of visual lines
o.breakindent = true -- preserve indentention on lines continuing from a wrap o.breakindent = true -- preserve indentention on lines continuing from a wrap
o.hlsearch = false -- Don't highlight search results o.hlsearch = true -- Highlight search results
o.scrolloff = 5 -- Margin between cursor and screen top/bottom o.scrolloff = 5 -- Margin between cursor and screen top/bottom
o.showmatch = true -- Highlight matching brackets o.showmatch = true -- Highlight matching brackets
o.splitright = true -- Open new windows below o.splitright = true -- Open new windows below
@ -74,6 +66,15 @@ if fn.executable('rg') then
o.grepformat = '%f:%l:%c:%m' o.grepformat = '%f:%l:%c:%m'
end end
if vim.fn.executable('darkman') then
local mode = vim.trim(vim.fn.system('darkman get'))
if mode == 'dark' then
vim.o.background = 'dark'
elseif mode == 'light' then
vim.o.background = 'light'
end
end
local zoom_notification = nil local zoom_notification = nil
--- "Zoom" by changing gui font size --- "Zoom" by changing gui font size
@ -98,7 +99,6 @@ local function zoom_out()
zoom(-1) zoom(-1)
end end
-- Convenience keybindings -- Convenience keybindings
do do
-- which-key might not be available yet -- which-key might not be available yet
@ -113,63 +113,70 @@ do
which_key.register { ['<A-n>'] = {'<C-w>n', 'Go to the up window'} } which_key.register { ['<A-n>'] = {'<C-w>n', 'Go to the up window'} }
which_key.register { ['<A-e>'] = {'<C-w>e', 'Go to the down window'} } which_key.register { ['<A-e>'] = {'<C-w>e', 'Go to the down window'} }
which_key.register { ['<C-l>'] = {function ()
local ok, notify = pcall(require, 'notify')
if ok then
notify.dismiss()
end
vim.cmd('nohlsearch|diffupdate|normal! <C-l>')
end, 'Clear'} }
which_key.register { ['+'] = {zoom_in, "Zoom in"} } which_key.register { ['+'] = {zoom_in, "Zoom in"} }
which_key.register { ['-'] = {zoom_out, "Zoom out"} } which_key.register { ['-'] = {zoom_out, "Zoom out"} }
end
end
-- Do workman remappings if workman then
noremap('', 'n', 'gj') which_key.register { j = {'n', 'Next search match'} }
noremap('', 'j', 'n') which_key.register { k = {'e', 'End of word'} }
noremap('', 'e', 'gk') which_key.register { n = {'gj', 'Down'} }
noremap('', 'k', 'e') which_key.register { e = {'gk', 'Up'} }
else
which_key.register { j = {'gj', 'Down'} }
which_key.register { k = {'gk', 'Up'} }
end
end
end
-- Commands -- Commands
vim.cmd [[ vim.cmd [[
command! Light colorscheme base16-atelier-sulphurpool-light command! Light set background=light
command! Dark colorscheme nord command! Dark set background=dark
]] ]]
-- Autocommands -- Autocommands
vim.cmd [[ local augroup = vim.api.nvim_create_augroup('luarc', {clear = true})
augroup vimrc local au = function(autocmd, opts)
au! opts.group = augroup
vim.api.nvim_create_autocmd(autocmd, opts)
" Restore file position from previous session end
au BufReadPost * au('User', {
\ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit' pattern = 'StartifyReady',
\ | exe "normal! g`\"" callback = function()
\ | endif if workman then
vim.keymap.set('', 'n', 'gj', {silent = true, buffer = true})
" Highlight yanked text vim.keymap.set('', 'e', 'gk', {silent = true, buffer = true})
au TextYankPost * silent! lua vim.highlight.on_yank() end
end
au User StartifyReady noremap <buffer> n gj| noremap <buffer> e gk })
au('BufWritePost', {
" Recompile plugin config cache when vimrc is updated pattern = '*/.config/nvim/init.lua',
au BufWritePost */.config/nvim/init.lua source <afile> | PackerCompile command = 'source <afile> | PackerCompile',
desc = 'Reload config when it is saved, and compile packer cache',
augroup END })
]] au('TextYankPost', {
--local au = vim.api.nvim_create_augroup pattern = '*',
--local augroup = vim.api.nvim_create_augroup('luarc', {clear = true}) callback = vim.highlight.on_yank,
--au('User', { pattern = 'StartifyReady', group = augroup, callback = function(cmd) desc = 'Highlight when text is yanked',
-- vim.keymap.set('', 'n', 'gj', {silent = true, buffer = true}) })
-- vim.keymap.set('', 'e', 'gk', {silent = true, buffer = true}) au('BufReadPost', {
--end}) callback = function()
--au('BufWritePost', { local mark = vim.api.nvim_buf_get_mark(0, '"')
-- pattern = '*/.config/nvim/init.lua', local lcount = vim.api.nvim_buf_line_count(0)
-- group = augroup, if mark[1] > 0 and mark[1] <= lcount then
-- command = 'source <afile> | PackerCompile' pcall(vim.api.nvim_win_set_cursor, 0, mark)
--}) end
--au('TextYankPost', { pattern = '*', group = augroup, callback = vim.highlight.on_yank }) end,
--au('BufWritePost', { pattern = '*/.config/nvim/init.lua', command = 'source <afile> | PackerCompile' }) desc = 'Remember cursor position across restarts'
--au('BufReadPost', { pattern = '*', group = augroup, command = function() })
-- local line = vim.fn.line
-- if line[['\"]] > 1 && line[['\"]] <= line'$' && o.ft ~= 'commit' then
-- vim.cmd'normal g`"'
-- end
--end })
-- Diagnostics -- Diagnostics
vim.diagnostic.config { vim.diagnostic.config {
@ -184,7 +191,6 @@ vim.diagnostic.config {
-- Set special URL handler -- Set special URL handler
g.netrw_browsex_viewer = 'xdg-open' g.netrw_browsex_viewer = 'xdg-open'
---- Plugins ---- ---- Plugins ----
-- Automatically download packer if not installed -- Automatically download packer if not installed
local packer_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' local packer_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
@ -203,7 +209,11 @@ require'packer'.startup(function(use)
-- Themes -- -- Themes --
use {'arcticicestudio/nord-vim', branch = 'main'} use {'arcticicestudio/nord-vim', branch = 'main'}
use 'chriskempson/base16-vim' use 'chriskempson/base16-vim'
use 'folke/tokyonight.nvim' use {'folke/tokyonight.nvim', config = function()
require'tokyonight'.setup {
style = 'night'
}
end}
use {'catppuccin/nvim', as = 'catppuccin', config = function () use {'catppuccin/nvim', as = 'catppuccin', config = function ()
vim.g.catppuccin_flavour = 'latte' vim.g.catppuccin_flavour = 'latte'
require'catppuccin'.setup { require'catppuccin'.setup {
@ -220,6 +230,7 @@ require'packer'.startup(function(use)
-- Filetype plugins -- -- Filetype plugins --
use 'rhysd/vim-crystal' use 'rhysd/vim-crystal'
use 'editorconfig/editorconfig-vim' use 'editorconfig/editorconfig-vim'
use 'bakpakin/fennel.vim'
use 'mboughaba/i3config.vim' use 'mboughaba/i3config.vim'
use 'plasticboy/vim-markdown' use 'plasticboy/vim-markdown'
use 'mracos/mermaid.vim' use 'mracos/mermaid.vim'
@ -230,7 +241,10 @@ require'packer'.startup(function(use)
-- Editing -- -- Editing --
use 'jiangmiao/auto-pairs' use 'jiangmiao/auto-pairs'
use 'ojroques/nvim-bufdel' use 'ojroques/nvim-bufdel'
use 'yuttie/comfortable-motion.vim' --use 'yuttie/comfortable-motion.vim'
use {'jbyuki/instant.nvim', config = function ()
vim.g.instant_username = 'agraven'
end}
use {'mizlan/iswap.nvim', config = function() use {'mizlan/iswap.nvim', config = function()
require'iswap'.setup{} require'iswap'.setup{}
require'which-key'.register{['<Leader>s'] = {'<Cmd>ISwapWith<CR>','Swap'}} require'which-key'.register{['<Leader>s'] = {'<Cmd>ISwapWith<CR>','Swap'}}
@ -247,6 +261,7 @@ require'packer'.startup(function(use)
end} end}
use {'julian/vim-textobj-variable-segment', requires = {'kana/vim-textobj-user'}, branch = 'main'} use {'julian/vim-textobj-variable-segment', requires = {'kana/vim-textobj-user'}, branch = 'main'}
use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'} use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'}
use 'windwp/nvim-ts-autotag'
use 'hrsh7th/vim-vsnip' use 'hrsh7th/vim-vsnip'
-- LSP -- -- LSP --
@ -276,6 +291,7 @@ require'packer'.startup(function(use)
end} end}
use {'mfussenegger/nvim-dap', config = function() use {'mfussenegger/nvim-dap', config = function()
local dap = require'dap' local dap = require'dap'
vim.fn.sign_define('DapBreakpoint', {text='', texthl='DiagnosticError'})
dap.adapters.codelldb = { dap.adapters.codelldb = {
type = 'server', type = 'server',
port = '${port}', port = '${port}',
@ -298,12 +314,19 @@ require'packer'.startup(function(use)
} }
dap.configurations.rust = dap.configurations.cpp dap.configurations.rust = dap.configurations.cpp
dap.configurations.c = dap.configurations.c dap.configurations.c = dap.configurations.c
local function conditional_breakpoint()
vim.ui.input({prompt = 'Breakpoint condition'}, function(condition)
if not condition then return end
dap.toggle_breakpoint(condition)
end)
end
require'which-key'.register { require'which-key'.register {
['<Leader>d'] = { ['<Leader>d'] = {
name = 'Debug', name = 'Debug',
c = {dap.continue, 'Continue/start'}, c = {dap.continue, 'Continue/start'},
s = {dap.terminate, 'Stop'}, s = {dap.terminate, 'Stop'},
b = {dap.toggle_breakpoint, 'Breakpoint'}, b = {dap.toggle_breakpoint, 'Breakpoint'},
B = {conditional_breakpoint, 'Conditional breakpoint'},
o = {dap.step_over, 'Step over'}, o = {dap.step_over, 'Step over'},
i = {dap.step_into, 'Step into'}, i = {dap.step_into, 'Step into'},
O = {dap.step_out, 'Step out'}, O = {dap.step_out, 'Step out'},
@ -315,9 +338,19 @@ require'packer'.startup(function(use)
} }
end} end}
use {'rcarriga/nvim-dap-ui', config = function() use {'rcarriga/nvim-dap-ui', config = function()
require'dapui'.setup() local dapui, dap = require'dapui', require'dap'
dapui.setup()
dap.listeners.after.event_initialized.dapui_config = function ()
dapui.open {}
end
dap.listeners.before.event_terminated.dapui_config = function ()
dapui.close {}
end
dap.listeners.before.event_exited.dapui_config = function ()
dapui.close {}
end
require'which-key'.register { require'which-key'.register {
['<Leader>dd'] = {require'dapui'.toggle, 'Debug'} ['<Leader>dd'] = {require'dapui'.toggle, 'Toggle'}
} }
end} end}
use {'theHamsta/nvim-dap-virtual-text', config = function() use {'theHamsta/nvim-dap-virtual-text', config = function()
@ -332,10 +365,19 @@ require'packer'.startup(function(use)
{ {
type = 'pwa-node', type = 'pwa-node',
request = 'launch', request = 'launch',
name = 'Launch file', name = 'Launch current file',
program = '${file}', program = '${file}',
cwd = '${workspaceFolder}', cwd = '${workspaceFolder}',
}, },
{
type = 'pwa-node',
request = 'launch',
name = 'Launch file',
program = function()
return vim.fn.input('Path to file: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
},
{ {
type = 'pwa-node', type = 'pwa-node',
request = 'attach', request = 'attach',
@ -365,11 +407,18 @@ require'packer'.startup(function(use)
opt = true, opt = true,
run = 'npm install --legacy-peer-deps && npm run compile' run = 'npm install --legacy-peer-deps && npm run compile'
} }
use {'sindrets/diffview.nvim', config = function()
require'diffview'.setup {
enhanced_diff_hl = true,
}
end}
use {'stevearc/dressing.nvim', config = function() use {'stevearc/dressing.nvim', config = function()
vim.cmd'highlight link FloatTitle TelescopeBorder' vim.cmd'highlight link FloatTitle TelescopeBorder'
require'dressing'.setup { require'dressing'.setup {
input = { input = {
win_options = {
winhighlight = 'NormalFloat:TelescopeNormal,FloatBorder:TelescopeBorder' winhighlight = 'NormalFloat:TelescopeNormal,FloatBorder:TelescopeBorder'
}
}, },
select = { select = {
enabled = false, enabled = false,
@ -629,7 +678,7 @@ cmp.setup {
ghost_text = true, ghost_text = true,
}, },
} }
local capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require'cmp_nvim_lsp'.default_capabilities()
---- lsp: language servers ---- ---- lsp: language servers ----
--- Performs keymaps and other setup specific to buffers with LSP enabled --- Performs keymaps and other setup specific to buffers with LSP enabled
@ -702,6 +751,8 @@ require'lspconfig'.sumneko_lua.setup {
require'lspconfig'.bashls.setup(default) require'lspconfig'.bashls.setup(default)
require'lspconfig'.clangd.setup(default) require'lspconfig'.clangd.setup(default)
require'lspconfig'.jdtls.setup(default)
require'lspconfig'.pyright.setup(default)
require'lspconfig'.tsserver.setup(default) require'lspconfig'.tsserver.setup(default)
require'lspconfig'.vimls.setup(default) require'lspconfig'.vimls.setup(default)
@ -727,19 +778,6 @@ g.rustfmt_emit_files = 1
g.rustfmt_command = 'rustup run nightly rustfmt' g.rustfmt_command = 'rustup run nightly rustfmt'
-- use cargo-lints if available -- use cargo-lints if available
local checkOnSave = {};
if fn.executable('cargo-lints') == 1 then
checkOnSave = {
overrideCommand = {"cargo", "lints", "clippy", "--workspace", "--message-format=json", "--all-targets"}
}
else
checkOnSave = {
-- Use clippy for error checking
command = "clippy",
-- Also run checks for tests
allTargets = true,
}
end
---- rust-tools ---- ---- rust-tools ----
require'rust-tools'.setup { require'rust-tools'.setup {
tools = { tools = {
@ -766,7 +804,22 @@ require'rust-tools'.setup {
-- Load OUT_DIR when running check on save, needed for proc macros -- Load OUT_DIR when running check on save, needed for proc macros
loadOutDirsFromCheck = true, loadOutDirsFromCheck = true,
}, },
checkOnSave = checkOnSave, checkOnSave = true,
-- Use cargo lints for error checking if available, otherwise fall back to regular clippy
check = (function()
if vim.fn.executable('cargo-lints') then
return {
overrideCommand = {"cargo", "lints", "clippy", "--workspace", "--message-format=json", "--all-targets"}
}
else
return {
-- Use clippy for error checking
command = "clippy",
-- Also run checks for tests
allTargets = true,
}
end
end)(),
diagnostics = { diagnostics = {
-- Disable diagnostics with false positives -- Disable diagnostics with false positives
disabled = {'unresolved-import'}; disabled = {'unresolved-import'};
@ -831,6 +884,9 @@ require('nvim-tree').setup {
-- Show LSP diagnostics in the sign column -- Show LSP diagnostics in the sign column
diagnostics = { diagnostics = {
enable = true, enable = true,
icons = {
hint = "",
},
}, },
git = { git = {
-- Don't hide .gitignore'd files by default -- Don't hide .gitignore'd files by default
@ -868,8 +924,7 @@ require('nvim-tree').setup {
update_cwd = true, update_cwd = true,
} }
vim.cmd'highlight NvimTreeOpenedFile guifg=NONE gui=italic' vim.cmd'highlight NvimTreeOpenedFile guifg=NONE gui=italic'
vim.api.nvim_create_autocmd('ColorScheme', { au('ColorScheme', {
group = 'vimrc',
desc = 'Change NvimTreeOpenedFile highlight', desc = 'Change NvimTreeOpenedFile highlight',
command = 'highlight NvimTreeOpenedFile guifg=NONE gui=italic' command = 'highlight NvimTreeOpenedFile guifg=NONE gui=italic'
}) })
@ -883,8 +938,7 @@ require'nvim-treesitter.configs'.setup {
autotag = { autotag = {
enable = true, enable = true,
}, },
-- TODO; Pick list manually ensure_installed = {'lua', 'html', 'c', 'cpp', 'nix', 'vim', 'rust'},
ensure_installed = {'lua', 'html', 'c', 'cpp', 'nix', 'vim', 'rust', 'markdown'},
highlight = { enable = true, disable = 'rust' }, highlight = { enable = true, disable = 'rust' },
incremental_selection = { enable = true }, incremental_selection = { enable = true },
} }
@ -892,6 +946,4 @@ require'nvim-treesitter.configs'.setup {
g.nord_italic = 1 g.nord_italic = 1
g.nord_italicize_comments = 1 g.nord_italicize_comments = 1
g.nord_underline = 1 g.nord_underline = 1
vim.cmd [[ vim.cmd 'colorscheme tokyonight'
colorscheme nord
]]