124 lines
3.7 KiB
Lua
124 lines
3.7 KiB
Lua
-- Bootstrap lazy.nvim
|
|
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
|
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
|
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
|
|
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
|
|
if vim.v.shell_error ~= 0 then
|
|
vim.api.nvim_echo({
|
|
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
|
|
{ out, "WarningMsg" },
|
|
{ "\nPress any key to exit..." },
|
|
}, true, {})
|
|
vim.fn.getchar()
|
|
os.exit(1)
|
|
end
|
|
end
|
|
vim.opt.rtp:prepend(lazypath)
|
|
|
|
-- Make sure to setup `mapleader` and `maplocalleader` before
|
|
-- loading setting manual mappings or loading lazy.nvim
|
|
vim.g.mapleader = " "
|
|
vim.g.maplocalleader = "\\"
|
|
|
|
-- no highlights after search
|
|
vim.opt.hlsearch = false
|
|
vim.opt.ignorecase = true -- ignore casing in searches...
|
|
vim.opt.smartcase = true -- ...unless I provide both caps and lowercase
|
|
|
|
-- allow arrow keys and h/l to move to the next/prev line when at the edge
|
|
vim.opt.whichwrap:append("<,>,h,l")
|
|
|
|
-- display non-printing character
|
|
vim.opt.listchars = 'tab:┆-,trail:~,extends:>,precedes:<,nbsp:•'
|
|
vim.opt.list = true
|
|
|
|
-- highlight line with cursor
|
|
vim.opt.cursorline = true
|
|
|
|
-- spaces, not tab
|
|
vim.opt.expandtab = true
|
|
vim.opt.tabstop = 2
|
|
vim.opt.shiftwidth = 2
|
|
vim.opt.softtabstop = 2
|
|
|
|
-- all my code is in git anyways, and these files are cluttery
|
|
vim.opt.backup = false
|
|
vim.opt.writebackup = false
|
|
vim.opt.swapfile = false
|
|
|
|
-- new splits open to the right or below the current window
|
|
vim.opt.splitbelow = true
|
|
vim.opt.splitright = true
|
|
|
|
function tblmerge(x, y)
|
|
for k, v in pairs(y) do x[k] = v end
|
|
return x
|
|
end
|
|
|
|
local function map(mode, lhs, rhs, opts)
|
|
vim.api.nvim_set_keymap(mode, lhs, rhs,
|
|
tblmerge({ noremap = true, silent = true }, opts or {}))
|
|
end
|
|
function nmap(l, r, opt) map('n', l, r, opt) end
|
|
|
|
function imap(l, r, opt) map('i', l, r, opt) end
|
|
|
|
function vmap(l, r, opt) map('v', l, r, opt) end
|
|
|
|
-- Treat long lines as broken lines so you can move in them
|
|
nmap('j', 'gj')
|
|
nmap('k', 'gk')
|
|
|
|
-- maintain visual selection when changing indentation
|
|
vmap('<', '<gv')
|
|
vmap('>', '>gv')
|
|
|
|
-- handy save
|
|
nmap("<Leader>w", ":w<CR>")
|
|
|
|
-- handy escape
|
|
imap('jk', '<Esc>')
|
|
|
|
-- tab handling
|
|
nmap("<Leader>tn", ":tabnew<CR>")
|
|
nmap('<Tab>', '<C-W>w')
|
|
nmap('<S-Tab>', '<C-W>W')
|
|
nmap('<Leader>te', ':tabedit <c-r>=expand("%:p:h")<cr>/<cr>')
|
|
|
|
-- Kill trailing whitespace
|
|
function Whitespace()
|
|
local save = vim.fn.winsaveview()
|
|
vim.cmd [[keeppatterns %s/\s\+$//e]]
|
|
vim.cmd [[keeppatterns %s/\r$//e]]
|
|
vim.fn.winrestview(save)
|
|
end
|
|
|
|
nmap('<leader>kw', ':lua Whitespace()<cr>')
|
|
|
|
-- C-; inserts current date in ISO8601 format, à la Excel
|
|
-- Requires configuring the terminal to send the correct sequence; ref
|
|
-- http://www.leonerd.org.uk/hacks/fixterms/. The correct sequence, in general, is `CSI
|
|
-- codepoint;modifier u`, where CSI is 'Esc-[', _codepoint_ is the decimal unicode
|
|
-- value (here, 59), and _modifier_ is chosen from
|
|
-- None Shift Alt A+S Ctrl C+S C+A C+A+
|
|
-- 1 2 3 4 5 6 7 8
|
|
-- For alacritty, e.g., the keybinding to configure i
|
|
-- - { key: Semicolon, mods: Control, chars: "\x1b[59;5u" }
|
|
imap('<C-;>', '<C-R>=strftime("%F")<CR>')
|
|
|
|
-- this fnamemodify invocations turns the absolute path from expand('%') into a path
|
|
-- relative to nvim's launch directory
|
|
nmap('<leader>l', ':let @+=fnamemodify(expand("%"), ":~:.") . ":" . line(".")<CR>')
|
|
|
|
-- Setup lazy.nvim
|
|
require("lazy").setup({
|
|
spec = {
|
|
{ import = "plugins" },
|
|
},
|
|
install = { colorscheme = { "habamax" } },
|
|
checker = { enabled = false },
|
|
})
|
|
|
|
-- set cursorline highlight to an underline. Has to happen after lazy setup, since
|
|
-- loading the colorscheme will overwrite any custom highlights.
|
|
vim.api.nvim_set_hl(0, 'CursorLine', { underline = true })
|