From bbd2fb70f4d833ddfa4169a91dcd206f0fbed721 Mon Sep 17 00:00:00 2001 From: Amanda Graven Date: Mon, 15 Aug 2022 15:05:12 +0200 Subject: [PATCH] gui zoom, misc plugin updates --- init.lua | 100 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/init.lua b/init.lua index 6ed6827..4482cef 100644 --- a/init.lua +++ b/init.lua @@ -74,19 +74,47 @@ if fn.executable('rg') then o.grepformat = '%f:%l:%c:%m' end +local zoom_notification = nil + +--- "Zoom" by changing gui font size +--- @param delta integer +local function zoom(delta) + local size = fn.substitute(o.guifont, [[^.*:h\([^:]*\).*$]], [[\1]], '') + size = size + delta + local guifont = fn.substitute(o.guifont, [[:h\([^:]*\)]], ':h' .. size, '') + o.guifont = guifont + zoom_notification = vim.notify('Changing font size to ' .. size, vim.log.levels.INFO, { + title = 'Font size', + replace = zoom_notification, + hide_from_history = true, + }) +end + +local function zoom_in() + zoom(1) +end + +local function zoom_out() + zoom(-1) +end + + -- Convenience keybindings do -- which-key might not be available yet local ok, which_key = pcall(require, 'which-key') if ok then - which_key.register{['!'] = {'copen', 'Quickfix window'}} - which_key.register{[''] = {'set number! relativenumber!', 'Toggle relative numbers'}} - which_key.register{[''] = {'set number!', 'Toggle line numbers'}} + which_key.register { ['!'] = {'copen', 'Quickfix window'} } + which_key.register { [''] = {'set number! relativenumber!', 'Toggle relative numbers'} } + which_key.register { [''] = {'set number!', 'Toggle line numbers'} } - which_key.register{[''] = {'h', 'Go to the left window'}} - which_key.register{[''] = {'l', 'Go to the right window'}} - which_key.register{[''] = {'n', 'Go to the up window'}} - which_key.register{[''] = {'e', 'Go to the down window'}} + which_key.register { [''] = {'h', 'Go to the left window'} } + which_key.register { [''] = {'l', 'Go to the right window'} } + which_key.register { [''] = {'n', 'Go to the up window'} } + which_key.register { [''] = {'e', 'Go to the down window'} } + + which_key.register { ['+'] = {zoom_in, "Zoom in"} } + which_key.register { ['-'] = {zoom_out, "Zoom out"} } end end @@ -208,7 +236,7 @@ require'packer'.startup(function(use) require'which-key'.register{['s'] = {'ISwapWith','Swap'}} end} use 'bfredl/nvim-luadev' -- lua scratchpad - use 'vim-scripts/ReplaceWithRegister' -- gr replace with register + use 'tpope/vim-repeat' use 'tpope/vim-sleuth' -- spellsitter: syntax aware spellchecking use {'lewis6991/spellsitter.nvim', config = function() require'spellsitter'.setup() end} @@ -218,7 +246,7 @@ require'packer'.startup(function(use) vim.g['test#strategy'] = 'neovim' end} use {'julian/vim-textobj-variable-segment', requires = {'kana/vim-textobj-user'}} - use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'} -- TODO: upgrade parsers on update + use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'} use 'hrsh7th/vim-vsnip' -- LSP -- @@ -266,7 +294,7 @@ require'packer'.startup(function(use) use 'junegunn/goyo.vim' use 'kosayoda/nvim-lightbulb' use {'https://git.sr.ht/~whynothugo/lsp_lines.nvim', config = function() - require'lsp_lines'.register_lsp_virtual_lines() + require'lsp_lines'.setup() vim.diagnostic.config { virtual_text = false } end} use {'rcarriga/nvim-notify', after = 'telescope.nvim', config = function () @@ -317,6 +345,7 @@ require'packer'.startup(function(use) name = 'Telescope', [""] = {'Telescope', 'List pickers'}, f = {'Telescope find_files', 'Files'}, + F = {'Telescope file_browser', 'File browser'}, d = {'Telescope find_files find_command=fd,--type,d,-I', 'Directories'}, r = {'Telescope oldfiles', 'Recent files'}, g = {'Telescope live_grep', 'Grep'}, @@ -326,6 +355,7 @@ require'packer'.startup(function(use) p = {'Telescope project', 'Projects'}, s = {'Telescope lsp_dynamic_workspace_symbols', 'Symbols'}, n = {'Telescope notify', 'Notifications'}, + m = {'Telescope man_pages', 'Man pages'}, [':'] = {'Telescope commands', 'Commands'}, } } @@ -503,35 +533,36 @@ local capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol. --- Performs keymaps and other setup specific to buffers with LSP enabled --- @param bufnr number local function on_attach(_client, bufnr) - -- keybinding settings - local opts = { noremap = true, silent = true } - -- keybinding shorthand - local function bufmap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end require'which-key'.register({ g = { - d = {'lua vim.lsp.buf.definition()', 'Goto definition'}, - D = {'lua vim.lsp.buf.implementation()', 'Goto implementation'}, - a = {'lua vim.lsp.buf.code_action()', 'Code action'}, - R = {'lua vim.lsp.buf.rename()', 'Rename'}, - y = {'lua vim.lsp.buf.type_definition()', 'Type definition'}, + d = {vim.lsp.buf.definition, 'Goto definition'}, + D = {vim.lsp.buf.implementation, 'Goto implementation'}, + a = {vim.lsp.buf.code_action, 'Code action'}, + R = {vim.lsp.buf.rename, 'Rename'}, + y = {vim.lsp.buf.type_definition, 'Type definition'}, }, [']'] = { - g = {'lua vim.diagnostic.goto_next()', 'Next diagnostic'}, - e = {'lua vim.diagnostic.goto_next { severity = vim.diagnostic.severity.ERROR }', 'Next error'}, - w = {'lua vim.diagnostic.goto_next { severity = vim.diagnostic.severity.WARN }', 'Next warning'}, - q = {'lua vim.diagnostic.setqflist()', 'Quickfix diagnostics'}, + g = {vim.diagnostic.goto_next, 'Next diagnostic'}, + e = {function() vim.diagnostic.goto_next { severity = vim.diagnostic.severity.ERROR } end, 'Next error'}, + w = {function() vim.diagnostic.goto_next { severity = vim.diagnostic.severity.WARN } end, 'Next warning'}, + q = {vim.diagnostic.setqflist, 'Quickfix diagnostics'}, }, ['['] = { - g = {'lua vim.diagnostic.goto_prev()', 'Previous diagnostic'}, - e = {'lua vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.ERROR }', 'Previous error'}, - w = {'lua vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.WARN }', 'Previous warning'}, + g = {vim.diagnostic.goto_prev, 'Previous diagnostic'}, + e = {function() vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.ERROR } end, 'Previous error'}, + w = {function() vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.WARN } end, 'Previous warning'}, } + }, {buffer = bufnr}) -- Hover - bufmap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - bufmap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - bufmap('i', '', 'lua vim.lsp.buf.signature_help()', opts) + require'which-key'.register({ + ['K'] = {vim.lsp.buf.hover, 'Documentation'}, + [''] = {vim.lsp.buf.signature_help, 'Function signature'}, + }, {buffer = bufnr}) + require'which-key'.register({ + ['=1.0 +g.rustfmt_emit_files = 1 -- Use nigtly rustfmt for unstable settings g.rustfmt_command = 'rustup run nightly rustfmt' @@ -725,11 +758,6 @@ require('nvim-tree').setup { open_on_setup = true, -- Match tree cwd to vim's cwd update_cwd = true, - -- When a file is BufEnter'ed, focus it in the tree - update_focused_file = { - enable = true, - ignore_list = {'fugitive'} - } } vim.cmd'highlight NvimTreeOpenedFile guifg=NONE gui=italic' vim.api.nvim_create_autocmd('ColorScheme', { @@ -738,7 +766,7 @@ vim.api.nvim_create_autocmd('ColorScheme', { command = 'highlight NvimTreeOpenedFile guifg=NONE gui=italic' }) -require'which-key'.register{['t'] = {'NvimTreeToggle', 'Nvim Tree'}} +require'which-key'.register{['t'] = {'NvimTreeFindFileToggle', 'Nvim Tree'}} ---- treesitter ---- @@ -748,7 +776,7 @@ require'nvim-treesitter.configs'.setup { 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' }, incremental_selection = { enable = true }, }