From e0a1ba6ad9a7b987206ece3ff345b85e45df690f Mon Sep 17 00:00:00 2001 From: Tim Redband Date: Fri, 5 Apr 2024 11:33:43 -0400 Subject: [PATCH] split out vim config --- init.lua | 171 +++++++------------------------- lua/custom/config/api.lua | 20 ++++ lua/custom/config/filetypes.lua | 5 + lua/custom/config/global.lua | 10 ++ lua/custom/config/keymaps.lua | 29 ++++++ lua/custom/config/options.lua | 69 +++++++++++++ 6 files changed, 168 insertions(+), 136 deletions(-) create mode 100644 lua/custom/config/api.lua create mode 100644 lua/custom/config/filetypes.lua create mode 100644 lua/custom/config/global.lua create mode 100644 lua/custom/config/keymaps.lua create mode 100644 lua/custom/config/options.lua diff --git a/init.lua b/init.lua index 88c31c8b..781e724c 100644 --- a/init.lua +++ b/init.lua @@ -84,137 +84,11 @@ I hope you enjoy your Neovim journey, P.S. You can delete this when you're done too. It's your config now! :) --]] --- Set as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - --- Set to true if you have a Nerd Font installed -vim.g.have_nerd_font = false - --- [[ Setting options ]] --- See `:help vim.opt` --- NOTE: You can change these options as you wish! --- For more options, you can see `:help option-list` - --- Make line numbers default -vim.opt.number = true --- You can also add relative line numbers, for help with jumping. --- Experiment for yourself to see if you like it! -vim.opt.relativenumber = true - --- Enable mouse mode, can be useful for resizing splits for example! -vim.opt.mouse = 'a' - --- Don't show the mode, since it's already in status line -vim.opt.showmode = false - --- Sync clipboard between OS and Neovim. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` -vim.opt.clipboard = 'unnamedplus' - --- Enable break indent -vim.opt.breakindent = true - --- Save undo history -vim.opt.undofile = true - --- Case-insensitive searching UNLESS \C or capital in search -vim.opt.ignorecase = true -vim.opt.smartcase = true - --- Keep signcolumn on by default -vim.opt.signcolumn = 'yes' - --- Decrease update time -vim.opt.updatetime = 250 -vim.opt.timeoutlen = 300 - --- Configure how new splits should be opened -vim.opt.splitright = true -vim.opt.splitbelow = true - --- Sets how neovim will display certain whitespace in the editor. --- See `:help 'list'` --- and `:help 'listchars'` -vim.opt.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } - --- Preview substitutions live, as you type! -vim.opt.inccommand = 'split' - --- Show which line your cursor is on -vim.opt.cursorline = true - --- Minimal number of screen lines to keep above and below the cursor. -vim.opt.scrolloff = 10 - --- [[ Basic Keymaps ]] --- See `:help vim.keymap.set()` - --- Set highlight on search, but clear on pressing in normal mode -vim.opt.hlsearch = true -vim.keymap.set('n', '', 'nohlsearch') - --- custom -vim.opt.shell = 'cmd.exe' -vim.opt.autoread = true -vim.opt.expandtab = true -vim.opt.tabstop = 4 - --- Diagnostic keymaps -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) -vim.keymap.set('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 --- is not what someone will guess without a bit more experience. --- --- 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' }) - --- TIP: Disable arrow keys in normal mode -vim.keymap.set('n', '', 'echo "Use h to move!!"') -vim.keymap.set('n', '', 'echo "Use l to move!!"') -vim.keymap.set('n', '', 'echo "Use k to move!!"') -vim.keymap.set('n', '', 'echo "Use j to move!!"') - --- Keybinds to make split navigation easier. --- 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', '0', '^') - -vim.api.nvim_create_autocmd({ 'BufWinEnter' }, { - group = vim.api.nvim_create_augroup('custom-cursor-remember', { clear = true }), - desc = 'return cursor to where it was last time closing the file', - pattern = '*', - command = 'silent! normal! g`"zv', -}) - --- [[ Basic Autocommands ]] --- See `:help lua-guide-autocommands` - --- Highlight when yanking (copying) text --- Try it with `yap` in normal mode --- See `:help vim.highlight.on_yank()` -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) +require 'lua/custom/config/global' +require 'lua/custom/config/options' +require 'lua/custom/config/keymaps' +require 'lua/custom/config/api' +require 'lua/custom/config/filetypes' -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info @@ -225,8 +99,6 @@ if not vim.loop.fs_stat(lazypath) then end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) -vim.g.editorconfig = true - -- [[ Configure and install plugins ]] -- -- To check the current status of your plugins, run @@ -539,9 +411,9 @@ require('lazy').setup({ -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { - -- jsonls = {}, + jsonls = {}, -- clangd = {}, - -- gopls = {}, + gopls = {}, -- pyright = {}, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs @@ -551,7 +423,9 @@ require('lazy').setup({ -- -- But for many setups, the LSP (`tsserver`) will work just fine -- tsserver = {}, - -- + bashls = { + filetypes = { 'sh', 'bats', 'bash' }, + }, lua_ls = { -- cmd = {...}, @@ -624,6 +498,7 @@ require('lazy').setup({ formatters_by_ft = { lua = { 'stylua' }, yaml = { 'prettier' }, + bash = { 'shfmt' }, -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, @@ -658,6 +533,7 @@ require('lazy').setup({ -- nvim-cmp does not ship with all sources by default. They are split -- into multiple repos for maintenance purposes. 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-path', -- If you want to add a bunch of pre-configured snippets, @@ -723,6 +599,7 @@ require('lazy').setup({ { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'path' }, + { name = 'nvim_lua' }, }, } end, @@ -816,6 +693,28 @@ require('lazy').setup({ -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects end, }, + { + { + 'kdheepak/lazygit.nvim', + cmd = { + 'LazyGit', + 'LazyGitConfig', + 'LazyGitCurrentFile', + 'LazyGitFilter', + 'LazyGitFilterCurrentFile', + }, + -- optional for floating window border decoration + dependencies = { + 'nvim-lua/plenary.nvim', + }, + -- setting the keybinding for LazyGit with 'keys' is recommended in + -- order to load the plugin when the command is run for the first time + keys = { + { 'lg', 'LazyGit', desc = 'LazyGit' }, + }, + }, + { 'shellpad/shellpad.nvim', opts = {} }, + }, -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the -- init.lua. If you want these files, they are in the repository, so you can just download them and diff --git a/lua/custom/config/api.lua b/lua/custom/config/api.lua new file mode 100644 index 00000000..a38c4204 --- /dev/null +++ b/lua/custom/config/api.lua @@ -0,0 +1,20 @@ +vim.api.nvim_create_autocmd({ 'BufWinEnter' }, { + group = vim.api.nvim_create_augroup('custom-cursor-remember', { clear = true }), + desc = 'return cursor to where it was last time closing the file', + pattern = '*', + command = 'silent! normal! g`"zv', +}) + +-- [[ Basic Autocommands ]] +-- See `:help lua-guide-autocommands` + +-- Highlight when yanking (copying) text +-- Try it with `yap` in normal mode +-- See `:help vim.highlight.on_yank()` +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, +}) diff --git a/lua/custom/config/filetypes.lua b/lua/custom/config/filetypes.lua new file mode 100644 index 00000000..abc06b7a --- /dev/null +++ b/lua/custom/config/filetypes.lua @@ -0,0 +1,5 @@ +vim.filetype.add { + extension = { + bats = 'bash', + }, +} diff --git a/lua/custom/config/global.lua b/lua/custom/config/global.lua new file mode 100644 index 00000000..f131a6d2 --- /dev/null +++ b/lua/custom/config/global.lua @@ -0,0 +1,10 @@ +-- Set as the leader key +-- See `:help mapleader` +-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +-- Set to true if you have a Nerd Font installed +vim.g.have_nerd_font = false + +vim.g.editorconfig = true diff --git a/lua/custom/config/keymaps.lua b/lua/custom/config/keymaps.lua new file mode 100644 index 00000000..acb0ed28 --- /dev/null +++ b/lua/custom/config/keymaps.lua @@ -0,0 +1,29 @@ +-- Disable arrow keys in normal mode +vim.keymap.set('n', '', 'echo "Use h to move!!"') +vim.keymap.set('n', '', 'echo "Use l to move!!"') +vim.keymap.set('n', '', 'echo "Use k to move!!"') +vim.keymap.set('n', '', 'echo "Use j to move!!"') + +vim.keymap.set('n', '', 'nohlsearch') + +-- Diagnostic keymaps +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) +vim.keymap.set('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 +-- is not what someone will guess without a bit more experience. +-- +-- 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' }) + +-- 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', '0', '^') diff --git a/lua/custom/config/options.lua b/lua/custom/config/options.lua new file mode 100644 index 00000000..6c4c42b6 --- /dev/null +++ b/lua/custom/config/options.lua @@ -0,0 +1,69 @@ +-- [[ Setting options ]] +-- See `:help vim.opt` +-- NOTE: You can change these options as you wish! +-- For more options, you can see `:help option-list` + +-- Make line numbers default +vim.opt.number = true +-- You can also add relative line numbers, for help with jumping. +-- Experiment for yourself to see if you like it! +vim.opt.relativenumber = true + +-- Enable mouse mode, can be useful for resizing splits for example! +vim.opt.mouse = 'a' + +-- Don't show the mode, since it's already in status line +vim.opt.showmode = false + +-- Sync clipboard between OS and Neovim. +-- Remove this option if you want your OS clipboard to remain independent. +-- See `:help 'clipboard'` +vim.opt.clipboard = 'unnamedplus' + +-- Enable break indent +vim.opt.breakindent = true +-- Save undo history +vim.opt.undofile = true + +-- Case-insensitive searching UNLESS \C or capital in search +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Keep signcolumn on by default +vim.opt.signcolumn = 'yes' + +-- Decrease update time +vim.opt.updatetime = 250 +vim.opt.timeoutlen = 300 + +-- Configure how new splits should be opened +vim.opt.splitright = true +vim.opt.splitbelow = true + +-- Sets how neovim will display certain whitespace in the editor. +-- See `:help 'list'` +-- and `:help 'listchars'` +vim.opt.list = true +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } + +-- Preview substitutions live, as you type! +vim.opt.inccommand = 'split' + +-- Show which line your cursor is on +vim.opt.cursorline = true + +-- Minimal number of screen lines to keep above and below the cursor. +vim.opt.scrolloff = 10 + +-- [[ Basic Keymaps ]] +-- See `:help vim.keymap.set()` + +-- Set highlight on search, but clear on pressing in normal mode +vim.opt.hlsearch = true + +-- custom +vim.opt.shell = 'cmd.exe' +vim.opt.autoread = true +vim.opt.expandtab = true +vim.opt.autoindent = true +vim.opt.shiftwidth = 2