From 534d9a102b8f6d91028d702c114f4ce440552f4b Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 3 Jun 2025 13:16:35 -0700 Subject: [PATCH] [neovim] Give key bindings a little love; add GUI bindings for neovide - Clean up the init interface. Move all the init methods into a single init_all() call. - Add two keybindings for and to move by soft-wrapped lines in Normal mode - Add a few key bindings for the usual shortcuts for cut/copy/paste when in GUI mode. In vim, D is the character that represents the Super/Apple key. So, , , and now do what you'd expect. --- config/nvim/init.lua | 5 +---- config/nvim/lua/gui.lua | 3 +++ config/nvim/lua/keys.lua | 39 ++++++++++++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 955a32c..8143253 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -56,10 +56,7 @@ require 'treesitter' require 'lsp' local keys = require 'keys' -keys.init_key_opts() -keys.init_window_key_mappings() -keys.init_diagnostic_key_mappings() -keys.init_telescope_mappings() +keys.init() local gui = require 'gui' gui.init() diff --git a/config/nvim/lua/gui.lua b/config/nvim/lua/gui.lua index 2840a21..873fc99 100644 --- a/config/nvim/lua/gui.lua +++ b/config/nvim/lua/gui.lua @@ -5,10 +5,13 @@ local function _init_neovide() return end + -- No use for these animations. vim.g.neovide_cursor_animation_length = 0 vim.g.neovide_position_animation_length = 0 vim.g.neovide_scroll_animation_length = 0 + vim.g.neovide_input_macos_option_key_is_meta = "both" + vim.cmd [[ colorscheme lunaperche ]] end diff --git a/config/nvim/lua/keys.lua b/config/nvim/lua/keys.lua index 962f33e..4eaebbb 100644 --- a/config/nvim/lua/keys.lua +++ b/config/nvim/lua/keys.lua @@ -2,10 +2,33 @@ local map = vim.keymap.set -local function init_key_opts() +local function init_key_options() vim.g.mapleader = "," end +local function navigation_mappings() + local options = { noremap = true } + + -- Navigate by soft-wrapped lines using Alt/Option/Meta + jk + map({'n', 'v'}, '', 'gk', options) + map({'n', 'v'}, '', 'gj', options) +end + +local function clipboard_mappings() + if not vim.fn.has('gui_running') then + return + end + + local options = { noremap = true } + + -- Copy to the system clipboard + map('v', '', '"+y', options) + -- Cut to the system clipboard + map('v', '', '"+x', options) + -- Paste from the system clipboard + map({'i', 'v'}, '', '"+p', options) +end + local function window_key_mappings() local options = { silent = true } @@ -70,10 +93,16 @@ local function telescope_mappings() map('n', 'fh', builtin.help_tags, { desc = 'Telescope help tags' }) end +local function init_all_global_keybindings() + init_key_options() + clipboard_mappings() + window_key_mappings() + navigation_mappings() + diagnostic_mappings() + telescope_mappings() +end + return { - init_key_opts = init_key_opts, - init_window_key_mappings = window_key_mappings, - init_diagnostic_key_mappings = diagnostic_mappings, + init = init_all_global_keybindings, init_lsp_key_mappings = local_lsp_mappings, - init_telescope_mappings = telescope_mappings, }