-- ----------------------------------------------------------------------------------------------- -- General configuration -- ----------------------------------------------------------------------------------------------- -- Basic settings vim.opt.hlsearch = true vim.opt.number = true vim.opt.mouse = "a" vim.opt.showmode = false vim.opt.spelllang = "en_gb" vim.opt.title = true vim.opt.titlestring = "nvim" -- Leader (this is here so plugins etc pick it up) vim.g.mapleader = " " -- anywhere you see = hit , -- use nvim-tree instead vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 -- Use system clipboard vim.opt.clipboard:append({ "unnamed", "unnamedplus" }) -- Display settings vim.opt.termguicolors = true vim.o.background = "dark" -- set to "dark" for dark theme -- Scrolling and UI settings vim.opt.cursorline = true vim.opt.cursorcolumn = true vim.opt.signcolumn = 'yes' vim.opt.wrap = false vim.opt.sidescrolloff = 8 vim.opt.scrolloff = 8 -- Persist undo (persists your undo history between sessions) vim.opt.undodir = vim.fn.stdpath("cache") .. "/undo" vim.opt.undofile = true -- Tab stuff vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true vim.opt.autoindent = true -- Search configuration vim.opt.ignorecase = true vim.opt.smartcase = true vim.opt.gdefault = true -- open new split panes to right and below (as you probably expect) vim.opt.splitright = true vim.opt.splitbelow = true -- LSP vim.lsp.inlay_hint.enable(true) -- ----------------------------------------------------------------------------------------------- -- Plugin list -- ----------------------------------------------------------------------------------------------- local plugins = { { "nvim-lua/plenary.nvim" }, -- used by several other plugins { "catppuccin/nvim" }, { "nvim-tree/nvim-web-devicons", lazy = true }, -- used by lualine and nvim-tree { "nvim-lualine/lualine.nvim" }, -- Status line { "nvim-tree/nvim-tree.lua" }, -- File browser { "numToStr/Comment.nvim" }, { "nvim-lua/plenary.nvim" }, { "ThePrimeagen/harpoon" }, -- Telescope command menu { "nvim-telescope/telescope.nvim" }, { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, -- TreeSitter { "nvim-treesitter/nvim-treesitter", priority = 1000, build = ":TSUpdate" }, -- LSP { 'mason-org/mason.nvim' }, -- installs LSP servers { 'neovim/nvim-lspconfig' }, -- configures LSPs { 'mason-org/mason-lspconfig.nvim' }, -- links installed to configured { 'stevearc/conform.nvim' }, -- Formatting where the LSP doesn't -- AI trash -- { 'supermaven-inc/supermaven-nvim' }, { 'saghen/blink.cmp', -- Blink completion tool (LSP, snippets etc) version = '1.*', -- see keymap here: -- opts_extend = { "sources.default" } -- https://cmp.saghen.dev/configuration/keymap.html#default opts = { keymap = { preset = "default" }, sources = { default = { "lsp", "path", "buffer" }, }, }, }, { "christoomey/vim-tmux-navigator", cmd = { "TmuxNavigateLeft", "TmuxNavigateDown", "TmuxNavigateUp", "TmuxNavigateRight", "TmuxNavigatePrevious", "TmuxNavigatorProcessList", }, keys = { { "", "TmuxNavigateLeft" }, { "", "TmuxNavigateDown" }, { "", "TmuxNavigateUp" }, { "", "TmuxNavigateRight" }, { "", "TmuxNavigatePrevious" }, }, } } -- ----------------------------------------------------------------------------------------------- -- Plugin installation -- ----------------------------------------------------------------------------------------------- local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath, }) end vim.opt.rtp:prepend(lazypath) require("lazy").setup(plugins) -- ----------------------------------------------------------------------------------------------- -- Plugin config -- ----------------------------------------------------------------------------------------------- vim.cmd.colorscheme("catppuccin") -- activate the theme require("lualine").setup() -- the status line require("nvim-tree").setup() -- the tree file browser panel require("telescope").setup() -- command menu require("Comment").setup() -- require("supermaven-nvim").setup({}) -- ----------------------------------------------------------------------------------------------- -- Treesitter (syntax highlighting and related stuff!) -- ----------------------------------------------------------------------------------------------- -- NB: Make sure to add more from this list! -- https://github.com/nvim-treesitter/nvim-treesitter/tree/master#supported-languages require("nvim-treesitter.configs").setup({ ensure_installed = { "typescript", "python", "rust", "go" }, sync_install = false, auto_install = true, highlight = { enable = true, }, }) vim.opt.foldmethod = "expr" vim.opt.foldexpr = "nvim_treesitter#foldexpr()" vim.opt.foldlevel = 99 -- ----------------------------------------------------------------------------------------------- -- LSP -- ----------------------------------------------------------------------------------------------- -- NB: These will FAIL if you don't have the language toolchains installed! -- NB: Make sure to add more from this list! -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md require("mason").setup() require("mason-lspconfig").setup({ ensure_installed = { "gopls", "bashls", "beautysh" } }) require("conform").setup({ default_format_opts = { lsp_format = "fallback" }, -- Many languages can be formatted directly by their LSP formatters_by_ft = { -- but some can't, so conform is for those ones bash = { "beautysh" }, javascript = { "prettier" }, javascriptreact = { "prettier" }, typescript = { "prettier" }, typescriptreact = { "prettier" }, json = { "prettier" }, html = { "prettier" }, css = { "prettier" }, }, }) -- ----------------------------------------------------------------------------------------------- -- Keymap settings -- ----------------------------------------------------------------------------------------------- -- Basic keys vim.keymap.set("n", "", ":") -- hit to start a command, quicker than : -- vim.keymap.set("n", "q", "") -- "u" is undo, I map "q" to redo -- Search navigation -- n is always forward, N is always backward -- ' is now forward and ; is backward vim.keymap.set("n", "n", "v:searchforward ? 'n' : 'N'", { expr = true }) vim.keymap.set("n", "N", "v:searchforward ? 'N' : 'n'", { expr = true }) vim.keymap.set({ "n", "v" }, ";", "getcharsearch().forward ? ',' : ';'", { expr = true }) vim.keymap.set({ "n", "v" }, "'", "getcharsearch().forward ? ';' : ','", { expr = true }) -- toggle line numbers and wrap vim.keymap.set("n", "n", ":set nonumber! relativenumber!") vim.keymap.set("n", "w", ":set wrap! wrap?") -- Moving between splits and resizing vim.keymap.set("n", "", "") -- use Ctrl-j (and so on) to move between splits vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", ":vertical resize -2") vim.keymap.set("n", "", ":vertical resize +2") vim.keymap.set("n", "", ":resize -2") vim.keymap.set("n", "", ":resize +2") -- nvim-tree (file browser settings) vim.keymap.set("n", "", ":NvimTreeFocus") vim.keymap.set("n", "", ":NvimTreeFindFile") vim.keymap.set("n", "", ":NvimTreeClose") -- Formatting vim.keymap.set("n", "fo", require('conform').format) vim.keymap.set('n', 'k', vim.diagnostic.goto_next, { desc = "Next diagnostic" }) -- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = "Prev diagnostic" }) local tele_builtin = require("telescope.builtin") vim.keymap.set("n", "ff", tele_builtin.git_files, {}) -- ,ff to find git files vim.keymap.set("n", "fa", tele_builtin.find_files, {}) -- ,fa to find any files vim.keymap.set("n", "fg", tele_builtin.live_grep, {}) -- ,fg to ripgrep vim.keymap.set("n", "fb", tele_builtin.buffers, {}) -- ,fb to see recent buffers vim.keymap.set("n", "fh", tele_builtin.help_tags, {}) -- ,fh to search help vim.keymap.set("n", "v", require("harpoon.ui").toggle_quick_menu, {}) -- ,fh to search help vim.keymap.set("n", "b", require("harpoon.mark").add_file, {}) -- ,fh to search help -- =============================================================================================== -- Recommended extra keymaps for a modern Neovim workflow -- =============================================================================================== -- ---------------------------- -- LSP / IDE-like keymaps -- ---------------------------- -- These should work in all buffers with an LSP attached vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Show hover documentation" }) vim.keymap.set("i", "", vim.lsp.buf.signature_help, { desc = "Show signature help" }) vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition" }) vim.keymap.set("n", "gr", vim.lsp.buf.references, { desc = "List references" }) vim.keymap.set("n", "rn", vim.lsp.buf.rename, { desc = "Rename symbol" }) vim.keymap.set("n", "ca", vim.lsp.buf.code_action, { desc = "Code actions" }) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Previous diagnostic" }) vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Next diagnostic" }) vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "Send diagnostics to location list" }) vim.keymap.set("n", "f", function() vim.lsp.buf.format({ async = true }) end, { desc = "Format buffer" }) -- ---------------------------- -- Telescope / fuzzy finding -- ---------------------------- -- local tele_builtin = require("telescope.builtin") -- vim.keymap.set("n", "fs", tele_builtin.lsp_document_symbols, { desc = "Document symbols" }) -- vim.keymap.set("n", "fS", tele_builtin.lsp_workspace_symbols, { desc = "Workspace symbols" }) -- vim.keymap.set("n", "fo", tele_builtin.oldfiles, { desc = "Recently opened files" }) -- ---------------------------- -- Clipboard convenience -- ---------------------------- vim.keymap.set({ "n", "v" }, "y", '"+y', { desc = "Yank to system clipboard" }) vim.keymap.set("n", "p", '"+p', { desc = "Paste from system clipboard" }) -- ---------------------------- -- Window / tab navigation enhancements -- ---------------------------- vim.keymap.set("n", "ww", "p", { desc = "Switch to last window" }) vim.keymap.set("n", "to", ":tabnew", { desc = "New tab" }) vim.keymap.set("n", "tn", ":tabnext", { desc = "Next tab" }) vim.keymap.set("n", "tp", ":tabprevious", { desc = "Previous tab" }) -- ---------------------------- -- Folding (Treesitter) -- ---------------------------- vim.keymap.set("n", "za", "za", { desc = "Toggle fold under cursor" }) vim.keymap.set("n", "zR", "zR", { desc = "Open all folds" }) vim.keymap.set("n", "zM", "zM", { desc = "Close all folds" }) -- ---------------------------- -- Highlight on yank -- ---------------------------- vim.cmd([[ augroup YankHighlight autocmd! autocmd TextYankPost * silent! lua vim.highlight.on_yank{higroup="IncSearch", timeout=200} augroup END ]]) -- Show diagnostic message in a floating window vim.keymap.set("n", "e", vim.diagnostic.open_float, { desc = "Show diagnostics in float" })