aboutsummaryrefslogtreecommitdiffstats
path: root/lua/config/autocmds.lua
blob: 86d3e1de9e9730d8b1ee7cfae5c513f17ba25ab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-- resize splits if window got resized
vim.api.nvim_create_autocmd({ "VimResized" }, {
  callback = function()
    vim.cmd "tabdo wincmd ="
  end,
})

-- close some filetypes with <q>
vim.api.nvim_create_autocmd("FileType", {
  pattern = {
    "qf",
    "help",
    "man",
    "notify",
    "lspinfo",
    "spectre_panel",
    "startuptime",
    "tsplayground",
    "PlenaryTestPopup",
  },
  callback = function(event)
    vim.bo[event.buf].buflisted = false
    vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
  end,
})

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "gitcommit", "markdown", "NeogitCommitMessage", "norg" },
  callback = function()
    vim.opt_local.wrap = true
    vim.opt_local.spell = true
  end,
})

vim.api.nvim_create_autocmd({ "BufWritePre" }, {
  callback = function()
    vim.cmd [[%s/\s\+$//e]]
  end,
})

if vim.fn.has "persistent_undo" then
  local target_path = vim.fn.expand "~/.cache/undodir"
  -- crear el directorio y cualquier directorio padre
  -- si la ubicación no existe.
  if not vim.fn.isdirectory(target_path) then
    vim.fn.mkdir(target_path, "p", 0700)
  end

  vim.o.undodir = target_path
  vim.o.undofile = true
end
-- Función para alternar el ajuste de línea
function ToggleWrap()
  local wrap = vim.wo.wrap
  vim.wo.wrap = not wrap
  if vim.wo.wrap then
    print "Ajuste de línea: Habilitado"
  else
    print "Ajuste de línea: Deshabilitado"
  end
end

vim.api.nvim_create_autocmd("BufEnter", {
  pattern = "*",
  callback = function()
    if vim.opt.diff:get() then
      local wk = require "which-key"
      local opts = {
        mode = "n", -- NORMAL mode
        buffer = vim.api.nvim_get_current_buf(), -- Specify a buffer number for buffer local mappings
      }
      local mappings = {
        ["<localleader>"] = {
          --- get from REMOTE
          ["1"] = { ":diffget LOCAL<CR>", "Get LOCAL" },
          --- get from BASE
          ["2"] = { ":diffget BASE<CR>", "Get BASE" },
          --- get from LOCAL
          ["3"] = { ":diffget REMOTE<CR>", "Get REMOTE" },
        },
      }

      wk.register(mappings, opts)
    end
  end,
})