Files
dotfiles/neovim/.config/nvim/init.lua

204 lines
5.0 KiB
Lua

-- Abbreviations
local opt = vim.opt
local map = vim.keymap.set
local cmd = vim.cmd
-- [[ OPTIONS ]] --
-- Line numbers
opt.number = true
opt.relativenumber = true
-- Block cursor
opt.guicursor = ""
-- Hightlight cursor line
opt.cursorline = true
-- File options
opt.undofile = true
opt.undodir = os.getenv("HOME") .. "/.vim/nvim_undodir"
opt.swapfile = false
opt.backup = false
opt.fixendofline = false
-- Tabs
opt.tabstop = 4
opt.softtabstop = 4
opt.shiftwidth = 4
opt.expandtab = true
opt.breakindent = true
-- Search
opt.ignorecase = true
opt.smartcase = true
opt.incsearch = true
map("n", "<ESC>", "<cmd>nohlsearch<CR>")
-- Columns
opt.signcolumn = "yes"
-- opt.textwidth = 78 -- RFC 5322
opt.colorcolumn = "79"
-- Auto complete
opt.completeopt = { "menuone", "popup" --[[, "noselect" ]] }
-- Window border
opt.winborder = "rounded"
-- [[ KEYMAPS ]] --
-- Leader key
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Clipboard
map({ "n", "v" }, "<leader>y", "\"+y")
-- Deletions
map({ "n", "v" }, "<leader>d", "\"_d")
map("n", "<leader>md", ":delmarks!<CR>")
-- Commands
map("n", "<leader>x", ":!chmod +x %<CR>")
map("n", "<leader>cd", ":cd %:h | pwd<CR>")
-- Tabs
map("n", "<leader>tt", ":tabnew<CR>")
map("n", "<leader>tw", ":tabclose<CR>")
map("n", "<leader>tn", ":tabnext<CR>")
map("n", "<leader>tp", ":tabprevious<CR>")
map("n", "<leader>tf", ":tabfirst<CR>")
map("n", "<leader>tl", ":tablast<CR>")
-- Buffers
map("n", "<leader>n", ":enew<CR>")
map("n", "<leader>db", ":bdelete<CR>")
map("n", "<TAB>", ":bnext<CR>")
map("n", "<S-TAB>", ":bprevious<CR>")
map("n", "<leader>\\", ":buffer term<CR>")
map("t", "<ESC>", "<C-\\><C-n>")
-- Indentation in visual mode
map("v", "<", "<gv")
map("v", ">", ">gv")
-- Move text in visual mode
map("v", "J", ":move '>+1<CR>gv=gv")
map("v", "K", ":move '<-2<CR>gv=gv")
-- Run last command in terminal
map("n", "<leader>r", ":buffer term<CR>i<Up><CR><C-\\><C-n>")
-- Window movement
map("n", "<M-h>", "<C-w>h")
map("n", "<M-j>", "<C-w>j")
map("n", "<M-k>", "<C-w>k")
map("n", "<M-l>", "<C-w>l")
map("t", "<M-h>", "<cmd>wincmd h<CR>")
map("t", "<M-j>", "<cmd>wincmd j<CR>")
map("t", "<M-k>", "<cmd>wincmd k<CR>")
map("t", "<M-l>", "<cmd>wincmd l<CR>")
-- Window resizing
map("n", "<M-Up>", "<cmd>resize -2<CR>")
map("n", "<M-Down>", "<cmd>resize +2<CR>")
map("n", "<M-Left>", "<cmd>vertical resize -2<CR>")
map("n", "<M-Right>", "<cmd>vertical resize +2<CR>")
-- Listchars
opt.listchars = {
-- eol = "$",
tab = "» ",
space = "·",
trail = "-"
}
-- Toggle listchars
map("n", "<leader>lc", function()
vim.wo.list = not vim.wo.list
end)
-- [[ PLUGINS ]] --
vim.pack.add({
-- Colorscheme
"https://github.com/blazkowolf/gruber-darker.nvim",
-- Background trasparency
"https://github.com/xiyaowong/transparent.nvim",
-- Fuzzy finder
"https://github.com/echasnovski/mini.pick",
-- Advanced undo tree
"https://github.com/mbbill/undotree",
-- Git integration
"https://github.com/tpope/vim-fugitive",
"https://github.com/lewis6991/gitsigns.nvim",
-- Text aligning
{ src = "https://github.com/Vonr/align.nvim", version = "v2" },
-- Multi cursor
"https://github.com/brenton-leighton/multiple-cursors.nvim",
-- Trailing whitespace
"https://github.com/kaplanz/retrail.nvim",
-- Indent blankline
"https://github.com/lukas-reineke/indent-blankline.nvim",
-- File tree
{ src = "https://github.com/nvim-neo-tree/neo-tree.nvim", version = vim.version.range("3") },
"https://github.com/nvim-lua/plenary.nvim",
"https://github.com/MunifTanjim/nui.nvim",
"https://github.com/nvim-tree/nvim-web-devicons"
})
-- Load plugins
cmd.colorscheme("gruber-darker")
require("mini.pick").setup()
require("multiple-cursors").setup()
require("retrail").setup({
hlgroup = "Error",
trim = {
auto = false, -- Auto trim on BufWritePre
}
})
require("ibl").setup()
require("neo-tree").setup({
window = {
width = 32
}
})
-- Plugin keymaps
map("n", "<leader>f", ":Pick files<CR>")
map("n", "<leader>b", ":Pick buffers<CR>")
map("n", "<leader>u", ":UndotreeToggle<CR>")
map("n", "<leader>gs", ":Git<CR>")
map("n", "<leader>gt", ":Gitsigns toggle_signs<CR>")
map("n", "<leader>gp", ":Gitsigns preview_hunk<CR>")
map("n", "<leader>gb", ":Gitsigns toggle_current_line_blame<CR>")
map("x", "<leader>al", function()
require("align").align_to_string({ preview = true, regex = true })
end)
map({ "n", "x" }, "<C-j>", "<cmd>MultipleCursorsAddDown<CR>")
map({ "n", "x" }, "<C-k>", "<cmd>MultipleCursorsAddUp<CR>")
map({ "n", "i", "x" }, "<C-Up>", "<cmd>MultipleCursorsAddUp<CR>")
map({ "n", "i", "x" }, "<C-Down>", "<cmd>MultipleCursorsAddDown<CR>")
map({ "n", "i" }, "<C-LeftMouse>", "<cmd>MultipleCursorsMouseAddDelete<CR>")
map({ "n", "v", "x" }, "<C-l>", "<cmd>MultipleCursorsAddJumpNextMatch<CR>")
map({ "n", "x" }, "<leader>D", "<cmd>MultipleCursorsJumpNextMatch<CR>")
map("n", "<leader>|", function()
require("multiple-cursors").align()
end)
map("n", "<leader>p", "<cmd>Neotree toggle<CR>")