aboutsummaryrefslogtreecommitdiff
path: root/base/.config/vis/visrc.lua
blob: b8f0bf3aa946455847787307bcced113708fc44d (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
87
-- Port de ~/.vimrc (+ auto.vim y maps.vim) a vis.
require('vis')

-------------
-- GENERAL --
-------------
-- LSP (vis-lspc). Se carga ANTES de los mapeos propios: el plugin también
-- mapea ' e' (diagnósticos) y el último en registrarse gana.
local lspc = require('plugins/vis-lspc')
lspc.menu_cmd = 'fzf'           -- menú de completado/referencias con fzf

-- Solo estos lenguajes: clangd, gopls, lua-language-server y zls.
local servers = {c = true, ansi_c = true, cpp = true, go = true, lua = true, zig = true}
for syntax in pairs(lspc.ls_map) do
    if not servers[syntax] then lspc.ls_map[syntax] = nil end
end

-- "Leader" = espacio: vis no tiene leader, se mapea la secuencia entera.
local n = vis.modes.NORMAL

-- Guardar y salir
vis:map(n, ' w', ':w<Enter>', 'Guardar')
vis:map(n, ' q', ':q<Enter>', 'Salir')
vis:map(n, ' s', ':vsplit<Enter>', 'Split vertical')

-- Moverse entre ventanas (vis no puede redimensionarlas)
vis:map(n, ' j', '<vis-window-prev>', 'Ventana anterior')
vis:map(n, ' k', '<vis-window-next>', 'Ventana siguiente')

-- Abrir fichero con fzf (equivale a :Files de vim). vis no expande $(...)
-- en sus comandos, así que se ejecuta fzf con vis:pipe y se abre el resultado.
vis:map(n, ' p', function()
    local status, out = vis:pipe(
        "find . -path '*/.git' -prune -o -type f -print | fzf --prompt='Files> '")
    out = out and out:gsub('\n$', '')
    if status == 0 and out and out ~= '' then
        vis:command("e '" .. out:gsub("'", "'\\''") .. "'")
    end
    vis:redraw()
end, 'Buscar ficheros con fzf')

-- Abrir fichero con yazi como selector. yazi dibuja en la terminal, no en
-- stdout (que captura vis:pipe), así que se fuerza /dev/tty y el resultado
-- se lee del fichero que escribe --chooser-file.
vis:map(n, ' e', function()
    local chooser = os.tmpname()
    vis:pipe("yazi --chooser-file='" .. chooser .. "' </dev/tty >/dev/tty")
    local f = io.open(chooser)
    local path = f and f:read('*l')
    if f then f:close() end
    os.remove(chooser)
    if path and path ~= '' then
        vis:command("e '" .. path:gsub("'", "'\\''") .. "'")
    end
    vis:redraw()
end, 'Elegir fichero con yazi')

-- ' e' es de yazi, así que los diagnósticos pasan a ' d'
vis:map(n, ' d', ':lspc-show-diagnostics<Enter>', 'Diagnóstico de la línea')

-- Completar llave: { -> {}
vis:map(vis.modes.INSERT, '{', function()
    local win = vis.win
    local pos = win.selection.pos
    win.file:insert(pos, '{}')
    win.selection.pos = pos + 1
end, 'Autocompletar {}')

vis.events.subscribe(vis.events.WIN_OPEN, function(win)
    vis:command('set numbers')
    vis:command('set relativenumbers')
    vis:command('set tabwidth 4')      -- tabstop/shiftwidth
    vis:command('set expandtab')
    vis:command('set autoindent')
    vis:command('set cursorline')
    -- set list
    vis:command('set showtabs')
    vis:command('set showspaces')
    vis:command('set shownewlines')

    -- Tema generado por cwal (apply-theme); opcional hasta que exista.
    local theme = io.open(os.getenv('HOME') .. '/.config/vis/themes/cwal.lua')
    if theme then
        theme:close()
        vis:command('set theme cwal')
    end
end)