Refactoring

This commit is contained in:
Ian Roddis
2026-05-06 12:20:14 -03:00
parent d96c6f7ebd
commit 25cf1e91e8
13 changed files with 305 additions and 587 deletions
+1 -421
View File
@@ -1,430 +1,10 @@
-- [[ NOTE: ]] Must happen before plugins are required (otherwise wrong leader will be used) require 'iroddis'
vim.g.mapleader = ','
vim.g.maplocalleader = ','
-- [[ Install `lazy.nvim` plugin manager ]]
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', -- latest stable release
lazypath,
}
end
vim.opt.rtp:prepend(lazypath)
-- [[ Configure plugins ]]
require('lazy').setup({
-- Git related plugins
'junegunn/vim-easy-align', -- Nice alignment
'jpalardy/vim-slime', -- Send text from buffer to a tmux pane
'neovim/nvim-lspconfig', -- LSP
'stevearc/conform.nvim', -- Autoformatting
'tanvirtin/monokai.nvim', -- Theme
'lewis6991/gitsigns.nvim', -- Nice git annotations
'nvim-treesitter/nvim-treesitter',
{ 'nvim-mini/mini.nvim', version = '*' },
-- Fuzzy Finder (files, lsp, etc)
{
'nvim-telescope/telescope.nvim',
version = '*',
dependencies = {
'nvim-lua/plenary.nvim',
-- optional but recommended
{ 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' },
},
},
-- Marks management
{
'chentoast/marks.nvim',
event = 'VeryLazy',
opts = {
builtin_marks = { '<', '>', '{', '}' },
},
},
}, {})
local servers = {}
for _, dir in ipairs(vim.api.nvim_get_runtime_file('lsp', true)) do
for name, type in vim.fs.dir(dir) do
if (type == 'file' or type == 'link') and name:sub(-4) == '.lua' then
servers[name:sub(1, -5)] = true -- dedupe across runtimepath entries
end
end
end
vim.lsp.enable(vim.tbl_keys(servers))
-- [[ Setting options ]]
-- vim.opt.autocomplete = true -- Autoindent
vim.opt.autocomplete = true
vim.opt.ai = true -- Autoindent
vim.opt.updatetime = 50
vim.opt.mouse = ''
vim.opt.ttimeoutlen = 1000
vim.opt.ttimeout = true
-- vim.opt.ttimeoutlen = 0 -- Leader timeout (default 50)
-- Whitespace
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
-- Search
vim.opt.ignorecase = true
vim.opt.incsearch = true
vim.opt.hlsearch = false
vim.opt.smartcase = true
-- Display
vim.opt.nu = true
vim.opt.wrap = false
vim.opt.termguicolors = false
vim.opt.scrolloff = 8
vim.opt.signcolumn = 'yes'
vim.opt.foldlevel = 99
vim.opt.foldmethod = 'expr'
vim.opt.wildmode = 'longest:full'
-- swap
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = os.getenv 'HOME' .. '/tmp/vim.undo'
vim.opt.undofile = true
-- Sync clipboard between OS and Neovim.
-- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
-- vim.o.clipboard = 'unnamedplus'
-- Enable break indent
vim.o.breakindent = true
-- Keep signcolumn on by default
vim.wo.signcolumn = 'yes'
-- Decrease update time
vim.o.updatetime = 250
vim.o.timeoutlen = 300
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'
-- NOTE: You should make sure your terminal supports this
vim.o.termguicolors = true
-- [[ Basic Keymaps ]]
-- Keymaps for better default experience
-- See `:help vim.keymap.set()`
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
vim.keymap.set('n', '<leader>,', ':w!<CR>')
vim.keymap.set('n', 'qq', ':qa!<CR>')
vim.keymap.set('n', "<leader>'", vim.cmd.tabn)
vim.keymap.set('n', '<leader>;', vim.cmd.tabp)
vim.keymap.set('n', '<C-e>', ':tabe ')
vim.keymap.set('n', '<C-j>', vim.diagnostic.goto_next)
vim.keymap.set('n', '<C-k>', vim.diagnostic.goto_prev)
vim.keymap.set('n', '<leader>r', ':%s/\\s*$//<CR>')
-- Moving code!!
-- vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")
-- vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")
-- vim.keymap.set('x', '<leader>o', '"_dP')
-- System copy/paste
vim.keymap.set('n', '<leader>y', '"+y')
vim.keymap.set('v', '<leader>y', '"+y')
vim.keymap.set('n', '<leader>y', '"+Y')
vim.keymap.set('n', '<leader>Y', ':.w! ~/.vimpaste<CR>')
vim.keymap.set('v', '<leader>Y', ':w! ~/.vimpaste<CR>')
vim.keymap.set('n', '<leader>P', ':r ~/.vimpaste<CR>')
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'markdown' },
callback = function(_)
vim.keymap.set('n', '<leader>f', '{!}fmt -p 150<CR>')
vim.keymap.set('v', '<leader>f', ':!fmt -p 150<CR>')
end,
})
require('monokai').setup { palette = require('monokai').ristretto } require('monokai').setup { palette = require('monokai').ristretto }
-- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()`
require('telescope').setup {
defaults = {
mappings = {
i = {
['<C-u>'] = false,
['<C-d>'] = false,
},
},
},
}
require('mini.snippets').setup {}
require('mini.keymap').setup {}
require('mini.icons').setup {}
require('mini.completion').setup {}
-- Enable telescope fzf native, if installed
pcall(require('telescope').load_extension, 'fzf')
-- Formatting
require('conform').setup {
formatters_by_ft = {
elixir = { 'mix' },
heex = { 'mix' },
go = { 'gofmt' },
javascript = { 'prettier' },
lua = { 'stylua' },
python = { 'black' },
rust = { 'rustfmt', lsp_format = 'fallback' },
cpp = { 'clang-format' },
},
format_on_save = {
-- These options will be passed to conform.format()
timeout_ms = 500,
lsp_format = 'fallback',
},
}
-- Telescope live_grep in git root
-- Function to find the git root directory based on the current buffer's path
local function find_git_root()
-- Use the current buffer's path as the starting point for the git search
local current_file = vim.api.nvim_buf_get_name(0)
local current_dir
local cwd = vim.fn.getcwd()
-- If the buffer is not associated with a file, return nil
if current_file == '' then
current_dir = cwd
else
-- Extract the directory from the current file's path
current_dir = vim.fn.fnamemodify(current_file, ':h')
end
-- Find the Git root directory from the current file's path
local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1]
if vim.v.shell_error ~= 0 then
print 'Not a git repository. Searching on current working directory'
return cwd
end
return git_root
end
-- Custom live_grep function to search in git root
local function live_grep_git_root()
local git_root = find_git_root()
if git_root then
require('telescope.builtin').live_grep {
search_dirs = { git_root },
}
end
end
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
-- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to telescope to change theme, layout, etc.
require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
winblend = 10,
previewer = false,
})
end, { desc = '[/] Fuzzily search in current buffer' })
local function telescope_live_grep_open_files()
require('telescope.builtin').live_grep {
grep_open_files = true,
prompt_title = 'Live Grep in Open Files',
}
end
vim.keymap.set('n', '<leader>s/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' })
vim.keymap.set('n', '<leader>ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' })
vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' })
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' })
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr)
-- NOTE: Remember that lua is a real programming language, and as such it is possible
-- to define small helper and utility functions so you don't have to repeat yourself
-- many times.
--
-- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time.
local nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
end
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nmap('<leader>ca', function()
vim.lsp.buf.code_action { context = { only = { 'quickfix', 'refactor', 'source' } } }
end, '[C]ode [A]ction')
nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
nmap('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' })
end
vim.g.slime_target = 'tmux'
vim.keymap.set('n', '<Space>', '<Plug>SlimeLineSend<CR>')
vim.keymap.set('v', '<Space>', "<Plug>SlimeRegionSend<CR>'>")
vim.keymap.set('n', '<leader>v', ':SlimeConfig<CR><CR>')
vim.api.nvim_create_autocmd('FileType', {
pattern = 'python',
callback = function()
vim.g.slime_python_ipython = 1
end,
})
-- vim.api.nvim_create_autocmd('FileType', {
-- pattern = '*',
-- callback = function()
-- vim.treesitter.start()
-- end,
-- })
vim.api.nvim_create_autocmd('FileType', {
group = vim.api.nvim_create_augroup('tree-sitter-enable', { clear = true }),
callback = function(args)
local lang = vim.treesitter.language.get_lang(args.match)
if not lang or not vim.treesitter.language.add(lang) then
return
end
if vim.treesitter.query.get(lang, 'highlights') then
vim.treesitter.start(args.buf)
end
if vim.treesitter.query.get(lang, 'indents') then
vim.opt_local.indentexpr = 'v:lua.require("nvim-treesitter").indentexpr()'
end
if vim.treesitter.query.get(lang, 'folds') then
vim.opt_local.foldmethod = 'expr'
vim.opt_local.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
end
end,
})
vim.keymap.set('n', 'ga', ':EasyAlign<CR>') vim.keymap.set('n', 'ga', ':EasyAlign<CR>')
vim.keymap.set('v', 'ga', ':EasyAlign<CR>') vim.keymap.set('v', 'ga', ':EasyAlign<CR>')
local builtin = require 'telescope.builtin'
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<C-p>', builtin.git_files, {})
vim.keymap.set('n', '<leader>ps', function()
builtin.grep_string { search = vim.fn.input 'Grep > ' }
end)
-- Define a function to highlight the current search term
local highlight_search_term = function(label)
local search_term = vim.fn.getreg '/'
if search_term ~= '' then
-- local matches =
vim.fn.matchadd(label, search_term)
-- for match_id in matches do
-- vim.api.nvim_buf_add_highlight(0, -1, label, 0, match_id[1] - 1, match_id[2])
-- end
end
end
vim.keymap.set('n', '<leader>m1', function()
highlight_search_term 'Matchadd_1'
end)
vim.keymap.set('n', '<leader>m2', function()
highlight_search_term 'Matchadd_2'
end)
vim.keymap.set('n', '<leader>m3', function()
highlight_search_term 'Matchadd_3'
end)
vim.keymap.set('n', '<leader>m4', function()
highlight_search_term 'Matchadd_4'
end)
vim.keymap.set('n', '<leader>m5', function()
highlight_search_term 'Matchadd_5'
end)
vim.keymap.set('n', '<leader>mc', function()
vim.fn.clearmatches()
end)
local colors = {
base03 = '#002b36',
base02 = '#073642',
base01 = '#586e75',
base00 = '#657b83',
base0 = '#839496',
base1 = '#93a1a1',
base2 = '#eee8d5',
base3 = '#fdf6e3',
yellow = '#b58900',
orange = '#cb4b16',
red = '#dc322f',
magenta = '#d33682',
violet = '#6c71c4',
blue = '#268bd2',
cyan = '#2aa198',
green = '#859900',
}
vim.api.nvim_set_hl(0, 'Matchadd_1', { bg = colors.blue, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_2', { bg = colors.violet, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_3', { bg = colors.cyan, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_4', { bg = colors.red, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_5', { bg = colors.orange, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_6', { bg = colors.yellow, fg = 0 })
-- Because nvim filetypes are stupid ... need to disable formatoptions for all file types -- Because nvim filetypes are stupid ... need to disable formatoptions for all file types
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = '*', pattern = '*',
-5
View File
@@ -1,5 +0,0 @@
-- You can add your own plugins here or in other files in this directory!
-- I promise not to create any merge conflicts in this directory :)
--
-- See the kickstart.nvim README for more information
return {}
+19
View File
@@ -0,0 +1,19 @@
-- Formatting
require('conform').setup {
formatters_by_ft = {
elixir = { 'mix' },
heex = { 'mix' },
go = { 'gofmt' },
javascript = { 'prettier' },
lua = { 'stylua' },
python = { 'black' },
rust = { 'rustfmt', lsp_format = 'fallback' },
cpp = { 'clang-format' },
},
format_on_save = {
-- These options will be passed to conform.format()
timeout_ms = 500,
lsp_format = 'fallback',
},
}
+10
View File
@@ -0,0 +1,10 @@
vim.g.slime_target = 'tmux'
vim.keymap.set('n', '<Space>', '<Plug>SlimeLineSend<CR>')
vim.keymap.set('v', '<Space>', "<Plug>SlimeRegionSend<CR>'>")
vim.keymap.set('n', '<leader>v', ':SlimeConfig<CR><CR>')
vim.api.nvim_create_autocmd('FileType', {
pattern = 'python',
callback = function()
vim.g.slime_python_ipython = 1
end,
})
+17
View File
@@ -0,0 +1,17 @@
require('telescope').setup {
defaults = {
mappings = {
i = {
['<C-u>'] = false,
['<C-d>'] = false,
},
},
},
}
pcall(require('telescope').load_extension, 'fzf')
vim.api.nvim_create_autocmd('FileType', {
pattern = '*',
callback = function()
vim.keymap.set('n', 'gd', require('telescope.builtin').lsp_definitions, { buffer = bufnr, desc = '[G]oto [D]efinition' })
end,
})
+56
View File
@@ -0,0 +1,56 @@
-- Define a function to highlight the current search term
local highlight_search_term = function(label)
local search_term = vim.fn.getreg '/'
if search_term ~= '' then
-- local matches =
vim.fn.matchadd(label, search_term)
-- for match_id in matches do
-- vim.api.nvim_buf_add_highlight(0, -1, label, 0, match_id[1] - 1, match_id[2])
-- end
end
end
vim.keymap.set('n', '<leader>m1', function()
highlight_search_term 'Matchadd_1'
end)
vim.keymap.set('n', '<leader>m2', function()
highlight_search_term 'Matchadd_2'
end)
vim.keymap.set('n', '<leader>m3', function()
highlight_search_term 'Matchadd_3'
end)
vim.keymap.set('n', '<leader>m4', function()
highlight_search_term 'Matchadd_4'
end)
vim.keymap.set('n', '<leader>m5', function()
highlight_search_term 'Matchadd_5'
end)
vim.keymap.set('n', '<leader>mc', function()
vim.fn.clearmatches()
end)
local colors = {
base03 = '#002b36',
base02 = '#073642',
base01 = '#586e75',
base00 = '#657b83',
base0 = '#839496',
base1 = '#93a1a1',
base2 = '#eee8d5',
base3 = '#fdf6e3',
yellow = '#b58900',
orange = '#cb4b16',
red = '#dc322f',
magenta = '#d33682',
violet = '#6c71c4',
blue = '#268bd2',
cyan = '#2aa198',
green = '#859900',
}
vim.api.nvim_set_hl(0, 'Matchadd_1', { bg = colors.blue, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_2', { bg = colors.violet, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_3', { bg = colors.cyan, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_4', { bg = colors.red, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_5', { bg = colors.orange, fg = 0 })
vim.api.nvim_set_hl(0, 'Matchadd_6', { bg = colors.yellow, fg = 0 })
+10
View File
@@ -0,0 +1,10 @@
-- require("iroddis.remaps")
-- require("iroddis.packer")
require 'iroddis.set'
require 'iroddis.lazy'
require 'iroddis.lsp'
require 'iroddis.cmatches'
require 'iroddis.cfg_conform'
require 'iroddis.cfg_slime'
require 'iroddis.cfg_telescope'
+48
View File
@@ -0,0 +1,48 @@
-- [[ Install `lazy.nvim` plugin manager ]]
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', -- latest stable release
lazypath,
}
end
vim.opt.rtp:prepend(lazypath)
-- require 'custom'
-- [[ Configure plugins ]]
require('lazy').setup({
-- Git related plugins
'junegunn/vim-easy-align', -- Nice alignment
'jpalardy/vim-slime', -- Send text from buffer to a tmux pane
'neovim/nvim-lspconfig', -- LSP
'stevearc/conform.nvim', -- Autoformatting
'tanvirtin/monokai.nvim', -- Theme
'lewis6991/gitsigns.nvim', -- Nice git annotations
'nvim-treesitter/nvim-treesitter',
-- { 'nvim-mini/mini.nvim', version = '*' },
{ 'nvim-mini/mini.nvim', version = '*' },
-- Fuzzy Finder (files, lsp, etc)
{
'nvim-telescope/telescope.nvim',
version = '*',
dependencies = {
'nvim-lua/plenary.nvim',
-- optional but recommended
{ 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' },
},
},
-- Marks management
{
'chentoast/marks.nvim',
event = 'VeryLazy',
opts = {
builtin_marks = { '<', '>', '{', '}' },
},
},
}, {})
+44
View File
@@ -0,0 +1,44 @@
local servers = {}
for _, dir in ipairs(vim.api.nvim_get_runtime_file('lsp', true)) do
for name, type in vim.fs.dir(dir) do
if (type == 'file' or type == 'link') and name:sub(-4) == '.lua' then
servers[name:sub(1, -5)] = true -- dedupe across runtimepath entries
end
end
end
vim.lsp.enable({
'ansiblels',
'arduino_language_server',
'asm_lsp',
'ast_grep',
'awk_ls',
'bashls',
'clangd',
'cmake',
'cssls',
'css_variables',
'ctags_lsp',
'elixirls',
'eslint',
'fish_lsp',
'gleam',
'golangci_lint_ls',
'gopls',
'graphql',
'html',
'htmx',
'janet_lsp',
'jsonls',
'julials',
'just',
'lua_ls',
'nginx_language_server',
'ruff',
'rust_analyzer',
'systemd_lsp',
'tailwindcss',
'ty',
'vimls',
'ziggy'
})
+35
View File
@@ -0,0 +1,35 @@
-- Keymaps for better default experience
-- See `:help vim.keymap.set()`
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
vim.keymap.set('n', '<leader>,', ':w!<CR>')
vim.keymap.set('n', 'qq', ':qa!<CR>')
vim.keymap.set('n', "<leader>'", vim.cmd.tabn)
vim.keymap.set('n', '<leader>;', vim.cmd.tabp)
vim.keymap.set('n', '<C-e>', ':tabe ')
vim.keymap.set('n', '<C-j>', vim.diagnostic.goto_next)
vim.keymap.set('n', '<C-k>', vim.diagnostic.goto_prev)
vim.keymap.set('n', '<leader>r', ':%s/\\s*$//<CR>')
-- Moving code!!
-- vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")
-- vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")
-- vim.keymap.set('x', '<leader>o', '"_dP')
-- System copy/paste
vim.keymap.set('n', '<leader>y', '"+y')
vim.keymap.set('v', '<leader>y', '"+y')
vim.keymap.set('n', '<leader>y', '"+Y')
vim.keymap.set('n', '<leader>Y', ':.w! ~/.vimpaste<CR>')
vim.keymap.set('v', '<leader>Y', ':w! ~/.vimpaste<CR>')
vim.keymap.set('n', '<leader>P', ':r ~/.vimpaste<CR>')
+65
View File
@@ -0,0 +1,65 @@
-- [[ NOTE: ]] Must happen before plugins are required (otherwise wrong leader will be used)
vim.g.mapleader = ','
vim.g.maplocalleader = ','
vim.opt.autocomplete = true
vim.opt.ai = true -- Autoindent
vim.opt.updatetime = 50
vim.opt.mouse = ''
vim.opt.ttimeoutlen = 1000
vim.opt.ttimeout = true
-- vim.opt.ttimeoutlen = 0 -- Leader timeout (default 50)
-- Whitespace
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
-- Search
vim.opt.ignorecase = true
vim.opt.incsearch = true
vim.opt.hlsearch = false
vim.opt.smartcase = true
-- Display
vim.opt.nu = true
vim.opt.wrap = false
vim.opt.termguicolors = false
vim.opt.scrolloff = 8
vim.opt.signcolumn = 'yes'
vim.opt.foldlevel = 99
vim.opt.foldmethod = 'expr'
vim.opt.wildmode = 'longest:full'
-- swap
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = os.getenv 'HOME' .. '/tmp/vim.undo'
vim.opt.undofile = true
-- Sync clipboard between OS and Neovim.
-- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
-- vim.o.clipboard = 'unnamedplus'
vim.o.breakindent = true
vim.wo.signcolumn = 'yes'
vim.o.updatetime = 250
vim.o.timeoutlen = 300
vim.o.completeopt = 'menuone,noselect'
vim.o.termguicolors = true
-- Because nvim filetypes are stupid ... need to disable formatoptions for all file types
vim.api.nvim_create_autocmd('FileType', {
pattern = '*',
callback = function()
vim.opt.formatoptions:remove 'r'
vim.opt.formatoptions:remove 'o'
end,
})
-- Disable change-detection if in diff mode. Allows for diffs involving redirects
-- eg nvim -d <(cmd 1) <(cmd 2)
if vim.diff then
vim.opt.autoread = false
end
-74
View File
@@ -1,74 +0,0 @@
-- autoformat.lua
--
-- Use your language server to automatically format your code on save.
-- Adds additional commands as well to manage the behavior
return {
'neovim/nvim-lspconfig',
config = function()
-- Switch for controlling whether you want autoformatting.
-- Use :KickstartFormatToggle to toggle autoformatting on or off
local format_is_enabled = true
vim.api.nvim_create_user_command('KickstartFormatToggle', function()
format_is_enabled = not format_is_enabled
print('Setting autoformatting to: ' .. tostring(format_is_enabled))
end, {})
-- Create an augroup that is used for managing our formatting autocmds.
-- We need one augroup per client to make sure that multiple clients
-- can attach to the same buffer without interfering with each other.
local _augroups = {}
local get_augroup = function(client)
if not _augroups[client.id] then
local group_name = 'kickstart-lsp-format-' .. client.name
local id = vim.api.nvim_create_augroup(group_name, { clear = true })
_augroups[client.id] = id
end
return _augroups[client.id]
end
-- Whenever an LSP attaches to a buffer, we will run this function.
--
-- See `:help LspAttach` for more information about this autocmd event.
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }),
-- This is where we attach the autoformatting for reasonable clients
callback = function(args)
local client_id = args.data.client_id
local client = vim.lsp.get_client_by_id(client_id)
local bufnr = args.buf
-- Only attach to clients that support document formatting
if not client.server_capabilities.documentFormattingProvider then
return
end
-- Tsserver usually works poorly. Sorry you work with bad languages
-- You can remove this line if you know what you're doing :)
if client.name == 'tsserver' then
return
end
-- Create an autocmd that will run *before* we save the buffer.
-- Run the formatting command for the LSP that has just attached.
vim.api.nvim_create_autocmd('BufWritePre', {
group = get_augroup(client),
buffer = bufnr,
callback = function()
if not format_is_enabled then
return
end
vim.lsp.buf.format {
async = false,
filter = function(c)
return c.id == client.id
end,
}
end,
})
end,
})
end,
}
-87
View File
@@ -1,87 +0,0 @@
-- debug.lua
--
-- Shows how to use the DAP plugin to debug your code.
--
-- Primarily focused on configuring the debugger for Go, but can
-- be extended to other languages as well. That's why it's called
-- kickstart.nvim and not kitchen-sink.nvim ;)
return {
-- NOTE: Yes, you can install new plugins here!
'mfussenegger/nvim-dap',
-- NOTE: And you can specify dependencies as well
dependencies = {
-- Creates a beautiful debugger UI
'rcarriga/nvim-dap-ui',
-- Installs the debug adapters for you
'williamboman/mason.nvim',
'jay-babu/mason-nvim-dap.nvim',
-- Add your own debuggers here
'leoluz/nvim-dap-go',
},
config = function()
local dap = require 'dap'
local dapui = require 'dapui'
require('mason-nvim-dap').setup {
-- Makes a best effort to setup the various debuggers with
-- reasonable debug configurations
automatic_setup = true,
-- You can provide additional configuration to the handlers,
-- see mason-nvim-dap README for more information
handlers = {},
-- You'll need to check that you have the required things installed
-- online, please don't ask me how to install them :)
ensure_installed = {
-- Update this to ensure that you have the debuggers for the langs you want
'delve',
},
}
-- Basic debugging keymaps, feel free to change to your liking!
vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug: Start/Continue' })
vim.keymap.set('n', '<F1>', dap.step_into, { desc = 'Debug: Step Into' })
vim.keymap.set('n', '<F2>', dap.step_over, { desc = 'Debug: Step Over' })
vim.keymap.set('n', '<F3>', dap.step_out, { desc = 'Debug: Step Out' })
vim.keymap.set('n', '<leader>b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
vim.keymap.set('n', '<leader>B', function()
dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
end, { desc = 'Debug: Set Breakpoint' })
-- Dap UI setup
-- For more information, see |:help nvim-dap-ui|
dapui.setup {
-- Set icons to characters that are more likely to work in every terminal.
-- Feel free to remove or use ones that you like more! :)
-- Don't feel like these are good choices.
icons = { expanded = '', collapsed = '', current_frame = '*' },
controls = {
icons = {
pause = '',
play = '',
step_into = '',
step_over = '',
step_out = '',
step_back = 'b',
run_last = '▶▶',
terminate = '',
disconnect = '',
},
},
}
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
vim.keymap.set('n', '<F7>', dapui.toggle, { desc = 'Debug: See last session result.' })
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
dap.listeners.before.event_terminated['dapui_config'] = dapui.close
dap.listeners.before.event_exited['dapui_config'] = dapui.close
-- Install golang specific config
require('dap-go').setup()
end,
}