From 5153613b3be6bda083595cdb96b2eba72dca05f5 Mon Sep 17 00:00:00 2001 From: David Ponte Date: Mon, 28 Apr 2025 15:56:40 +0200 Subject: [PATCH] Adds window resizing keymaps and Monokai theme Implements keymaps for window resizing and maximizing, providing more flexibility in window management. Also, includes Monokai theme with classic palette as a user option. Adds cpp to ensure_installed languages for treesitter. Add C LSP in Mason Plugin Added after folder to make sure comment string isn't altered by other plugins --- after/ftplugin/c.lua | 5 +++++ ftplugin/c.lua | 19 +++++++++++++++++++ init.lua | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 after/ftplugin/c.lua create mode 100644 ftplugin/c.lua diff --git a/after/ftplugin/c.lua b/after/ftplugin/c.lua new file mode 100644 index 00000000..9fb44987 --- /dev/null +++ b/after/ftplugin/c.lua @@ -0,0 +1,5 @@ +local set = vim.opt_local + +set.shiftwidth = 4 +set.tabstop = 4 +set.commentstring = '/* %s */' diff --git a/ftplugin/c.lua b/ftplugin/c.lua new file mode 100644 index 00000000..7894aabe --- /dev/null +++ b/ftplugin/c.lua @@ -0,0 +1,19 @@ +-- local set = vim.opt_local + +-- Define a custom command ':intmain' that inserts int main() {} template +vim.api.nvim_create_user_command('IntMain', function() + local current_line = vim.api.nvim_win_get_cursor(0)[1] + local lines = { + '#include ', + '', + 'int main ()', + '{', + ' ', + ' printf();', + ' return 0;', + '}', + } + vim.api.nvim_buf_set_lines(0, current_line - 1, current_line - 1, false, lines) + -- Position cursor inside the function body + vim.api.nvim_win_set_cursor(0, { current_line + 1, 4 }) +end, {}) diff --git a/init.lua b/init.lua index 71156af8..84493aa7 100644 --- a/init.lua +++ b/init.lua @@ -51,12 +51,29 @@ vim.g.have_nerd_font = false require 'options' -- [[ Basic Keymaps ]] --- See `:help vim.keymap.set()` +-- `:help vim.keymap.set()` -- Clear highlights on search when pressing in normal mode -- See `:help hlsearch` vim.keymap.set('n', '', 'nohlsearch') +-- Resize window +-- Leader+<: Decrease window width +vim.keymap.set('n', '<', 'vertical resize -5', { silent = true, desc = 'Decrease window width' }) + +-- Leader+>: Increase window width +vim.keymap.set('n', '>', 'vertical resize +5', { silent = true, desc = 'Increase window width' }) + +-- Alternative keys for larger adjustments +vim.keymap.set('n', '[', 'vertical resize -10', { silent = true, desc = 'Decrease window width more' }) +vim.keymap.set('n', ']', 'vertical resize +10', { silent = true, desc = 'Increase window width more' }) + +-- Leader+=: Equal width for all windows +vim.keymap.set('n', '=', '=', { silent = true, desc = 'Equal size all windows' }) + +-- Leader+|: Maximize current window width +vim.keymap.set('n', '|', '|', { silent = true, desc = 'Maximize window width' }) + -- Diagnostic keymaps vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) @@ -342,13 +359,6 @@ require('lazy').setup({ end, { desc = '[S]earch [N]eovim files' }) end, }, - -- { - -- 'nvim-tree/nvim-tree.lua', - -- dependencies = { 'nvim-tree/nvim-web-devicons' }, -- Optional, for file icons - -- config = function() - -- require('nvim-tree').setup {} - -- end, - -- }, -- LSP Plugins { @@ -764,6 +774,13 @@ require('lazy').setup({ }, }, + { + 'tanvirtin/monokai.nvim', + config = function() + -- pcall(vim.cmd, [[colorscheme monokai]]) + require('monokai').setup { palette = require('monokai').classic } + end, + }, { -- You can easily change to a different colorscheme. -- Change the name of the colorscheme plugin below, and then -- change the command in the config to whatever the name of that colorscheme is. @@ -775,7 +792,7 @@ require('lazy').setup({ ---@diagnostic disable-next-line: missing-fields require('tokyonight').setup { styles = { - comments = { italic = false }, -- Disable italics in comments + -- comments = { italic = false }, -- Disable italics in comments }, } @@ -785,13 +802,6 @@ require('lazy').setup({ vim.cmd.colorscheme 'tokyonight-night' end, }, - { - 'tanvirtin/monokai.nvim', - config = function() - -- pcall(vim.cmd, [[colorscheme monokai]]) - require('monokai').setup { palette = require('monokai').classic } - end, - }, -- Highlight todo, notes, etc in comments { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, @@ -842,6 +852,7 @@ require('lazy').setup({ ensure_installed = { 'bash', 'c', + 'cpp', 'diff', 'html', 'lua',