Last active
January 6, 2025 16:12
-
-
Save hailelagi/22e97fe87f85a1f5a6c500c39681cb51 to your computer and use it in GitHub Desktop.
neovim enjoying
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Disable netrw at the very start of your init.lua | |
| vim.g.loaded_netrw = 1 | |
| vim.g.loaded_netrwPlugin = 1 | |
| -- Set termguicolors to enable highlight groups | |
| vim.opt.termguicolors = true | |
| -- Ensure packer is installed | |
| 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 | |
| PACKER_BOOTSTRAP = fn.system({ | |
| 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path | |
| }) | |
| print("Installing packer... Restart Neovim after installation") | |
| vim.cmd([[packadd packer.nvim]]) | |
| end | |
| -- Set up packer | |
| require('packer').startup(function(use) | |
| use 'wbthomason/packer.nvim' -- Packer can manage itself | |
| use 'nvim-treesitter/nvim-treesitter' | |
| use 'Mofiqul/dracula.nvim' | |
| -- LSP plugins | |
| use 'neovim/nvim-lspconfig' -- LSP configuration | |
| use 'williamboman/mason.nvim' -- LSP installer | |
| use 'williamboman/mason-lspconfig.nvim' | |
| -- Autocompletion plugins | |
| use 'hrsh7th/nvim-cmp' -- Completion engine | |
| use 'hrsh7th/cmp-nvim-lsp' -- LSP completion source | |
| use 'hrsh7th/cmp-buffer' -- Buffer completion source | |
| use 'hrsh7th/cmp-path' -- Path completion source | |
| use 'hrsh7th/cmp-cmdline' -- Command line completion source | |
| use 'L3MON4D3/LuaSnip' -- Snippet engine | |
| use 'saadparwaiz1/cmp_luasnip' -- Snippet completion source | |
| -- Add telescope and its dependencies | |
| use { | |
| 'nvim-telescope/telescope.nvim', | |
| tag = '0.1.5', | |
| requires = { {'nvim-lua/plenary.nvim'} } | |
| } | |
| use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } | |
| -- Add nvim-tree | |
| use { 'nvim-tree/nvim-tree.lua' } | |
| -- Add Comment.nvim | |
| use 'numToStr/Comment.nvim' | |
| -- Automatically set up after cloning packer.nvim | |
| if PACKER_BOOTSTRAP then | |
| require('packer').sync() | |
| end | |
| end) | |
| vim.cmd[[colorscheme dracula]] | |
| -- nvim-treesitter setup | |
| require'nvim-treesitter.configs'.setup { | |
| ensure_installed = { "c", "cpp", "go", "rust", "elixir" }, | |
| highlight = { | |
| enable = true, | |
| }, | |
| indent = { | |
| enable = true, | |
| }, | |
| } | |
| -- Set up Mason | |
| require("mason").setup() | |
| require("mason-lspconfig").setup({ | |
| ensure_installed = { "clangd", "rust_analyzer", "gopls", "elixirls" } | |
| }) | |
| -- LSP configurations | |
| local lspconfig = require('lspconfig') | |
| local cmp = require('cmp') | |
| local luasnip = require('luasnip') | |
| -- Set up nvim-cmp | |
| cmp.setup({ | |
| snippet = { | |
| expand = function(args) | |
| luasnip.lsp_expand(args.body) | |
| end, | |
| }, | |
| mapping = cmp.mapping.preset.insert({ | |
| ['<C-b>'] = cmp.mapping.scroll_docs(-4), | |
| ['<C-f>'] = cmp.mapping.scroll_docs(4), | |
| ['<C-Space>'] = cmp.mapping.complete(), | |
| ['<C-e>'] = cmp.mapping.abort(), | |
| ['<CR>'] = cmp.mapping.confirm({ select = true }), | |
| ['<Tab>'] = cmp.mapping(function(fallback) | |
| if cmp.visible() then | |
| cmp.select_next_item() | |
| elseif luasnip.expand_or_jumpable() then | |
| luasnip.expand_or_jump() | |
| else | |
| fallback() | |
| end | |
| end, { 'i', 's' }), | |
| ['<S-Tab>'] = cmp.mapping(function(fallback) | |
| if cmp.visible() then | |
| cmp.select_prev_item() | |
| elseif luasnip.jumpable(-1) then | |
| luasnip.jump(-1) | |
| else | |
| fallback() | |
| end | |
| end, { 'i', 's' }), | |
| }), | |
| sources = cmp.config.sources({ | |
| { name = 'nvim_lsp' }, | |
| { name = 'luasnip' }, | |
| { name = 'buffer' }, | |
| { name = 'path' }, | |
| }), | |
| }) | |
| -- Set up lspconfig with cmp capabilities | |
| local capabilities = require('cmp_nvim_lsp').default_capabilities() | |
| -- C/C++ language server | |
| lspconfig.clangd.setup{ | |
| capabilities = capabilities, | |
| cmd = { | |
| "clangd", | |
| "--background-index", | |
| "--clang-tidy", | |
| "--header-insertion=iwyu", | |
| "--completion-style=detailed", | |
| "--function-arg-placeholders" | |
| } | |
| } | |
| -- Rust language server | |
| lspconfig.rust_analyzer.setup{ | |
| capabilities = capabilities | |
| } | |
| -- Go language server | |
| lspconfig.gopls.setup{ | |
| capabilities = capabilities, | |
| settings = { | |
| gopls = { | |
| analyses = { | |
| unusedparams = true, | |
| shadow = true, | |
| nilness = true, | |
| unusedwrite = true, | |
| useany = true, | |
| }, | |
| staticcheck = true, | |
| gofumpt = true, | |
| usePlaceholders = true, | |
| hints = { | |
| assignVariableTypes = true, | |
| compositeLiteralFields = true, | |
| compositeLiteralTypes = true, | |
| constantValues = true, | |
| functionTypeParameters = true, | |
| parameterNames = true, | |
| rangeVariableTypes = true, | |
| }, | |
| }, | |
| }, | |
| flags = { | |
| debounce_text_changes = 150, | |
| }, | |
| } | |
| -- Elixir LSP setup | |
| lspconfig.elixirls.setup{ | |
| capabilities = capabilities, | |
| cmd = { vim.fn.stdpath("data") .. "/mason/bin/elixir-ls" }, | |
| settings = { | |
| elixirLS = { | |
| -- Enable dialyzer for static analysis | |
| dialyzerEnabled = true, | |
| -- Enable formatting on save | |
| enableTestLenses = true, | |
| suggestSpecs = true, | |
| } | |
| } | |
| } | |
| -- Global LSP key mappings | |
| vim.keymap.set('n', '<space>e', vim.diagnostic.open_float) | |
| vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) | |
| vim.keymap.set('n', ']d', vim.diagnostic.goto_next) | |
| vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist) | |
| -- Use LspAttach autocommand to only map the following keys | |
| -- after the language server attaches to the current buffer | |
| vim.api.nvim_create_autocmd('LspAttach', { | |
| group = vim.api.nvim_create_augroup('UserLspConfig', {}), | |
| callback = function(ev) | |
| local opts = { buffer = ev.buf } | |
| vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) | |
| vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) | |
| vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) | |
| vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) | |
| vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts) | |
| vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts) | |
| vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts) | |
| vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) | |
| end, | |
| }) | |
| -- Telescope setup | |
| require('telescope').setup{ | |
| defaults = { | |
| -- Default configuration for telescope goes here: | |
| prompt_prefix = "🔍 ", | |
| selection_caret = "❯ ", | |
| path_display = { "truncate" }, | |
| mappings = { | |
| i = { | |
| ["<C-j>"] = "move_selection_next", | |
| ["<C-u>"] = "preview_scrolling_up", | |
| ["<C-k>"] = "move_selection_previous", | |
| ["<C-d>"] = "preview_scrolling_down", | |
| } | |
| }, | |
| file_ignore_patterns = { | |
| "node_modules", | |
| ".git", | |
| "target", | |
| "dist", | |
| "build" | |
| }, | |
| layout_config = { | |
| horizontal = { | |
| preview_width = 0.6, | |
| } | |
| } | |
| }, | |
| pickers = { | |
| find_files = { | |
| hidden = true | |
| } | |
| } | |
| } | |
| -- Load telescope-fzf-native | |
| require('telescope').load_extension('fzf') | |
| -- Add telescope keymaps | |
| vim.keymap.set('n', '<leader>ff', require('telescope.builtin').git_files, {}) | |
| vim.keymap.set('n', '<C-p>', require('telescope.builtin').git_files, {}) | |
| vim.keymap.set('n', '<leader>fF', require('telescope.builtin').find_files, {}) | |
| vim.keymap.set('n', '<leader>fg', require('telescope.builtin').live_grep, {}) | |
| vim.keymap.set('n', '<leader>fb', require('telescope.builtin').buffers, {}) | |
| vim.keymap.set('n', '<leader>fh', require('telescope.builtin').help_tags, {}) | |
| -- Nvim-tree setup | |
| require("nvim-tree").setup({ | |
| sort_by = "case_sensitive", | |
| view = { | |
| width = 30, | |
| }, | |
| renderer = { | |
| group_empty = true, | |
| icons = { | |
| show = { | |
| file = false, | |
| folder = false, | |
| folder_arrow = false, | |
| git = true, | |
| }, | |
| }, | |
| }, | |
| filters = { | |
| dotfiles = true, | |
| }, | |
| }) | |
| -- Nvim-tree keymaps | |
| vim.keymap.set('n', '<leader>e', ':NvimTreeToggle<CR>', { silent = true }) | |
| -- Add these additional Telescope keymaps | |
| vim.keymap.set('n', '<leader>fs', require('telescope.builtin').grep_string, {}) -- Find string under cursor | |
| vim.keymap.set('n', '<C-p>', require('telescope.builtin').find_files, {}) -- Common shortcut for file finding | |
| vim.keymap.set('n', '<leader>/', require('telescope.builtin').current_buffer_fuzzy_find, {}) -- Search in current buffer | |
| -- Terminal configurations | |
| vim.keymap.set('n', '<leader>t', ':botright split | terminal<CR>', { silent = true }) -- Open terminal at bottom | |
| vim.keymap.set('n', '<leader>vt', ':vsplit | terminal<CR>', { silent = true }) -- Open terminal in vertical split | |
| vim.keymap.set('t', '<Esc>', '<C-\\><C-n>') -- Exit terminal mode with Esc | |
| vim.keymap.set('t', '<C-h>', '<C-\\><C-n><C-w>h') -- Navigate left from terminal | |
| vim.keymap.set('t', '<C-j>', '<C-\\><C-n><C-w>j') -- Navigate down from terminal | |
| -- this seems to break stuff | |
| vim.keymap.set('t', '<C-k>', '<C-\\><C-n><C-w>k') -- Navigate up from terminal | |
| vim.keymap.set('t', '<C-l>', '<C-\\><C-n><C-w>l') -- Navigate right from terminal | |
| -- Auto-enter insert mode when switching to a terminal window | |
| vim.cmd([[ | |
| augroup TerminalSettings | |
| autocmd! | |
| autocmd BufEnter term://* startinsert | |
| augroup END | |
| ]]) | |
| -- Set terminal height when opened | |
| vim.api.nvim_create_autocmd("TermOpen", { | |
| pattern = "*", | |
| callback = function() | |
| -- Set the terminal height to 15 lines | |
| vim.cmd('resize 15') | |
| vim.opt_local.number = false | |
| vim.opt_local.relativenumber = false | |
| vim.opt_local.signcolumn = "no" | |
| end, | |
| }) | |
| -- Add format on save for Go files | |
| vim.api.nvim_create_autocmd("BufWritePre", { | |
| pattern = "*.go", | |
| callback = function() | |
| vim.lsp.buf.format({ async = false }) | |
| end, | |
| }) | |
| -- Add format on save for Elixir files (after your Go format on save) | |
| vim.api.nvim_create_autocmd("BufWritePre", { | |
| pattern = "*.ex,*.exs", | |
| callback = function() | |
| vim.lsp.buf.format({ async = false }) | |
| end, | |
| }) | |
| -- Add jump list keymaps | |
| vim.keymap.set('n', 'gb', '<C-o>', { noremap = true, desc = 'Jump back' }) | |
| vim.keymap.set('n', '<C-i>', '<C-i>', { noremap = true, desc = 'Jump forward' }) | |
| -- Add comment/uncomment block mappings | |
| vim.keymap.set('v', '<leader>cc', ':s/^/-- /<CR>:noh<CR>', { noremap = true, silent = true }) | |
| vim.keymap.set('v', '<leader>cu', ':s/^-- //<CR>:noh<CR>', { noremap = true, silent = true }) | |
| vim.opt.clipboard:append("unnamedplus") -- Use system clipboard | |
| vim.opt.clipboard:append("unnamed") -- Use system clipboard (macOS) | |
| vim.o.mouse = 'a' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment