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

232
init.lua
View file

@ -11,23 +11,15 @@ local g = vim.g
local fn = vim.fn
local opt = vim.opt
-- Define functions for keymaps
local function noremap(mode, key, mapping)
-- 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
-- Whether to enable workman remappings
local workman = false
-- Set font
if fn.hostname() == 'sharpy' then
o.guifont = 'Iosevka Term Slab,Iosevka:h10'
else
o.guifont = 'Iosevka Term Slab Extended,Iosevka:h9'
end
o.guifont = 'Iosevka Term Slab,Iosevka:h10'
if fn.hostname() == 'tappy' then
g.neovide_refresh_rate = 144
end
opt.guicursor:append('a:blinkon1000') -- Blink cursor once a second for all modes
o.mouse = 'a' -- Enable mouse input
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.linebreak = true -- Enable word-wrapping at the end of visual lines
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.showmatch = true -- Highlight matching brackets
o.splitright = true -- Open new windows below
@ -74,6 +66,15 @@ if fn.executable('rg') then
o.grepformat = '%f:%l:%c:%m'
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
--- "Zoom" by changing gui font size
@ -98,7 +99,6 @@ local function zoom_out()
zoom(-1)
end
-- Convenience keybindings
do
-- 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-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_out, "Zoom out"} }
if workman then
which_key.register { j = {'n', 'Next search match'} }
which_key.register { k = {'e', 'End of word'} }
which_key.register { n = {'gj', 'Down'} }
which_key.register { e = {'gk', 'Up'} }
else
which_key.register { j = {'gj', 'Down'} }
which_key.register { k = {'gk', 'Up'} }
end
end
end
-- Do workman remappings
noremap('', 'n', 'gj')
noremap('', 'j', 'n')
noremap('', 'e', 'gk')
noremap('', 'k', 'e')
-- Commands
vim.cmd [[
command! Light colorscheme base16-atelier-sulphurpool-light
command! Dark colorscheme nord
command! Light set background=light
command! Dark set background=dark
]]
-- Autocommands
vim.cmd [[
augroup vimrc
au!
" Restore file position from previous session
au BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
" Highlight yanked text
au TextYankPost * silent! lua vim.highlight.on_yank()
au User StartifyReady noremap <buffer> n gj| noremap <buffer> e gk
" Recompile plugin config cache when vimrc is updated
au BufWritePost */.config/nvim/init.lua source <afile> | PackerCompile
augroup END
]]
--local au = vim.api.nvim_create_augroup
--local augroup = vim.api.nvim_create_augroup('luarc', {clear = true})
--au('User', { pattern = 'StartifyReady', group = augroup, callback = function(cmd)
-- vim.keymap.set('', 'n', 'gj', {silent = true, buffer = true})
-- vim.keymap.set('', 'e', 'gk', {silent = true, buffer = true})
--end})
--au('BufWritePost', {
-- pattern = '*/.config/nvim/init.lua',
-- group = augroup,
-- command = 'source <afile> | PackerCompile'
--})
--au('TextYankPost', { pattern = '*', group = augroup, callback = vim.highlight.on_yank })
--au('BufWritePost', { pattern = '*/.config/nvim/init.lua', command = 'source <afile> | PackerCompile' })
--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 })
local augroup = vim.api.nvim_create_augroup('luarc', {clear = true})
local au = function(autocmd, opts)
opts.group = augroup
vim.api.nvim_create_autocmd(autocmd, opts)
end
au('User', {
pattern = 'StartifyReady',
callback = function()
if workman then
vim.keymap.set('', 'n', 'gj', {silent = true, buffer = true})
vim.keymap.set('', 'e', 'gk', {silent = true, buffer = true})
end
end
})
au('BufWritePost', {
pattern = '*/.config/nvim/init.lua',
command = 'source <afile> | PackerCompile',
desc = 'Reload config when it is saved, and compile packer cache',
})
au('TextYankPost', {
pattern = '*',
callback = vim.highlight.on_yank,
desc = 'Highlight when text is yanked',
})
au('BufReadPost', {
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
desc = 'Remember cursor position across restarts'
})
-- Diagnostics
vim.diagnostic.config {
@ -184,7 +191,6 @@ vim.diagnostic.config {
-- Set special URL handler
g.netrw_browsex_viewer = 'xdg-open'
---- Plugins ----
-- Automatically download packer if not installed
local packer_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
@ -203,7 +209,11 @@ require'packer'.startup(function(use)
-- Themes --
use {'arcticicestudio/nord-vim', branch = 'main'}
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 ()
vim.g.catppuccin_flavour = 'latte'
require'catppuccin'.setup {
@ -220,6 +230,7 @@ require'packer'.startup(function(use)
-- Filetype plugins --
use 'rhysd/vim-crystal'
use 'editorconfig/editorconfig-vim'
use 'bakpakin/fennel.vim'
use 'mboughaba/i3config.vim'
use 'plasticboy/vim-markdown'
use 'mracos/mermaid.vim'
@ -230,7 +241,10 @@ require'packer'.startup(function(use)
-- Editing --
use 'jiangmiao/auto-pairs'
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()
require'iswap'.setup{}
require'which-key'.register{['<Leader>s'] = {'<Cmd>ISwapWith<CR>','Swap'}}
@ -247,6 +261,7 @@ require'packer'.startup(function(use)
end}
use {'julian/vim-textobj-variable-segment', requires = {'kana/vim-textobj-user'}, branch = 'main'}
use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'}
use 'windwp/nvim-ts-autotag'
use 'hrsh7th/vim-vsnip'
-- LSP --
@ -276,6 +291,7 @@ require'packer'.startup(function(use)
end}
use {'mfussenegger/nvim-dap', config = function()
local dap = require'dap'
vim.fn.sign_define('DapBreakpoint', {text='', texthl='DiagnosticError'})
dap.adapters.codelldb = {
type = 'server',
port = '${port}',
@ -298,12 +314,19 @@ require'packer'.startup(function(use)
}
dap.configurations.rust = dap.configurations.cpp
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 {
['<Leader>d'] = {
name = 'Debug',
c = {dap.continue, 'Continue/start'},
s = {dap.terminate, 'Stop'},
b = {dap.toggle_breakpoint, 'Breakpoint'},
B = {conditional_breakpoint, 'Conditional breakpoint'},
o = {dap.step_over, 'Step over'},
i = {dap.step_into, 'Step into'},
O = {dap.step_out, 'Step out'},
@ -315,9 +338,19 @@ require'packer'.startup(function(use)
}
end}
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 {
['<Leader>dd'] = {require'dapui'.toggle, 'Debug'}
['<Leader>dd'] = {require'dapui'.toggle, 'Toggle'}
}
end}
use {'theHamsta/nvim-dap-virtual-text', config = function()
@ -332,10 +365,19 @@ require'packer'.startup(function(use)
{
type = 'pwa-node',
request = 'launch',
name = 'Launch file',
name = 'Launch current file',
program = '${file}',
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',
request = 'attach',
@ -365,11 +407,18 @@ require'packer'.startup(function(use)
opt = true,
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()
vim.cmd'highlight link FloatTitle TelescopeBorder'
require'dressing'.setup {
input = {
winhighlight = 'NormalFloat:TelescopeNormal,FloatBorder:TelescopeBorder'
win_options = {
winhighlight = 'NormalFloat:TelescopeNormal,FloatBorder:TelescopeBorder'
}
},
select = {
enabled = false,
@ -629,7 +678,7 @@ cmp.setup {
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 ----
--- 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'.clangd.setup(default)
require'lspconfig'.jdtls.setup(default)
require'lspconfig'.pyright.setup(default)
require'lspconfig'.tsserver.setup(default)
require'lspconfig'.vimls.setup(default)
@ -727,19 +778,6 @@ g.rustfmt_emit_files = 1
g.rustfmt_command = 'rustup run nightly rustfmt'
-- 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 ----
require'rust-tools'.setup {
tools = {
@ -766,7 +804,22 @@ require'rust-tools'.setup {
-- Load OUT_DIR when running check on save, needed for proc macros
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 = {
-- Disable diagnostics with false positives
disabled = {'unresolved-import'};
@ -831,6 +884,9 @@ require('nvim-tree').setup {
-- Show LSP diagnostics in the sign column
diagnostics = {
enable = true,
icons = {
hint = "",
},
},
git = {
-- Don't hide .gitignore'd files by default
@ -868,8 +924,7 @@ require('nvim-tree').setup {
update_cwd = true,
}
vim.cmd'highlight NvimTreeOpenedFile guifg=NONE gui=italic'
vim.api.nvim_create_autocmd('ColorScheme', {
group = 'vimrc',
au('ColorScheme', {
desc = 'Change NvimTreeOpenedFile highlight',
command = 'highlight NvimTreeOpenedFile guifg=NONE gui=italic'
})
@ -883,8 +938,7 @@ require'nvim-treesitter.configs'.setup {
autotag = {
enable = true,
},
-- TODO; Pick list manually
ensure_installed = {'lua', 'html', 'c', 'cpp', 'nix', 'vim', 'rust', 'markdown'},
ensure_installed = {'lua', 'html', 'c', 'cpp', 'nix', 'vim', 'rust'},
highlight = { enable = true, disable = 'rust' },
incremental_selection = { enable = true },
}
@ -892,6 +946,4 @@ require'nvim-treesitter.configs'.setup {
g.nord_italic = 1
g.nord_italicize_comments = 1
g.nord_underline = 1
vim.cmd [[
colorscheme nord
]]
vim.cmd 'colorscheme tokyonight'