Skip to content

Instantly share code, notes, and snippets.

@netmute
Last active December 5, 2024 09:47
Show Gist options
  • Save netmute/3c810e94492448bcc28f6061f2cf0304 to your computer and use it in GitHub Desktop.
Save netmute/3c810e94492448bcc28f6061f2cf0304 to your computer and use it in GitHub Desktop.
Neovim config
-- Disable unused providers
vim.g.loaded_python3_provider = 0
vim.g.loaded_ruby_provider = 0
vim.g.loaded_node_provider = 0
vim.g.loaded_perl_provider = 0
-- Keymap leader keys
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Editor settings
vim.opt.breakindent = true -- Preserve indentation for wrapped lines
vim.opt.ignorecase = true -- Case insensitive search...
vim.opt.inccommand = "split" -- Preview substitutions in split
vim.opt.laststatus = 0 -- Hide statusline
vim.opt.linebreak = true -- Break lines without cutting words
vim.opt.number = true -- Display line numbers
vim.opt.ruler = false -- Disable ruler
vim.opt.scrolloff = 10 -- Keep 10 lines above/below cursor
vim.opt.shiftwidth = 4 -- Indent by 4 spaces
vim.opt.signcolumn = "yes" -- Always display signcolumn
vim.opt.smartcase = true -- ...unless search has capitals
vim.opt.splitbelow = true -- Open horizontal splits below
vim.opt.splitright = true -- Open vertical splits to the right
vim.opt.swapfile = false -- Disable swapfile
vim.opt.tabstop = 4 -- Set tab width to 4 spaces
vim.opt.title = true -- Let vim control the window title
vim.opt.undofile = true -- Persist undo history
-- Plugins
vim.opt.rtp:prepend("~/.local/share/nvim/lazy/lazy.nvim")
require("lazy").setup({
-- Colorscheme
{ "miikanissi/modus-themes.nvim", lazy = false },
-- Dependencies, we'll just put them here in case someone needs them
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
-- Treesitter
{
"nvim-treesitter/nvim-treesitter",
dependencies = {
"nvim-treesitter/nvim-treesitter-textobjects",
"nvim-treesitter/nvim-treesitter-context",
"RRethy/nvim-treesitter-endwise",
},
event = "BufReadPost",
build = ":TSUpdate",
main = "nvim-treesitter.configs",
opts = {
auto_install = true,
highlight = { enable = true },
endwise = { enable = true },
matchup = { enable = true },
textobjects = {
select = {
enable = true,
keymaps = {
["af"] = "@function.outer",
["if"] = "@function.inner",
["aa"] = "@parameter.outer",
["ia"] = "@parameter.inner",
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]f"] = "@function.outer",
},
goto_previous_start = {
["[f"] = "@function.outer",
},
},
},
},
},
-- Fzf
{
"ibhagwan/fzf-lua",
keys = {
{ "<Leader>t", "<cmd>FzfLua files<cr>" },
{ "<Leader>g", "<cmd>FzfLua grep<cr>" },
{ "<Leader>r", "<cmd>FzfLua oldfiles<cr>" },
{ "<Leader>s", "<cmd>FzfLua grep_cword<cr>" },
{ "<Leader>S", "<cmd>FzfLua grep_cWORD<cr>" },
{ "<Leader>d", "<cmd>FzfLua diagnostics_document<cr>" },
{
"<Leader>]",
function()
local fzf = require("fzf-lua")
if next(vim.lsp.get_active_clients({ bufnr = 0 })) then
fzf.lsp_document_symbols()
else
fzf.treesitter()
end
end,
},
},
cmd = "FzfLua",
opts = {
winopts = { border = false, preview = { hidden = "hidden" } },
oldfiles = { cwd_only = true },
},
},
-- File tree
{
"nvim-neo-tree/neo-tree.nvim",
cmd = "Neotree",
keys = {
{ "<Leader>p", "<cmd>Neotree float buffers<cr>" },
},
lazy = vim.fn.isdirectory(vim.fn.argv(0)) ~= 1,
opts = {
filesystem = {
follow_current_file = { enabled = true },
window = { position = "float" },
},
},
},
-- LSP
{
"neovim/nvim-lspconfig",
dependencies = { "netmute/ctags-lsp.nvim", dev = true },
ft = { "lua", "go", "ruby" },
config = function()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup({})
lspconfig.gopls.setup({})
lspconfig.ctags_lsp.setup({
-- cmd = { "/usr/local/bin/ctags-lsp" }, -- Just for development
filetypes = { "ruby" },
})
vim.keymap.set("n", "gr", vim.lsp.buf.rename)
end,
},
-- Autocomplete
{
"saghen/blink.cmp",
event = "BufReadPost",
build = "nix shell github:nix-community/fenix/monthly#minimal.toolchain -c cargo build --release",
opts = {
keymap = {
preset = "super-tab",
["<C-j>"] = { "select_next", "fallback" },
["<C-k>"] = { "select_prev", "fallback" },
},
appearance = { use_nvim_cmp_as_default = true },
},
},
-- Formatting
{
"stevearc/conform.nvim",
event = "BufWritePre",
keys = {
{
"<leader>f",
function()
require("conform").format({ async = true, lsp_format = "fallback" })
end,
},
},
opts = {
formatters_by_ft = {
lua = { "stylua" },
json = { "jq" },
sh = { "shfmt" },
go = { "goimports" },
fish = { "fish_indent" },
markdown = { "markdownfmt" },
},
format_on_save = { timeout_ms = 500 },
},
},
-- Improve native search and replace
{
"roobert/search-replace.nvim",
keys = {
{ "gr", "<cmd>SearchReplaceSingleBufferCWord<cr>" },
{ "gr", "<cmd>SearchReplaceSingleBufferVisualSelection<cr>", mode = "v" },
},
opts = {},
},
-- Show git changes in signcolumn
{
"lewis6991/gitsigns.nvim",
event = "BufReadPost",
keys = {
{ "]c", "<cmd>Gitsigns next_hunk<cr>" },
{ "[c", "<cmd>Gitsigns prev_hunk<cr>" },
},
opts = {},
},
-- Auto pairs
{ "windwp/nvim-autopairs", event = "InsertEnter", opts = {} },
-- Auto-detect indentation settings
{ "Darazaki/indent-o-matic", event = "BufReadPost", opts = {} },
-- Pair matching
{ "andymass/vim-matchup", event = "BufReadPost" },
-- Surround text
{ "kylechui/nvim-surround", event = "BufReadPost", opts = {} },
-- Remember last cursor position
{ "vladdoster/remember.nvim", event = "BufReadPost", opts = {} },
-- Extra filetype support
{
"fladson/vim-kitty",
ft = "kitty",
config = function()
vim.api.nvim_create_autocmd("BufWritePost", {
-- Reload kitty.conf on save
pattern = "kitty.conf",
command = "silent !killall -SIGUSR1 kitty",
})
end,
},
{ "khaveesh/vim-fish-syntax", ft = "fish" },
}, {
defaults = { lazy = true },
install = { colorscheme = { "modus_operandi" } },
performance = {
rtp = {
disabled_plugins = {
"editorconfig",
"gzip",
"man",
"matchit",
"matchparen",
"netrwPlugin",
"osc52",
"rplugin",
"spellfile",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
})
-- Disable mappings
vim.keymap.set("n", "<ScrollWheelLeft>", "<nop>")
vim.keymap.set("n", "<ScrollWheelRight>", "<nop>")
vim.keymap.set("n", "q:", "<nop>")
-- Key mappings
vim.keymap.set({ "n", "x", "o" }, "gy", '"+y')
vim.keymap.set({ "n", "x", "o" }, "gp", '"+p')
vim.keymap.set("n", "<Esc>", "<cmd>nohlsearch<CR>")
vim.keymap.set("n", "<Tab>", "<C-^>")
vim.api.nvim_set_keymap("n", "<Leader>,", ":e $MYVIMRC<CR>", { silent = true })
vim.api.nvim_set_keymap("n", "<Leader>c", "mmyyP`m", {})
vim.api.nvim_set_keymap("n", "<Leader>z", "mmyyPgcc`m", {})
vim.cmd("command Qa qa") -- Jeez, you know what I meant
-- Colorscheme
vim.cmd.colorscheme("modus_operandi")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment