178 lines
6.2 KiB
Lua
178 lines
6.2 KiB
Lua
-- options ---------------------------------------------------------------------
|
|
-- colorscheme
|
|
vim.cmd.colorscheme("basic")
|
|
|
|
-- leader
|
|
vim.g.mapleader = " "
|
|
vim.g.maplocalleader = " "
|
|
vim.keymap.set({ "n", "v" }, "<space>", "<nop>", { silent = true })
|
|
|
|
-- general
|
|
vim.opt.undofile = true
|
|
vim.opt.backup = false
|
|
vim.opt.writebackup = false
|
|
vim.opt.mouse = {}
|
|
vim.opt.title = true
|
|
|
|
-- appearance
|
|
vim.opt.shortmess:append({ I = true })
|
|
vim.opt.number = true
|
|
vim.opt.relativenumber = true
|
|
vim.opt.signcolumn = "number"
|
|
vim.opt.textwidth = 80
|
|
vim.opt.colorcolumn = "+1"
|
|
|
|
-- tabline, winbar, statusline
|
|
vim.opt.showtabline = 2
|
|
vim.opt.winbar = "%f%( %h%m%r%y%)"
|
|
vim.opt.laststatus = 3
|
|
function _G.statusline()
|
|
local col = vim.api.nvim_win_get_cursor(0)[2] + 1
|
|
local char = vim.api.nvim_get_current_line():sub(col, col):gsub("%%", "%%%1")
|
|
local wc = vim.fn.wordcount()
|
|
return table.concat({
|
|
vim.fn.pathshorten(vim.fn.getcwd()),
|
|
"%=",
|
|
"<", char, "> %b ",
|
|
wc.visual_chars or wc.cursor_chars, "/", wc.chars, " ",
|
|
wc.visual_words or wc.cursor_words, "/", wc.words
|
|
})
|
|
end
|
|
vim.opt.statusline = "%!v:lua.statusline()"
|
|
|
|
-- behaviour
|
|
vim.opt.ignorecase = true
|
|
vim.opt.infercase = true
|
|
vim.opt.smartcase = true
|
|
vim.opt.smartindent = true
|
|
vim.opt.clipboard = "unnamedplus"
|
|
vim.opt.whichwrap = {
|
|
["b"] = true,
|
|
["s"] = true,
|
|
["h"] = true,
|
|
["l"] = true,
|
|
["<"] = true,
|
|
[">"] = true,
|
|
["~"] = true,
|
|
["["] = true,
|
|
["]"] = true
|
|
}
|
|
vim.opt.wildoptions = { "fuzzy" }
|
|
vim.opt.wildignorecase = true
|
|
|
|
-- path
|
|
vim.opt.path = ".,,**"
|
|
-- local root = vim.fs.find({ ".git" }, { upward = true })[1]
|
|
|
|
-- completion
|
|
vim.opt.completeopt = {
|
|
"menuone",
|
|
"preview",
|
|
"noinsert",
|
|
"noselect"
|
|
}
|
|
|
|
-- keymaps ---------------------------------------------------------------------
|
|
-- clear hlsearch
|
|
vim.keymap.set( "n", "<esc>", function()
|
|
vim.cmd.nohlsearch()
|
|
end, { desc = "Stop the highlighting for the 'hlsearch' option" })
|
|
|
|
-- move cursor with alt in c-mode
|
|
vim.keymap.set("c", "<m-h>", "<left>", { desc = "Left" })
|
|
vim.keymap.set("c", "<m-l>", "<right>", { desc = "Right" })
|
|
|
|
-- move cursor with alt in i-mode
|
|
vim.keymap.set("i", "<m-h>", "<left>", { desc = "Left" })
|
|
vim.keymap.set("i", "<m-j>", "<down>", { desc = "Down" })
|
|
vim.keymap.set("i", "<m-k>", "<up>", { desc = "Up" })
|
|
vim.keymap.set("i", "<m-l>", "<right>", { desc = "Right" })
|
|
|
|
-- move cursor with alt in t-mode
|
|
vim.keymap.set("t", "<m-h>", "<left>", { desc = "Left" })
|
|
vim.keymap.set("t", "<m-j>", "<down>", { desc = "Down" })
|
|
vim.keymap.set("t", "<m-k>", "<up>", { desc = "Up" })
|
|
vim.keymap.set("t", "<m-l>", "<right>", { desc = "Right" })
|
|
|
|
-- navigate windows
|
|
vim.keymap.set("n", "<c-h>", "<c-w>h", { desc = "Navigate window left"})
|
|
vim.keymap.set("n", "<c-j>", "<c-w>j", { desc = "Navigate window down"})
|
|
vim.keymap.set("n", "<c-k>", "<c-w>k", { desc = "Navigate window up"})
|
|
vim.keymap.set("n", "<c-l>", "<c-w>l", { desc = "Navigate window right"})
|
|
vim.keymap.set("i", "<c-h>", "<c-\\><c-n><c-w>h", { desc = "Navigate window left"})
|
|
vim.keymap.set("i", "<c-j>", "<c-\\><c-n><c-w>j", { desc = "Navigate window down"})
|
|
vim.keymap.set("i", "<c-k>", "<c-\\><c-n><c-w>k", { desc = "Navigate window up"})
|
|
vim.keymap.set("i", "<c-l>", "<c-\\><c-n><c-w>l", { desc = "Navigate window right"})
|
|
vim.keymap.set("t", "<c-h>", "<c-\\><c-n><c-w>h", { desc = "Navigate window left"})
|
|
vim.keymap.set("t", "<c-j>", "<c-\\><c-n><c-w>j", { desc = "Navigate window down"})
|
|
vim.keymap.set("t", "<c-k>", "<c-\\><c-n><c-w>k", { desc = "Navigate window up"})
|
|
vim.keymap.set("t", "<c-l>", "<c-\\><c-n><c-w>l", { desc = "Navigate window right"})
|
|
|
|
-- navigate buffer
|
|
vim.keymap.set("n", "<c-d>", "<c-d>zz")
|
|
vim.keymap.set("n", "<c-u>", "<c-u>zz")
|
|
|
|
-- cmdline history navigation
|
|
vim.keymap.set("c", "<c-p>", "<up>")
|
|
vim.keymap.set("c", "<c-n>", "<down>")
|
|
|
|
-- menus
|
|
vim.keymap.set("n", "<leader>f", ":find ", { desc = ":find" })
|
|
vim.keymap.set("n", "<leader>b", ":buffer ", { desc = ":buffer" })
|
|
vim.keymap.set("n", "<leader>h", ":help ", { desc = ":help" })
|
|
|
|
-- spell
|
|
vim.keymap.set("n", "<leader>s", function()
|
|
vim.opt_local.spell = not(vim.opt_local.spell:get())
|
|
end, { desc = "Toggle spell" })
|
|
|
|
-- make
|
|
vim.keymap.set("n", "<leader>m", "<cmd>make<cr>", { desc = ":make" })
|
|
|
|
-- buffers ---------------------------------------------------------------------
|
|
vim.keymap.set("n", "]b", "<cmd>bnext<cr>", { desc = "Next buffer" })
|
|
vim.keymap.set("n", "[b", "<cmd>bprev<cr>", { desc = "Previous buffer" })
|
|
vim.keymap.set("n", "<leader>d", "<cmd>enew<cr><cmd>bd #<cr>", { desc = "Delete buffer" })
|
|
vim.keymap.set("n", "<leader>D", "<cmd>bd<cr>", { desc = "Delete buffer and close window" })
|
|
|
|
-- tabs ------------------------------------------------------------------------
|
|
vim.keymap.set("n", "]t", "<cmd>tabnext<cr>", { desc = "Next tab" })
|
|
vim.keymap.set("n", "[t", "<cmd>tabprevious<cr>", { desc = "Previous tab" })
|
|
|
|
-- vimgrep ---------------------------------------------------------------------
|
|
vim.keymap.set("n", "<leader>g", ":vimgrep / **/*<c-left><c-left>/")
|
|
|
|
local vimgrep_group = vim.api.nvim_create_augroup("Vimgrep", {})
|
|
vim.api.nvim_create_autocmd("QuickfixCmdPost", {
|
|
group = vimgrep_group,
|
|
pattern = "vimgrep",
|
|
desc = "Open quickfix window after :vimgrep",
|
|
command = "copen"
|
|
})
|
|
|
|
-- quickfix --------------------------------------------------------------------
|
|
vim.keymap.set("n", "co", "<cmd>copen<cr>", { desc = "Open quickfix window" })
|
|
vim.keymap.set("n", "cc", "<cmd>cclose<cr>", { desc = "Close quickfix window" })
|
|
vim.keymap.set("n", "]q", "<cmd>cnext<cr>zz", { desc = "Next quickfix item" })
|
|
vim.keymap.set("n", "[q", "<cmd>cprev<cr>zz", { desc = "Previous quickfix item" })
|
|
|
|
-- netrw -----------------------------------------------------------------------
|
|
vim.g.netrw_use_errorwindow = 0
|
|
vim.g.netrw_banner = 0
|
|
vim.g.netrw_bufsettings = "noma nomod nowrap ro nobl"
|
|
vim.g.netrw_fastbrowse = 0
|
|
|
|
vim.keymap.set("n", "<leader>.", "<cmd>Explore .<cr>",
|
|
{ desc = "Explore current working directory" })
|
|
|
|
local netrw_group = vim.api.nvim_create_augroup("Netrw", {})
|
|
vim.api.nvim_create_autocmd("Filetype", {
|
|
group = netrw_group,
|
|
pattern = "netrw",
|
|
desc = "Set keymap netrw buffers",
|
|
callback = function()
|
|
vim.keymap.set("n", "<esc>", "<cmd>Rexplore<cr>",
|
|
{ buffer = true, desc = "Return to/from Explorer" })
|
|
end
|
|
})
|