--[[--------------------------------------------- - Description - Vilyaem's Neovim Configuration - Author - Vilyaem - -------------------------------------------]] vim.g.mapleader = " " --Vilyaem's Settings vim.opt.autoindent = true vim.opt.backspace = { 'indent', 'eol', 'start' } vim.opt.encoding = 'utf-8' vim.opt.expandtab = true vim.opt.lazyredraw = true vim.opt.list = true vim.opt.listchars = { tab = '>.' } vim.opt.mouse = 'a' vim.opt.swapfile = false vim.opt.number = true vim.opt.relativenumber = true vim.opt.spelllang = 'en_gb' vim.opt.shiftwidth = 2 vim.opt.viminfo = '' vim.opt.history = 1000 --Colouring vim.cmd("highlight Comment guifg=NONE ") vim.cmd("highlight @comment guifg=NONE ") vim.api.nvim_set_hl(0,"Normal",{bg = "none"}) vim.api.nvim_set_hl(0,"NormalFloat",{bg = "none"}) --Enable King's English Spell Checking vim.opt.spelllang = 'en_gb' vim.opt.spell = true -- Easy search and replace vim.api.nvim_set_keymap('n', 'S', ':%s///g', { noremap = true }) vim.api.nvim_set_keymap('v', 'S', ':s///g', { noremap = true }) -- Easy save vim.api.nvim_set_keymap('n', 'W', ':w', { noremap = true }) -- Function or File heading function FileHeading() local line = vim.fn.line(".") vim.fn.setline(line, "/*********************************************") vim.fn.append(line, "* Description - ") vim.fn.append(line + 1, "* Author - Vilyaem") vim.fn.append(line + 2, "* *******************************************/") end vim.api.nvim_set_keymap('i', '', ':lua FileHeading()g;kkA', { noremap = true }) -- Section vim.api.nvim_set_keymap('i', '', 'I/*----------!----------*//!?xi', { noremap = true }) --F6 talk to the soybot vim.api.nvim_set_keymap("n","",":Gen",{noremap = true, silent = true}) -- Set the key mappings for the GDB commands vim.keymap.set("n", "db", "GdbStart", { noremap = true, silent = true }) vim.keymap.set("n", "dc", "GdbContinue", { noremap = true, silent = true }) vim.keymap.set("n", "dn", "GdbNext", { noremap = true, silent = true }) vim.keymap.set("n", "ds", "GdbStep", { noremap = true, silent = true }) vim.keymap.set("n", "di", "GdbStepInto", { noremap = true, silent = true }) vim.keymap.set("n", "do", "GdbStepOut", { noremap = true, silent = true }) vim.keymap.set("n", "db", "GdbBreakpoint", { noremap = true, silent = true }) vim.keymap.set("n", "dw", "GdbWatch", { noremap = true, silent = true }) --Calculate expression plugin vim.api.nvim_create_user_command("Calculate", "lua require(\"calculator\").calculate()", { ["range"] = 1, ["nargs"] = 0 }) --Setup packer -- Install packer.nvim for plugin management local function bootstrap_packer() local fn = vim.fn local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) vim.cmd('packadd packer.nvim') return true end return false end local packer_bootstrap = bootstrap_packer() -- Use packer to manage plugins require('packer').startup(function(use) use 'wbthomason/packer.nvim' -- Package manager use{"L3MON4D3/LuaSnip"} use{"vzze/calculator.nvim"} use{"hrsh7th/nvim-cmp"} use{"hrsh7th/cmp-buffer"} use{"hrsh7th/cmp-nvim-lsp"} use{"hrsh7th/cmp-nvim-lua"} use{"hrsh7th/cmp-path"} use{"saadparwaiz1/cmp_luasnip"} use{"stevearc/conform.nvim"} use{"rafamadriz/friendly-snippets"} use{"David-Kunz/gen.nvim"} use{"lewis6991/gitsigns.nvim"} use{"lukas-reineke/indent-blankline.nvim"} use{"williamboman/mason.nvim"} use{"williamboman/mason-lspconfig.nvim"} use{"windwp/nvim-autopairs"} use{"sakhnik/nvim-gdb"} use{"neovim/nvim-lspconfig"} use{"nvim-tree/nvim-tree.lua"} use{"nvim-treesitter/nvim-treesitter"} use{"nvim-lua/plenary.nvim"} use{"nvim-telescope/telescope.nvim"} use{"ThePrimeagen/vim-be-good"} use{"folke/which-key.nvim"} if packer_bootstrap then require('packer').sync() end end) -- Setup installed packages require("nvim-tree").setup() require("mason").setup() require("telescope").setup{} -- LSP vim.api.nvim_create_autocmd('LspAttach', { desc = 'LSP actions', callback = function(event) local opts = {buffer = event.buf} -- these will be buffer-local keybindings -- because they only work if you have an active language server vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) vim.keymap.set({'n', 'x'}, '', 'lua vim.lsp.buf.format({async = true})', opts) vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) end }) local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities() require('mason').setup({}) require('mason-lspconfig').setup({ ensure_installed = {}, handlers = { function(clangd) require('lspconfig').clangd.setup({ capabilities = lsp_capabilities, }) end, }, }) local cmp = require('cmp') cmp.setup({ sources = { {name = 'nvim_lsp'}, }, mapping = cmp.mapping.preset.insert({ -- Enter key confirms completion item [''] = cmp.mapping.confirm({select = false}), -- Ctrl + space triggers completion menu [''] = cmp.mapping.complete(), }), snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, }) -- Set package keybindings local map = vim.keymap.set map("i", "", "^i", { desc = "move beginning of line" }) map("i", "", "", { desc = "move end of line" }) map("i", "", "", { desc = "move left" }) map("i", "", "", { desc = "move right" }) map("i", "", "", { desc = "move down" }) map("i", "", "", { desc = "move up" }) map("n", "", "h", { desc = "switch window left" }) map("n", "", "l", { desc = "switch window right" }) map("n", "", "j", { desc = "switch window down" }) map("n", "", "k", { desc = "switch window up" }) map("n", "", "noh", { desc = "general clear highlights" }) map("n", "", "w", { desc = "general save file" }) map("n", "", "%y+", { desc = "general copy whole file" }) -- Key mappings for tab navigation vim.api.nvim_set_keymap('n', '', ':tabnext', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '', ':tabprevious', { noremap = true, silent = true }) -- Key mappings for closing and creating tabs vim.api.nvim_set_keymap('n', 'x', ':tabclose', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', 'b', ':tabnew', { noremap = true, silent = true }) -- Ensure new files opened from Nvim Tree open in new tabs vim.api.nvim_create_autocmd("BufEnter", { pattern = "*", callback = function() if vim.fn.winnr('$') == 1 and vim.bo.filetype == 'NvimTree' then vim.cmd('tabnew') end end }) -- Comment map("n", "/", "gcc", { desc = "toggle comment", remap = true }) map("v", "/", "gc", { desc = "toggle comment", remap = true }) -- nvimtree map("n", "", "NvimTreeToggle", { desc = "nvimtree toggle window" }) map("n", "e", "NvimTreeFocus", { desc = "nvimtree focus window" }) -- telescope map("n", "fw", "Telescope live_grep", { desc = "telescope live grep" }) map("n", "fb", "Telescope buffers", { desc = "telescope find buffers" }) map("n", "fh", "Telescope help_tags", { desc = "telescope help page" }) map("n", "ma", "Telescope marks", { desc = "telescope find marks" }) map("n", "fo", "Telescope oldfiles", { desc = "telescope find oldfiles" }) map("n", "fz", "Telescope current_buffer_fuzzy_find", { desc = "telescope find in current buffer" }) map("n", "cm", "Telescope git_commits", { desc = "telescope git commits" }) map("n", "gt", "Telescope git_status", { desc = "telescope git status" }) map("n", "pt", "Telescope terms", { desc = "telescope pick hidden term" }) map("n", "ff", "Telescope find_files", { desc = "telescope find files" }) map( "n", "fa", "Telescope find_files follow=true no_ignore=true hidden=true", { desc = "telescope find all files" } )