Renaming files, moving to modular config.

This commit is contained in:
juanito87 2024-04-22 21:28:19 -03:00
parent 9ef80b2ace
commit ede599bae8
No known key found for this signature in database
GPG Key ID: EAB042894FD44AFD
15 changed files with 231 additions and 53 deletions

View File

@ -93,6 +93,10 @@ vim.g.maplocalleader = ' '
-- Set to true if you have a Nerd Font installed and selected in the terminal -- Set to true if you have a Nerd Font installed and selected in the terminal
vim.g.have_nerd_font = true vim.g.have_nerd_font = true
-- [[ Global variables ]]
Autocmd = vim.api.nvim_create_autocmd
Fugitive = vim.api.nvim_create_augroup('juanito_Fugitive', {})
-- [[ Setting options ]] -- [[ Setting options ]]
require 'options' require 'options'

View File

@ -1,13 +1,11 @@
-- [[ Autocommands ]] -- [[ Autocommands ]]
-- See `:help lua-guide-autocommands` -- See `:help lua-guide-autocommands`
-- Definitions -- Definitions
local autocmd = vim.api.nvim_create_autocmd
-- local augroup = vim.api.nvim_create_augroup
-- Highlight when yanking (copying) text -- Highlight when yanking (copying) text
-- Try it with `yap` in normal mode -- Try it with `yap` in normal mode
-- See `:help vim.highlight.on_yank()` -- See `:help vim.highlight.on_yank()`
autocmd('TextYankPost', { Autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text', desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }), group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }),
callback = function() callback = function()
@ -20,7 +18,7 @@ local function augroup(name)
return vim.api.nvim_create_augroup('lazyvim_' .. name, { clear = true }) return vim.api.nvim_create_augroup('lazyvim_' .. name, { clear = true })
end end
autocmd({ 'VimResized' }, { Autocmd({ 'VimResized' }, {
group = augroup 'resize_splits', group = augroup 'resize_splits',
callback = function() callback = function()
vim.cmd 'tabdo wincmd =' vim.cmd 'tabdo wincmd ='
@ -28,7 +26,7 @@ autocmd({ 'VimResized' }, {
}) })
-- Remove auto comment next line -- Remove auto comment next line
autocmd({ 'BufEnter' }, { Autocmd({ 'BufEnter' }, {
group = augroup 'remove_auto_comment', group = augroup 'remove_auto_comment',
callback = function() callback = function()
vim.cmd 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o' vim.cmd 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'
@ -36,7 +34,7 @@ autocmd({ 'BufEnter' }, {
}) })
-- Set cursorline only in focused window -- Set cursorline only in focused window
autocmd({ 'WinEnter', 'WinLeave' }, { Autocmd({ 'WinEnter', 'WinLeave' }, {
group = augroup 'cursorline', group = augroup 'cursorline',
callback = function() callback = function()
vim.wo.cursorline = vim.fn.win_getid() == vim.fn.win_getid() vim.wo.cursorline = vim.fn.win_getid() == vim.fn.win_getid()

View File

@ -1,7 +1,4 @@
-- [[ Configure and install plugins ]] -- [[ Configure and install plugins ]]
-- Definitions
local autocmd = vim.api.nvim_create_autocmd
--
-- To check the current status of your plugins, run -- To check the current status of your plugins, run
-- :Lazy -- :Lazy
-- --
@ -13,7 +10,16 @@ local autocmd = vim.api.nvim_create_autocmd
-- NOTE: Here is where you install your plugins. -- NOTE: Here is where you install your plugins.
require('lazy').setup({ require('lazy').setup({
-- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
-- Plugins with default values
'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
-- Plugins with custom values
require 'plugins_config/vim-fugitive', -- Manage git in nvim
require 'plugins_config/which-key', -- Show created key bindings
-- require 'plugins_config/gitsigns', -- Manage git signs
'APZelos/blamer.nvim', -- Show git blame
'ThePrimeagen/git-worktree.nvim', -- Manage worktrees from nvim
'theprimeagen/harpoon', -- Improve workflow for multiple files
-- NOTE: Plugins can also be added by using a table, -- NOTE: Plugins can also be added by using a table,
-- with the first argument being the link and the following -- with the first argument being the link and the following
@ -32,18 +38,6 @@ require('lazy').setup({
-- require('gitsigns').setup({ ... }) -- require('gitsigns').setup({ ... })
-- --
-- See `:help gitsigns` to understand what the configuration keys do -- See `:help gitsigns` to understand what the configuration keys do
{ -- Adds git related signs to the gutter, as well as utilities for managing changes
'lewis6991/gitsigns.nvim',
opts = {
signs = {
add = { text = '+' },
change = { text = '~' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
},
},
},
-- NOTE: Plugins can also be configured to run Lua code when they are loaded. -- NOTE: Plugins can also be configured to run Lua code when they are loaded.
-- --
@ -60,29 +54,6 @@ require('lazy').setup({
-- after the plugin has been loaded: -- after the plugin has been loaded:
-- config = function() ... end -- config = function() ... end
{ -- Useful plugin to show you pending keybinds.
'folke/which-key.nvim',
event = 'VimEnter', -- Sets the loading event to 'VimEnter'
config = function() -- This is the function that runs, AFTER loading
require('which-key').setup()
-- Document existing key chains
require('which-key').register {
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
}
-- visual mode
require('which-key').register({
['<leader>h'] = { 'Git [H]unk' },
}, { mode = 'v' })
end,
},
-- NOTE: Plugins can specify dependencies. -- NOTE: Plugins can specify dependencies.
-- --
-- The dependencies are proper plugin specifications as well - anything -- The dependencies are proper plugin specifications as well - anything
@ -241,8 +212,8 @@ require('lazy').setup({
-- That is to say, every time a new file is opened that is associated with -- That is to say, every time a new file is opened that is associated with
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
-- function will be executed to configure the current buffer -- function will be executed to configure the current buffer
autocmd('LspAttach', { Autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }), group = Augroup('lsp-attach', { clear = true }),
callback = function(event) callback = function(event)
-- NOTE: Remember that Lua is a real programming language, and as such it is possible -- 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. -- to define small helper and utility functions so you don't have to repeat yourself.
@ -301,12 +272,12 @@ require('lazy').setup({
-- When you move your cursor, the highlights will be cleared (the second autocommand). -- When you move your cursor, the highlights will be cleared (the second autocommand).
local client = vim.lsp.get_client_by_id(event.data.client_id) local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.server_capabilities.documentHighlightProvider then if client and client.server_capabilities.documentHighlightProvider then
autocmd({ 'CursorHold', 'CursorHoldI' }, { Autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf, buffer = event.buf,
callback = vim.lsp.buf.document_highlight, callback = vim.lsp.buf.document_highlight,
}) })
autocmd({ 'CursorMoved', 'CursorMovedI' }, { Autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf, buffer = event.buf,
callback = vim.lsp.buf.clear_references, callback = vim.lsp.buf.clear_references,
}) })
@ -429,8 +400,12 @@ require('lazy').setup({
formatters_by_ft = { formatters_by_ft = {
lua = { 'stylua' }, lua = { 'stylua' },
-- Conform can also run multiple formatters sequentially -- Conform can also run multiple formatters sequentially
-- python = { "isort", "black" }, python = { 'isort', 'black' },
-- yaml = { 'yamlfix' },
go = { 'gofmt' },
rust = { 'rustfmt' },
toml = { 'taplo' },
jinja2 = { 'djlint' },
-- You can use a sub-list to tell conform to run *until* a formatter -- You can use a sub-list to tell conform to run *until* a formatter
-- is found. -- is found.
-- javascript = { { "prettierd", "prettier" } }, -- javascript = { { "prettierd", "prettier" } },

View File

@ -3,9 +3,15 @@
-- config. This will add also the recommended keymaps. -- config. This will add also the recommended keymaps.
return { return {
{
'lewis6991/gitsigns.nvim', 'lewis6991/gitsigns.nvim',
opts = { opts = {
signs = {
add = { text = '+' },
change = { text = '~' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
},
on_attach = function(bufnr) on_attach = function(bufnr)
local gitsigns = require 'gitsigns' local gitsigns = require 'gitsigns'
@ -57,5 +63,4 @@ return {
map('n', '<leader>tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) map('n', '<leader>tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' })
end, end,
}, },
},
} }

View File

@ -0,0 +1,18 @@
local mark = require 'harpoon.mark'
local ui = require 'harpoon.ui'
vim.keymap.set('n', '<leader>a', mark.add_file)
vim.keymap.set('n', '<C-e>', ui.toggle_quick_menu)
vim.keymap.set('n', '<C-u>', function()
ui.nav_file(1)
end)
vim.keymap.set('n', '<C-i>', function()
ui.nav_file(2)
end)
vim.keymap.set('n', '<C-o>', function()
ui.nav_file(3)
end)
vim.keymap.set('n', '<C-p>', function()
ui.nav_file(4)
end)

View File

@ -0,0 +1,111 @@
return { -- Fuzzy Finder (files, lsp, etc)
'nvim-telescope/telescope.nvim',
event = 'VimEnter',
branch = '0.1.x',
dependencies = {
'nvim-lua/plenary.nvim',
{ -- If encountering errors, see telescope-fzf-native README for installation instructions
'nvim-telescope/telescope-fzf-native.nvim',
-- `build` is used to run some command when the plugin is installed/updated.
-- This is only run then, not every time Neovim starts up.
build = 'make',
-- `cond` is a condition used to determine whether this plugin should be
-- installed and loaded.
cond = function()
return vim.fn.executable 'make' == 1
end,
},
{ 'nvim-telescope/telescope-ui-select.nvim' },
-- Useful for getting pretty icons, but requires a Nerd Font.
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
{ 'ThePrimeagen/git-worktree' },
},
config = function()
-- Telescope is a fuzzy finder that comes with a lot of different things that
-- it can fuzzy find! It's more than just a "file finder", it can search
-- many different aspects of Neovim, your workspace, LSP, and more!
--
-- The easiest way to use Telescope, is to start by doing something like:
-- :Telescope help_tags
--
-- After running this command, a window will open up and you're able to
-- type in the prompt window. You'll see a list of `help_tags` options and
-- a corresponding preview of the help.
--
-- Two important keymaps to use while in Telescope are:
-- - Insert mode: <c-/>
-- - Normal mode: ?
--
-- This opens a window that shows you all of the keymaps for the current
-- Telescope picker. This is really useful to discover what Telescope can
-- do as well as how to actually do it!
-- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()`
require('telescope').setup {
-- You can put your default mappings / updates / etc. in here
-- All the info you're looking for is in `:help telescope.setup()`
--
-- defaults = {
-- mappings = {
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
-- },
-- },
-- pickers = {}
extensions = {
['ui-select'] = {
require('telescope.themes').get_dropdown(),
},
},
}
-- Enable Telescope extensions if they are installed
pcall(require('telescope').load_extension, 'fzf')
pcall(require('telescope').load_extension, 'ui-select')
-- See `:help telescope.builtin`
local builtin = require 'telescope.builtin'
vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader>wm', function()
require('telescope').extensions.git_worktree.git_worktrees() -- manage worktrees on telescope
end)
vim.keymap.set('n', '<leader>wc', function()
require('telescope').extensions.git_worktree.create_git_worktree() -- create worktree
end)
-- Slightly advanced example of overriding default behavior and theme
vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to Telescope to change the theme, layout, etc.
builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
winblend = 10,
previewer = false,
})
end, { desc = '[/] Fuzzily search in current buffer' })
-- It's also possible to pass additional configuration options.
-- See `:help telescope.builtin.live_grep()` for information about particular keys
vim.keymap.set('n', '<leader>s/', function()
builtin.live_grep {
grep_open_files = true,
prompt_title = 'Live Grep in Open Files',
}
end, { desc = '[S]earch [/] in Open Files' })
-- Shortcut for searching your Neovim configuration files
vim.keymap.set('n', '<leader>sn', function()
builtin.find_files { cwd = vim.fn.stdpath 'config' }
end, { desc = '[S]earch [N]eovim files' })
end,
}

View File

@ -0,0 +1,42 @@
return {
'tpope/vim-fugitive',
-- set git status remap
vim.keymap.set('n', '<leader>gs', vim.cmd.Git, { desc = 'Start git buffer and check status' }),
vim.keymap.set('n', '<C-g>dv', ':Gvdiffsplit!<CR>', { desc = 'Diff split against HEAD vertical' }),
vim.keymap.set('n', '<C-g>dh', ':Gdiffsplit!<CR>', { desc = 'Diff split against HEAD horizontal' }),
vim.keymap.set('n', '<C-g>dt', ':windo diffthis<CR>', { desc = 'Diff files in all windows' }),
vim.keymap.set('n', '<C-g>dm', ':Gdiff!<CR>', { desc = 'On conflicted file opens a 3-way diff' }),
vim.keymap.set('n', '<C-g>2', ':diffget //2 | diffupdate<CR>', { desc = 'On the middle file get the diff from Head' }),
vim.keymap.set('n', '<C-g>3', ':diffget //3 | diffupdate<CR>', { desc = 'On the middle file get the diff from the other branch' }),
vim.keymap.set('n', '<C-g>do', ':diffo!<CR>', { desc = 'Turn off diff mode' }),
--
Autocmd('BufWinEnter', {
group = Fugitive,
pattern = '*',
callback = function()
if vim.bo.ft ~= 'fugitive' then
return
end
local bufnr = vim.api.nvim_get_current_buf()
local opts = { buffer = bufnr, remap = false }
vim.keymap.set('n', '<leader>gc', function()
vim.cmd.Git 'commit'
end)
vim.keymap.set('n', '<leader>p', function()
vim.cmd.Git 'push'
end, opts)
-- rebase always
vim.keymap.set('n', '<leader>P', function()
vim.cmd.Git { 'pull', '--rebase' }
end, opts)
-- NOTE: It allows me to easily set the branch i am pushing and any tracking
-- needed if i did not set the branch up correctly
vim.keymap.set('n', '<leader>t', ':Git push -u origin ', opts)
end,
}),
}

View File

@ -0,0 +1,22 @@
return { -- Useful plugin to show you pending keybinds.
'folke/which-key.nvim',
event = 'VimEnter', -- Sets the loading event to 'VimEnter'
config = function() -- This is the function that runs, AFTER loading
require('which-key').setup()
-- Document existing key chains
require('which-key').register {
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
}
-- visual mode
require('which-key').register({
['<leader>h'] = { 'Git [H]unk' },
}, { mode = 'v' })
end,
}

View File

@ -0,0 +1,3 @@
require('git-worktree').setup {
change_directory_command = 'tcd', -- command to change directory (e.g. lcd for NvimTree)
}