From b771adeb0ba201b6079dc043d799f61f26a86367 Mon Sep 17 00:00:00 2001 From: km Date: Sun, 24 Nov 2024 19:17:07 +0000 Subject: [PATCH] add showbreak symbol to show line breaks add map function for setting keymaps --- init.lua | 4 +-- lua/core/keymaps.lua | 59 +++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/init.lua b/init.lua index 65493d8d..bcbd1ecf 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,4 @@ --[[ - - - Lua - quick guide: https://learnxinyminutes.com/docs/lua/ - :help lua-guide - (or HTML version): https://neovim.io/doc/user/lua-guide.html @@ -42,6 +40,7 @@ vim.schedule(function() end) vim.opt.breakindent = true -- Enable break indent +vim.opt.showbreak = '↳ ' vim.opt.undofile = false -- Do not save undo history (no undo beyond last save) vim.opt.ignorecase = true -- Case-insensitive searching UNLESS \C or one or more capital letters in the search term vim.opt.smartcase = true @@ -57,7 +56,6 @@ vim.opt.splitbelow = true -- Configure how new splits should be opened vim.opt.list = false --vim.opt.listchars = { tab = '» ', trail = '·', eol = '$', nbsp = '␣' } vim.opt.listchars = { tab = '▸·', trail = '▸', eol = '$', nbsp = '␣' } - vim.opt.inccommand = 'split' -- Preview substitutions live, as you type! vim.opt.cursorline = true -- Show which line your cursor is on vim.opt.scrolloff = 3 -- Minimal number of screen lines to keep above and below the cursor. diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index a781b1d5..5480f43f 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -1,24 +1,22 @@ +-- function to assist with keymapping +function map(mode, lhs, rhs, opts) + local options = { noremap = true, silent = true } + if opts then + options = vim.tbl_extend('force', options, opts) + end + vim.keymap.set(mode, lhs, rhs, options) +end + return { -- [[ Basic Keymaps ]] - -- See `:help vim.keymap.set()` - - -- function to assist with keymapping - --[[ - function map(mode, lhs, rhs, opts) - local options = { noremap = true, silent = true } - if opts then - options = vim.tbl_extend("force", options, opts) - end - vim.keymap.set(mode, lhs, rhs, options) - end - --]] + -- See `:help map()` -- Clear highlights on search when pressing in normal mode -- See `:help hlsearch` - vim.keymap.set('n', '', 'nohlsearch'), + map('n', '', 'nohlsearch'), -- Diagnostic keymaps - vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }), + map('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }), -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which @@ -26,29 +24,28 @@ return { -- -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping -- or just use to exit terminal mode - vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }), + map('t', '', '', { desc = 'Exit terminal mode' }), -- Window and buffer handling -- Use CTRL+ to switch between windows -- See `:help wincmd` for a list of all window commands - vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }), - vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }), - vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }), - vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }), - vim.keymap.set('n', '', ':bn!', { desc = 'Go to next buffer' }), - vim.keymap.set('n', '', ':bp!', { desc = 'Go to previous buffer' }), - vim.keymap.set('n', 'ws', ':split', { desc = 'split window horizontally' }), - vim.keymap.set('n', 'wv', ':vsplit', { desc = 'split window vertically' }), + map('n', '', '', { desc = 'Move focus to the left window' }), + map('n', '', '', { desc = 'Move focus to the right window' }), + map('n', '', '', { desc = 'Move focus to the lower window' }), + map('n', '', '', { desc = 'Move focus to the upper window' }), + map('n', '', ':bn!', { desc = 'Go to next buffer' }), + map('n', '', ':bp!', { desc = 'Go to previous buffer' }), + map('n', 'bd', ':bd', { desc = 'close the current buffer' }), -- terraform - vim.keymap.set('n', 'ti', ':!terraform init -no-color', { desc = 'terraform init' }), - vim.keymap.set('n', 'tv', ':!terraform validate -no-color', { desc = 'terraform validate' }), - vim.keymap.set('n', 'tp', ':!terraform plan -no-color', { desc = 'terraform plan' }), - vim.keymap.set('n', 'taa', ':!terraform apply -no-color -auto-approve', { desc = 'terraform apply' }), + map('n', 'ti', ':!terraform init -no-color', { desc = 'terraform init' }), + map('n', 'tv', ':!terraform validate -no-color', { desc = 'terraform validate' }), + map('n', 'tp', ':!terraform plan -no-color', { desc = 'terraform plan' }), + map('n', 'ta', ':!terraform apply -no-color -auto-approve', { desc = 'terraform apply' }), -- Toggles - vim.keymap.set('n', 'n', ':set number!:set relativenumber!'), - vim.keymap.set('n', 'g', ':Gitsigns toggle_signs', { desc = 'Toggle Gitsigns' }), - vim.keymap.set('n', 'l', ':set list!', { desc = 'Toggle list mode' }), - vim.keymap.set('n', 'p', ':set paste!', { desc = 'Toggle paste mode' }), + map('n', 'n', ':set number!:set relativenumber!'), + map('n', 'g', ':Gitsigns toggle_signs', { desc = 'Toggle Gitsigns' }), + map('n', 'l', ':set list!', { desc = 'Toggle list mode' }), + map('n', 'p', ':set paste!', { desc = 'Toggle paste mode' }), }