diff --git a/after/ftplugin/c.lua b/after/ftplugin/c.lua new file mode 100644 index 00000000000..01126cbb00b --- /dev/null +++ b/after/ftplugin/c.lua @@ -0,0 +1,82 @@ +-- Import vim module +local set = vim.opt_local + +-- Indentation settings +set.expandtab = false -- Convert tabs to spaces +set.shiftwidth = 4 -- Indent size for autoindent +set.tabstop = 4 -- How wide tabs appear +-- set.softtabstop = 4 -- How many spaces Tab key inserts/removes + +-- Comment string for commentary plugins +set.commentstring = '/* %s */' + +-- Disable vim-sleuth for C files +vim.g.sleuth_automatic = 0 + +-- 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(void)', + '{', + ' ', + ' printf("Hello, world!\\n");', + ' 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 + 4, 4 }) +end, {}) + +-- Define a custom command ':Libft' that inserts libft.h include +vim.api.nvim_create_user_command('Libft', function() + local current_line = vim.api.nvim_win_get_cursor(0)[1] + vim.api.nvim_buf_set_lines(0, current_line - 1, current_line - 1, false, { + '#include "libft.h"', + }) +end, {}) + +-- Define a custom command ':CommentRestOfFile' that comments out rest of file +vim.api.nvim_create_user_command('CommentRestOfFile', function() + local current_line = vim.api.nvim_win_get_cursor(0)[1] + local last_line = vim.api.nvim_buf_line_count(0) + + -- Get all lines from current to end of file + local lines = vim.api.nvim_buf_get_lines(0, current_line - 1, last_line, false) + + -- Prefix each line with // + for i = 1, #lines do + lines[i] = '//' .. lines[i] + end + + -- Set the modified lines back in the buffer + vim.api.nvim_buf_set_lines(0, current_line - 1, last_line, false, lines) +end, {}) + +-- Define a custom command ':UncommentRestOfFile' that removes comments from rest of file +vim.api.nvim_create_user_command('UncommentRestOfFile', function() + local current_line = vim.api.nvim_win_get_cursor(0)[1] + local last_line = vim.api.nvim_buf_line_count(0) + + -- Get all lines from current to end of file + local lines = vim.api.nvim_buf_get_lines(0, current_line - 1, last_line, false) + + -- Remove leading // if present + for i = 1, #lines do + lines[i] = lines[i]:gsub('^%s*//', '') + end + + -- Set the modified lines back in the buffer + vim.api.nvim_buf_set_lines(0, current_line - 1, last_line, false, lines) +end, {}) + +-- Add any C-specific key mappings you want here +-- Example: Map F5 to compile and run the current file +vim.keymap.set('n', '', function() + local filename = vim.fn.expand '%:r' + vim.cmd 'write' + vim.cmd('belowright split | terminal gcc -Wall -Wextra -Werror % -o ' .. filename .. ' && ./' .. filename) +end, { buffer = true, desc = 'Compile and run C file' }) diff --git a/init.lua b/init.lua index b98ffc6198a..cd2ffa8b4c5 100644 --- a/init.lua +++ b/init.lua @@ -1,177 +1,44 @@ ---[[ - -===================================================================== -==================== READ THIS BEFORE CONTINUING ==================== -===================================================================== -======== .-----. ======== -======== .----------------------. | === | ======== -======== |.-""""""""""""""""""-.| |-----| ======== -======== || || | === | ======== -======== || KICKSTART.NVIM || |-----| ======== -======== || || | === | ======== -======== || || |-----| ======== -======== ||:Tutor || |:::::| ======== -======== |'-..................-'| |____o| ======== -======== `"")----------------(""` ___________ ======== -======== /::::::::::| |::::::::::\ \ no mouse \ ======== -======== /:::========| |==hjkl==:::\ \ required \ ======== -======== '""""""""""""' '""""""""""""' '""""""""""' ======== -======== ======== -===================================================================== -===================================================================== - -What is Kickstart? - - Kickstart.nvim is *not* a distribution. - - Kickstart.nvim is a starting point for your own configuration. - The goal is that you can read every line of code, top-to-bottom, understand - what your configuration is doing, and modify it to suit your needs. - - Once you've done that, you can start exploring, configuring and tinkering to - make Neovim your own! That might mean leaving Kickstart just the way it is for a while - or immediately breaking it into modular pieces. It's up to you! - - If you don't know anything about Lua, I recommend taking some time to read through - a guide. One possible example which will only take 10-15 minutes: - - https://learnxinyminutes.com/docs/lua/ - - After understanding a bit more about Lua, you can use `:help lua-guide` as a - reference for how Neovim integrates Lua. - - :help lua-guide - - (or HTML version): https://neovim.io/doc/user/lua-guide.html - -Kickstart Guide: - - TODO: The very first thing you should do is to run the command `:Tutor` in Neovim. - - If you don't know what this means, type the following: - - - - : - - Tutor - - - - (If you already know the Neovim basics, you can skip this step.) - - Once you've completed that, you can continue working through **AND READING** the rest - of the kickstart init.lua. - - Next, run AND READ `:help`. - This will open up a help window with some basic information - about reading, navigating and searching the builtin help documentation. - - This should be the first place you go to look when you're stuck or confused - with something. It's one of my favorite Neovim features. - - MOST IMPORTANTLY, we provide a keymap "sh" to [s]earch the [h]elp documentation, - which is very useful when you're not exactly sure of what you're looking for. - - I have left several `:help X` comments throughout the init.lua - These are hints about where to find more information about the relevant settings, - plugins or Neovim features used in Kickstart. - - NOTE: Look for lines like this - - Throughout the file. These are for you, the reader, to help you understand what is happening. - Feel free to delete them once you know what you're doing, but they should serve as a guide - for when you are first encountering a few different constructs in your Neovim config. - -If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. - -I hope you enjoy your Neovim journey, -- TJ - -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 and selected in the terminal -vim.g.have_nerd_font = false - --- [[ Setting options ]] --- See `:help vim.o` --- NOTE: You can change these options as you wish! --- For more options, you can see `:help option-list` - --- Make line numbers default -vim.o.number = true --- You can also add relative line numbers, to help with jumping. --- Experiment for yourself to see if you like it! --- vim.o.relativenumber = true - --- Enable mouse mode, can be useful for resizing splits for example! -vim.o.mouse = 'a' - --- Don't show the mode, since it's already in the status line -vim.o.showmode = false - --- Sync clipboard between OS and Neovim. --- Schedule the setting after `UiEnter` because it can increase startup-time. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` -vim.schedule(function() - vim.o.clipboard = 'unnamedplus' -end) +-- Disables netrw for better file explorers +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 --- Enable break indent -vim.o.breakindent = true +-- optionally enable 24-bit colour +vim.opt.termguicolors = true --- Save undo history -vim.o.undofile = true - --- Case-insensitive searching UNLESS \C or one or more capital letters in the search term -vim.o.ignorecase = true -vim.o.smartcase = true - --- Keep signcolumn on by default -vim.o.signcolumn = 'yes' - --- Decrease update time -vim.o.updatetime = 250 - --- Decrease mapped sequence wait time -vim.o.timeoutlen = 300 +-- Set to true if you have a Nerd Font installed and selected in the terminal +vim.g.have_nerd_font = true --- Configure how new splits should be opened -vim.o.splitright = true -vim.o.splitbelow = true +-- Load options from options.lua +require 'options' --- Sets how neovim will display certain whitespace characters in the editor. --- See `:help 'list'` --- and `:help 'listchars'` --- --- Notice listchars is set using `vim.opt` instead of `vim.o`. --- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables. --- See `:help lua-options` --- and `:help lua-options-guide` -vim.o.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +-- [[ Basic Keymaps ]] +-- `:help vim.keymap.set()` --- Preview substitutions live, as you type! -vim.o.inccommand = 'split' +-- Clear highlights on search when pressing in normal mode +-- See `:help hlsearch` +vim.keymap.set('n', '', 'nohlsearch') --- Show which line your cursor is on -vim.o.cursorline = true +-- Resize window +-- Leader+<: Decrease window width +vim.keymap.set('n', '<', 'vertical resize -5', { silent = true, desc = 'Decrease window width' }) --- Minimal number of screen lines to keep above and below the cursor. -vim.o.scrolloff = 10 +-- Leader+>: Increase window width +vim.keymap.set('n', '>', 'vertical resize +5', { silent = true, desc = 'Increase window width' }) --- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`), --- instead raise a dialog asking if you wish to save the current file(s) --- See `:help 'confirm'` -vim.o.confirm = true +-- 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' }) --- [[ Basic Keymaps ]] --- See `:help vim.keymap.set()` +-- Leader+=: Equal width for all windows +vim.keymap.set('n', '=', '=', { silent = true, desc = 'Equal size all windows' }) --- Clear highlights on search when pressing in normal mode --- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') +-- 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' }) @@ -283,7 +150,18 @@ require('lazy').setup({ }, }, }, + { -- AutoSession takes advantage of Neovim's existing session management capabilities to provide seamless automatic session management + 'rmagatti/auto-session', + lazy = false, + ---enables autocomptete for opts + ---@module "auto-session" + ---@type AutoSession.Config + opts = { + suppressed_dirs = { '~/', '~/Projects', '~/Downloads', '/' }, + -- log_level = 'debug', + }, + }, -- NOTE: Plugins can also be configured to run Lua code when they are loaded. -- -- This is often very useful to both group configuration, as well as handle @@ -845,6 +723,7 @@ require('lazy').setup({ -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' -- Adjusts spacing to ensure icons are aligned nerd_font_variant = 'mono', + -- nerd_font_variant = 'normal', }, completion = { @@ -875,7 +754,126 @@ require('lazy').setup({ signature = { enabled = true }, }, }, + -- -- Norminette checker + -- { + -- 'hardyrafael17/norminette42.nvim', + -- config = function() + -- local norminette = require 'norminette' + -- norminette.setup { + -- runOnSave = true, + -- maxErrorsToShow = 5, + -- active = true, + -- } + -- end, + -- }, + { + 'loctvl842/monokai-pro.nvim', + opts = { + transparent_background = true, + terminal_colors = true, + devicons = true, -- highlight the icons of `nvim-web-devicons` + styles = { + comment = { italic = true }, + keyword = { italic = true }, -- any other keyword + type = { italic = true }, -- (preferred) int, long, char, etc + storageclass = { italic = true }, -- static, register, volatile, etc + structure = { italic = true }, -- struct, union, enum, etc + parameter = { italic = true }, -- parameter pass in function + annotation = { italic = true }, + tag_attribute = { italic = true }, -- attribute of tag in reactjs + }, + filter = 'pro', -- classic | octagon | pro | machine | ristretto | spectrum + -- Enable this will disable filter option + day_night = { + enable = true, -- turn off by default + day_filter = 'pro', -- classic | octagon | pro | machine | ristretto | spectrum + night_filter = 'spectrum', -- classic | octagon | pro | machine | ristretto | spectrum + }, + inc_search = 'background', -- underline | background + background_clear = { + -- -- "float_win", + -- "toggleterm", + 'telescope', + -- "which-key", + 'renamer', + 'notify', + 'nvim-tree', + -- 'neo-tree', + 'bufferline', -- better used if background of `neo-tree` or `nvim-tree` is cleared + }, -- "float_win", "toggleterm", "telescope", "which-key", "renamer", "neo-tree", "nvim-tree", "bufferline" + plugins = { + bufferline = { + underline_selected = false, + underline_visible = false, + }, + indent_blankline = { + context_highlight = 'default', -- default | pro + context_start_underline = false, + }, + }, + ---@param cs Colorscheme + ---@param p ColorschemeOptions + ---@param Config MonokaiProOptions + ---@param hp Helper + override = function(cs, p, Config, hp) end, + }, + config = function(_, opts) + require('monokai-pro').setup(opts) + vim.cmd 'colorscheme monokai-pro' + end, + }, + { + 'polirritmico/monokai-nightasty.nvim', + lazy = false, + priority = 1000, + keys = { + { 'tt', 'MonokaiToggleLight', desc = 'Monokai-Nightasty: Toggle dark/light theme.' }, + }, + ---@module "monokai-nightasty" + ---@type monokai.UserConfig + opts = { + dark_style_background = 'transparent', -- default | dark | transparent | #RRGGBB + light_style_background = 'transparent', -- default | dark | transparent | #RRGGBB + markdown_header_marks = true, + hl_styles = { + keywords = { italic = true }, + comments = { italic = true }, + floats = 'dark', + }, + terminal_colors = function(colors) + return { fg = colors.fg_dark } + end, + on_colors = function(colors) + if vim.o.background == 'light' then + -- Custom colors for light theme + colors.comment = '#2d7e79' + colors.lualine.normal_bg = '#7ebd00' + else + -- Custom colors for dark theme + colors.border = colors.magenta + colors.lualine.normal_bg = colors.green + end + end, + on_highlights = function(highlights, colors) + -- You could add styles like bold, underline, italic + highlights.TelescopeSelection = { bold = true } + highlights.TelescopeBorder = { fg = colors.grey } + highlights['@lsp.type.property.lua'] = { fg = colors.fg } + end, + }, + config = function(_, opts) + vim.opt.cursorline = true -- Highlight line at the cursor position + vim.o.background = 'dark' -- Default to dark theme + require('monokai-nightasty').load(opts) + end, + }, + { + 'tanvirtin/monokai.nvim', + config = function() + 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. @@ -886,8 +884,9 @@ require('lazy').setup({ config = function() ---@diagnostic disable-next-line: missing-fields require('tokyonight').setup { + transparent = true, styles = { - comments = { italic = false }, -- Disable italics in comments + comments = { italic = true }, -- Disable italics in comments }, } @@ -897,7 +896,36 @@ require('lazy').setup({ vim.cmd.colorscheme 'tokyonight-night' end, }, + { + 'rose-pine/neovim', + config = function() + require('rose-pine').setup { + variant = 'auto', -- auto, main, moon, or dawn + dark_variant = 'main', -- main, moon, or dawn + dim_inactive_windows = false, + extend_background_behind_borders = true, + + enable = { + terminal = true, + legacy_highlights = true, + migrations = true, + }, + styles = { + bold = true, + italic = true, + transparency = false, + }, + + highlight_groups = { + Comment = { fg = 'foam' }, + -- StatusLine = { fg = "love", bg = "love", blend = 15 }, + -- VertSplit = { fg = "muted", bg = "muted" }, + -- Visual = { fg = "base", bg = "text", inherit = false }, + }, + } + end, + }, -- Highlight todo, notes, etc in comments { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, @@ -944,7 +972,23 @@ require('lazy').setup({ main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + ensure_installed = { + 'bash', + 'c', + 'cpp', + 'diff', + 'html', + 'lua', + 'luadoc', + 'markdown', + 'markdown_inline', + 'query', + 'vim', + 'vimdoc', + 'javascript', + 'rust', + 'typescript', + }, -- Autoinstall languages that are not installed auto_install = true, highlight = { @@ -973,23 +1017,23 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps + require 'kickstart.plugins.debug', + require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.lint', + require 'kickstart.plugins.autopairs', + require 'kickstart.plugins.neo-tree', + require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, - -- + { import = 'custom.plugins' }, + -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! -- In normal mode type `sh` then write `lazy.nvim-plugin` - -- you can continue same window with `sr` which resumes last telescope search + -- you can co tinue same window with `sr` which resumes last telescope search }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the diff --git a/lua/custom/plugins/codam-header.lua b/lua/custom/plugins/codam-header.lua new file mode 100644 index 00000000000..a2bcbcfb4cd --- /dev/null +++ b/lua/custom/plugins/codam-header.lua @@ -0,0 +1,13 @@ +return { + 'f-ras/codam-header.nvim', + cmd = { 'Stdheader' }, + opts = { + auto_update = true, -- Update header when saving. + user = 'dponte', + mail = 'dponte@student.codam.nl', -- Your mail. + -- add other options. + }, + config = function(_, opts) + require('codamheader').setup(opts) + end, +} diff --git a/lua/custom/plugins/nvim-tree.lua b/lua/custom/plugins/nvim-tree.lua new file mode 100644 index 00000000000..febf277d8c2 --- /dev/null +++ b/lua/custom/plugins/nvim-tree.lua @@ -0,0 +1,25 @@ +return { + 'nvim-tree/nvim-tree.lua', + dependencies = { 'nvim-tree/nvim-web-devicons' }, -- Optional, for file icons + config = function() + require('nvim-tree').setup { + sort = { + sorter = 'case_sensitive', + folders_first = true, + files_first = false, + }, + view = { + width = 30, + }, + renderer = { + group_empty = true, + }, + filters = { + dotfiles = true, + }, + } + + -- Key mapping to toggle NvimTree + vim.keymap.set('n', '', ':NvimTreeToggle', { desc = 'Toggle NvimTree' }) + end, +} diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 00000000000..52268c17363 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,70 @@ +-- [[ 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, to 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 the status line +vim.opt.showmode = false + +-- Sync clipboard between OS and Neovim. +-- Schedule the setting after `UiEnter` because it can increase startup-time. +-- Remove this option if you want your OS clipboard to remain independent. +-- See `:help 'clipboard'` +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' +end) + +-- Enable break indent +vim.opt.breakindent = true + +-- Save undo history +vim.opt.undofile = true + +-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Keep signcolumn on by default +vim.opt.signcolumn = 'yes' + +-- Decrease update time +vim.opt.updatetime = 250 + +-- Decrease mapped sequence wait time +vim.opt.timeoutlen = 300 + +-- Configure how new splits should be opened +vim.opt.splitright = true +vim.opt.splitbelow = true + +-- swapfile +vim.opt.swapfile = false + +-- Sets how neovim will display certain whitespace characters 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 + +-- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`), +-- instead raise a dialog asking if you wish to save the current file(s) +-- See `:help 'confirm'` +vim.opt.confirm = true