add `nvim` config
parent
b87c36a1f3
commit
10e72f2b02
|
@ -0,0 +1,7 @@
|
|||
-- options ---------------------------------------------------------------------
|
||||
vim.opt.tabstop = 2
|
||||
vim.opt.shiftwidth = 2
|
||||
vim.opt.expandtab = true
|
||||
|
||||
-- treesitter ------------------------------------------------------------------
|
||||
-- vim.treesitter.start()
|
|
@ -0,0 +1,7 @@
|
|||
-- options ---------------------------------------------------------------------
|
||||
vim.opt.joinspaces = true
|
||||
vim.opt.formatoptions:append("p")
|
||||
vim.bo.tabstop = 2
|
||||
vim.bo.shiftwidth = 2
|
||||
vim.bo.expandtab = true
|
||||
vim.bo.textwidth = 72
|
|
@ -0,0 +1,317 @@
|
|||
-- basic neovim colorscheme template
|
||||
--
|
||||
-- A simple neovim colorscheme template that defines highlight groups
|
||||
-- from a list of 8 colors.
|
||||
|
||||
-- colors ----------------------------------------------------------------------
|
||||
local C = {
|
||||
{ 0, "#292526" }, -- black
|
||||
{ 1, "#ff404f" }, -- red
|
||||
{ 2, "#00a147" }, -- green
|
||||
{ 3, "#e06e00" }, -- orange
|
||||
{ 4, "#6185ff" }, -- blue
|
||||
{ 5, "#ff3e8b" }, -- magenta
|
||||
{ 6, "#0095d7" }, -- cyan
|
||||
{ 7, "#e3e0e1" }, -- white
|
||||
{ 8, "#958a8d" }, -- black
|
||||
{ 9, "#ffb3b6" }, -- red
|
||||
{ 10, "#00e46a" }, -- green
|
||||
{ 11, "#ffb598" }, -- orange
|
||||
{ 12, "#b8c3ff" }, -- blue
|
||||
{ 13, "#ffb1c5" }, -- magenta
|
||||
{ 14, "#92ccff" }, -- cyan
|
||||
{ 15, "#f4f3f3" }, -- white
|
||||
}
|
||||
|
||||
local black_c = C[1]
|
||||
local red_c = C[2]
|
||||
local green_c = C[3]
|
||||
local orange_c = C[4]
|
||||
local blue_c = C[5]
|
||||
local magenta_c = C[6]
|
||||
local cyan_c = C[7]
|
||||
local white_c = C[8]
|
||||
|
||||
-- init ------------------------------------------------------------------------
|
||||
-- vim.cmd.highlight("clear")
|
||||
vim.cmd("highlight clear")
|
||||
if vim.fn.exists("syntax_on") then
|
||||
-- vim.cmd.syntax("reset")
|
||||
vim.cmd("syntax reset")
|
||||
end
|
||||
vim.opt.background = "dark"
|
||||
vim.g.colors_name = "basic"
|
||||
|
||||
if
|
||||
vim.env.TERM == "linux" or
|
||||
vim.env.TERM == "screen" or
|
||||
vim.env.TERM == "screen.linux"
|
||||
then
|
||||
vim.opt.termguicolors = false
|
||||
else
|
||||
vim.opt.termguicolors = true
|
||||
end
|
||||
|
||||
local tty = vim.env.TERM == "linux" or vim.env.TERM == "screen.linux"
|
||||
|
||||
for _, v in ipairs(C) do
|
||||
local key = ("terminal_color_%i"):format(v[1])
|
||||
vim.g[key] = v[2]
|
||||
end
|
||||
|
||||
-- highlights ------------------------------------------------------------------
|
||||
local H = {}
|
||||
|
||||
function H:new(o)
|
||||
o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function H:fg(c)
|
||||
self.ctermfg = c[1]
|
||||
self.fg = c[2]
|
||||
if c[1] == 4 and tty then
|
||||
self.bold = true
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
function H:bg(c)
|
||||
self.ctermbg = c[1]
|
||||
self.bg = c[2]
|
||||
if c[1] == 4 and tty then
|
||||
self.bold = true
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
function H:attr(a)
|
||||
if tty then
|
||||
if a == "underline" then return self end
|
||||
end
|
||||
self[a] = true
|
||||
return self
|
||||
end
|
||||
|
||||
local fg_c = white_c
|
||||
local bg_c = black_c
|
||||
local accent_c = magenta_c
|
||||
local dimmed_c = blue_c
|
||||
|
||||
local function set_hl(group, def) vim.api.nvim_set_hl(0, group, def) end
|
||||
|
||||
-- normal ----------------------------------------------------------------------
|
||||
local normal_h = {}
|
||||
|
||||
set_hl("Normal", normal_h)
|
||||
set_hl("NormalNC", normal_h)
|
||||
|
||||
-- tui -------------------------------------------------------------------------
|
||||
local tui_normal_h = {}
|
||||
local tui_accent_h = H:new():fg(accent_c)
|
||||
local tui_dimmed_h = H:new():fg(dimmed_c)
|
||||
|
||||
set_hl("StatusLine", tui_accent_h)
|
||||
set_hl("StatusLineNC", tui_dimmed_h)
|
||||
set_hl("TabLine", tui_dimmed_h)
|
||||
set_hl("TabLineFill", tui_dimmed_h)
|
||||
set_hl("TabLineSel", tui_accent_h)
|
||||
set_hl("WinBar", tui_accent_h)
|
||||
set_hl("WinBarNC", tui_dimmed_h)
|
||||
set_hl("WinSeparator", tui_dimmed_h)
|
||||
set_hl("LineNr", tui_dimmed_h)
|
||||
set_hl("LineNrAbove", tui_dimmed_h)
|
||||
set_hl("LineNrBelow", tui_dimmed_h)
|
||||
set_hl("SignColumn", tui_dimmed_h)
|
||||
set_hl("FoldColumn", tui_dimmed_h)
|
||||
|
||||
-- float -----------------------------------------------------------------------
|
||||
local float_normal_h = H:new():fg(bg_c):bg(fg_c)
|
||||
local float_accent_h = H:new():fg(accent_c):bg(fg_c)
|
||||
|
||||
set_hl("NormalFloat", float_normal_h)
|
||||
set_hl("FloatBorder", float_normal_h)
|
||||
set_hl("FloatTitle", float_accent_h)
|
||||
|
||||
-- menu ------------------------------------------------------------------------
|
||||
local menu_normal_h = H:new():fg(bg_c):bg(fg_c)
|
||||
local menu_accent_h = H:new():fg(accent_c):bg(fg_c)
|
||||
local menu_accent_r_h = H:new():fg(accent_c):bg(fg_c):attr("reverse")
|
||||
|
||||
set_hl("Pmenu", menu_normal_h)
|
||||
set_hl("PmenuSel", menu_accent_h)
|
||||
set_hl("PmenuKind", menu_normal_h)
|
||||
set_hl("PmenuKindSel", menu_accent_h)
|
||||
set_hl("PmenuExtra", menu_normal_h)
|
||||
set_hl("PmenuExtraSel", menu_accent_h)
|
||||
set_hl("PmenuSbar", menu_accent_h)
|
||||
set_hl("PmenuThumb", menu_accent_r_h)
|
||||
set_hl("WildMenu", menu_accent_h)
|
||||
|
||||
-- messages --------------------------------------------------------------------
|
||||
local message_normal_h = {}
|
||||
local message_accent_h = H:new():fg(accent_c)
|
||||
local message_error_h = H:new():fg(red_c)
|
||||
local message_warn_h = H:new():fg(orange_c)
|
||||
|
||||
set_hl("MsgArea", message_normal_h)
|
||||
set_hl("MsgSeparator", message_normal_h)
|
||||
set_hl("ModeMsg", message_accent_h)
|
||||
set_hl("MoreMsg", message_accent_h)
|
||||
set_hl("WarningMsg", message_warn_h)
|
||||
set_hl("ErrorMsg", message_error_h)
|
||||
set_hl("Question", message_accent_h)
|
||||
set_hl("Title", message_accent_h)
|
||||
|
||||
-- buffer ----------------------------------------------------------------------
|
||||
local buffer_normal_h = H:new():fg(dimmed_c)
|
||||
local buffer_normal_bg_h = H:new():bg(dimmed_c)
|
||||
local buffer_accent_h = H:new():fg(accent_c)
|
||||
|
||||
set_hl("Conceal", buffer_normal_h)
|
||||
set_hl("NonText", buffer_normal_h)
|
||||
set_hl("EndOfBuffer", buffer_normal_h)
|
||||
set_hl("Whitespace", buffer_normal_h)
|
||||
set_hl("Folded", buffer_normal_h)
|
||||
set_hl("SpecialKey", buffer_accent_h)
|
||||
set_hl("ColorColumn", buffer_normal_bg_h)
|
||||
|
||||
-- cursor ----------------------------------------------------------------------
|
||||
local cursor_normal_h = H:new():attr("reverse")
|
||||
|
||||
set_hl("CursorLine", cursor_normal_h)
|
||||
set_hl("CursorLineNr", cursor_normal_h)
|
||||
set_hl("CursorLineSign", cursor_normal_h)
|
||||
set_hl("CursorLineFold", cursor_normal_h)
|
||||
set_hl("CursorColumn", cursor_normal_h)
|
||||
set_hl("QuickFixLine", cursor_normal_h)
|
||||
set_hl("Cursor", cursor_normal_h)
|
||||
set_hl("lCursor", cursor_normal_h)
|
||||
set_hl("CursorIM", cursor_normal_h)
|
||||
set_hl("TermCursor", cursor_normal_h)
|
||||
set_hl("TermCursorNC", cursor_normal_h)
|
||||
|
||||
-- match -----------------------------------------------------------------------
|
||||
local match_normal_h = H:new():fg(orange_c)
|
||||
local match_current_h = H:new():fg(orange_c):attr("reverse")
|
||||
|
||||
set_hl("Search", match_normal_h)
|
||||
set_hl("Substitute", match_normal_h)
|
||||
set_hl("IncSearch", match_current_h)
|
||||
set_hl("CurSearch", match_current_h)
|
||||
set_hl("MatchParen", match_normal_h)
|
||||
|
||||
-- selection -------------------------------------------------------------------
|
||||
local selection_normal_h = H:new():fg(magenta_c):attr("reverse")
|
||||
|
||||
set_hl("visual", selection_normal_h)
|
||||
set_hl("visualnos", selection_normal_h)
|
||||
|
||||
-- diff ------------------------------------------------------------------------
|
||||
local diff_add_h = H:new():fg(green_c)
|
||||
local diff_change_h = H:new():fg(orange_c)
|
||||
local diff_delete_h = H:new():fg(red_c)
|
||||
local diff_text_h = H:new():fg(orange_c):attr("underline")
|
||||
|
||||
set_hl("DiffAdd", diff_add_h)
|
||||
set_hl("DiffChange", diff_change_h)
|
||||
set_hl("DiffDelete", diff_delete_h)
|
||||
set_hl("DiffText", diff_text_h)
|
||||
|
||||
-- spell -----------------------------------------------------------------------
|
||||
local spell_error_h = H:new():fg(red_c):attr("underline")
|
||||
local spell_warn_h = H:new():fg(orange_c):attr("underline")
|
||||
|
||||
set_hl("SpellBad", spell_error_h)
|
||||
set_hl("SpellCap", spell_warn_h)
|
||||
set_hl("SpellLocal", spell_warn_h)
|
||||
set_hl("SpellRare", spell_warn_h)
|
||||
|
||||
-- diagnostic ------------------------------------------------------------------
|
||||
local diagnostic_error_h = H:new():fg(red_c)
|
||||
local diagnostic_warn_h = H:new():fg(orange_c)
|
||||
local diagnostic_info_h = H:new():fg(blue_c)
|
||||
local diagnostic_hint_h = H:new():fg(white_c)
|
||||
local diagnostic_ok_h = H:new():fg(green_c)
|
||||
local diagnostic_error_u_h = H:new():fg(red_c):attr("underline")
|
||||
local diagnostic_warn_u_h = H:new():fg(orange_c):attr("underline")
|
||||
local diagnostic_info_u_h = H:new():fg(blue_c):attr("underline")
|
||||
local diagnostic_hint_u_h = H:new():fg(white_c):attr("underline")
|
||||
local diagnostic_ok_u_h = H:new():fg(green_c):attr("underline")
|
||||
|
||||
set_hl("DiagnosticError", diagnostic_error_h)
|
||||
set_hl("DiagnosticWarn", diagnostic_warn_h)
|
||||
set_hl("DiagnosticInfo", diagnostic_info_h)
|
||||
set_hl("DiagnosticHint", diagnostic_hint_h)
|
||||
set_hl("DiagnosticOk", diagnostic_ok_h)
|
||||
set_hl("DiagnosticVirtualError", diagnostic_error_h)
|
||||
set_hl("DiagnosticVirtualWarn", diagnostic_warn_h)
|
||||
set_hl("DiagnosticVirtualInfo", diagnostic_info_h)
|
||||
set_hl("DiagnosticVirtualHint", diagnostic_hint_h)
|
||||
set_hl("DiagnosticVirtualOk", diagnostic_ok_h)
|
||||
set_hl("DiagnosticUnderlineError", diagnostic_error_u_h)
|
||||
set_hl("DiagnosticUnderlineWarn", diagnostic_warn_u_h)
|
||||
set_hl("DiagnosticUnderlineInfo", diagnostic_info_u_h)
|
||||
set_hl("DiagnosticUnderlineHint", diagnostic_hint_u_h)
|
||||
set_hl("DiagnosticUnderlineOk", diagnostic_ok_u_h)
|
||||
set_hl("DiagnosticFloatingError", diagnostic_error_h)
|
||||
set_hl("DiagnosticFloatingWarn", diagnostic_warn_h)
|
||||
set_hl("DiagnosticFloatingInfo", diagnostic_info_h)
|
||||
set_hl("DiagnosticFloatingHint", diagnostic_hint_h)
|
||||
set_hl("DiagnosticFloatingOk", diagnostic_ok_h)
|
||||
set_hl("DiagnosticSingError", diagnostic_error_h)
|
||||
set_hl("DiagnosticSingWarn", diagnostic_warn_h)
|
||||
set_hl("DiagnosticSingInfo", diagnostic_info_h)
|
||||
set_hl("DiagnosticSingHint", diagnostic_hint_h)
|
||||
set_hl("DiagnosticSingOk", diagnostic_ok_h)
|
||||
set_hl("DiagnosticDeprecated", diagnostic_hint_u_h)
|
||||
set_hl("DiagnosticUnnecessary", diagnostic_hint_u_h)
|
||||
|
||||
-- misc ------------------------------------------------------------------------
|
||||
set_hl("Directory", H:new():fg(blue_c):attr("bold"))
|
||||
|
||||
-- syntax ----------------------------------------------------------------------
|
||||
local syntax_normal_h = {}
|
||||
local syntax_comment_h = H:new():fg(blue_c):attr("bold")
|
||||
local syntax_ignore_h = H:new():fg(black_c)
|
||||
local syntax_underline_h = H:new():attr("underline")
|
||||
local syntax_error_h = H:new():fg(red_c)
|
||||
local syntax_warn_h = H:new():fg(orange_c)
|
||||
|
||||
set_hl("Comment", syntax_comment_h)
|
||||
set_hl("Constant", syntax_normal_h)
|
||||
set_hl("String", syntax_normal_h)
|
||||
set_hl("Character", syntax_normal_h)
|
||||
set_hl("Number", syntax_normal_h)
|
||||
set_hl("Boolean", syntax_normal_h)
|
||||
set_hl("Float", syntax_normal_h)
|
||||
set_hl("Identifier", syntax_normal_h)
|
||||
set_hl("Function", syntax_normal_h)
|
||||
set_hl("Statement", syntax_normal_h)
|
||||
set_hl("Conditional", syntax_normal_h)
|
||||
set_hl("Repeat", syntax_normal_h)
|
||||
set_hl("Label", syntax_normal_h)
|
||||
set_hl("Operator", syntax_normal_h)
|
||||
set_hl("Keyword", syntax_normal_h)
|
||||
set_hl("Exception", syntax_normal_h)
|
||||
set_hl("PreProc", syntax_normal_h)
|
||||
set_hl("Include", syntax_normal_h)
|
||||
set_hl("Define", syntax_normal_h)
|
||||
set_hl("Macro", syntax_normal_h)
|
||||
set_hl("PreCondit", syntax_normal_h)
|
||||
set_hl("Type", syntax_normal_h)
|
||||
set_hl("StorageClass", syntax_normal_h)
|
||||
set_hl("Structure", syntax_normal_h)
|
||||
set_hl("Typedef", syntax_normal_h)
|
||||
set_hl("Special", syntax_normal_h)
|
||||
set_hl("SpecialChar", syntax_normal_h)
|
||||
set_hl("Tag", syntax_normal_h)
|
||||
set_hl("Delimiter", syntax_normal_h)
|
||||
set_hl("SpecialComment", syntax_normal_h)
|
||||
set_hl("Debug", syntax_normal_h)
|
||||
set_hl("Underlined", syntax_underline_h)
|
||||
set_hl("Ignore", syntax_ignore_h)
|
||||
set_hl("Error", syntax_error_h)
|
||||
set_hl("Todo", syntax_warn_h)
|
|
@ -0,0 +1,284 @@
|
|||
-- options ---------------------------------------------------------------------
|
||||
-- colorscheme
|
||||
vim.cmd("colorscheme basic") -- TODO
|
||||
|
||||
-- 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)
|
||||
local wc = vim.fn.wordcount()
|
||||
return table.concat({
|
||||
vim.fn.pathshorten(vim.fn.getcwd()),
|
||||
"%=",
|
||||
" %12(", "'", char, "' %b%)",
|
||||
" %12(", wc.visual_chars or wc.cursor_chars, "/", wc.chars, "%)",
|
||||
" %12(", wc.visual_words or wc.cursor_words, "/", wc.words, "%)",
|
||||
" %12(%l,%c%V%) %P",
|
||||
})
|
||||
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.wildignorecase = true
|
||||
-- vim.opt.wildoptions:append("fuzzy")
|
||||
|
||||
--
|
||||
vim.cmd("cnoreabbrev W w")
|
||||
vim.cmd("cnoreabbrev Q q")
|
||||
|
||||
-- langmap
|
||||
vim.opt.langmap = { "č\\;", "Č:", "š[", "Š{", "đ]", "Đ}", "ž#", "Ž~" }
|
||||
|
||||
-- path
|
||||
vim.opt.path = ".,,**"
|
||||
|
||||
-- completion
|
||||
vim.opt.completeopt = {
|
||||
"menuone",
|
||||
"noinsert",
|
||||
"preview",
|
||||
"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"})
|
||||
|
||||
-- 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 ")
|
||||
vim.keymap.set("n", "<leader>b", ":buffer ")
|
||||
vim.keymap.set("n", "<leader>h", ":help ")
|
||||
|
||||
-- scratch ---------------------------------------------------------------------
|
||||
local scratch_buffer = vim.api.nvim_create_buf(true, true)
|
||||
vim.keymap.set("n", "<leader>s", function()
|
||||
vim.api.nvim_win_set_buf(0, scratch_buffer)
|
||||
vim.keymap.set("n", "<leader>e", function()
|
||||
if vim.bo.filetype == "lua" then
|
||||
loadstring(table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, true)))()
|
||||
end
|
||||
end, { desc = "Evaluate buffer" })
|
||||
end, { desc = "Open scratch buffer" })
|
||||
|
||||
-- buffers ---------------------------------------------------------------------
|
||||
vim.keymap.set("n", "]b", "<cmd>bnext<cr>")
|
||||
vim.keymap.set("n", "[b", "<cmd>bprev<cr>")
|
||||
|
||||
-- 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 = "",
|
||||
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" })
|
||||
|
||||
-- highlight on yank -----------------------------------------------------------
|
||||
local yankhighlight_group = vim.api.nvim_create_augroup("YankHighlight", {})
|
||||
vim.api.nvim_create_autocmd("TextYankPost", {
|
||||
group = yankhighlight_group,
|
||||
desc = "Highlight on yank",
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end
|
||||
})
|
||||
|
||||
-- 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>e .<cr>")
|
||||
|
||||
local netrw_group = vim.api.nvim_create_augroup("Netrw", {})
|
||||
vim.api.nvim_create_autocmd("Filetype", {
|
||||
group = netrw_group,
|
||||
pattern = "netrw",
|
||||
desc = "",
|
||||
callback = function()
|
||||
vim.keymap.set("n", "<esc>", "<cmd>Rexplore<cr>", { buffer = true })
|
||||
end
|
||||
})
|
||||
|
||||
-- autopairs -------------------------------------------------------------------
|
||||
local brackets = {
|
||||
"()",
|
||||
"[]",
|
||||
"{}",
|
||||
"<>",
|
||||
}
|
||||
|
||||
for _,v in pairs(brackets) do
|
||||
vim.keymap.set({ "i", "c" }, v:sub(1,1), ("%s<left>"):format(v))
|
||||
end
|
||||
|
||||
vim.keymap.set("i", "<bs>", function()
|
||||
local l = vim.api.nvim_get_current_line()
|
||||
local c = vim.api.nvim_win_get_cursor(0)[2]
|
||||
local pair = l:sub(c, c + 1)
|
||||
for _, bracket in pairs(brackets) do
|
||||
if bracket == pair then
|
||||
return "<bs><del>"
|
||||
end
|
||||
end
|
||||
return "<bs>"
|
||||
end, { expr = true })
|
||||
|
||||
vim.keymap.set("c", "<bs>", function()
|
||||
local l = vim.fn.getcmdline()
|
||||
local c = vim.fn.getcmdpos()
|
||||
local pair = l:sub(c - 1, c)
|
||||
for _, bracket in pairs(brackets) do
|
||||
if bracket == pair then
|
||||
return "<bs><del>"
|
||||
end
|
||||
end
|
||||
return "<bs>"
|
||||
end, { expr = true })
|
||||
|
||||
-- comment ---------------------------------------------------------------------
|
||||
-- function toggle(line_start, line_end)
|
||||
-- -- make comment parts
|
||||
-- local buf_cs = vim.bo.commentstring:gsub("%%s", " %%s "):gsub("%s*$", "")
|
||||
-- local left, right = cs:match("^%s*(.*)%%s(.-)%s*$")
|
||||
-- -- get lines
|
||||
-- local lines = vim.api.nvim_buf_get_lines(0, line_start - 1, line_end, false)
|
||||
-- -- get indent
|
||||
-- local indent
|
||||
-- for _, l in pairs(lines) do
|
||||
-- _, n_indent_cur, indent_cur = l:find("^(%s*)")
|
||||
-- local is_blank = n_indent_cur == l:len()
|
||||
--
|
||||
-- if n_indent_cur < n_indent and not is_blank then
|
||||
-- n_indent = n_indent_cur
|
||||
-- indent = indent_cur
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- -- if is comment, make uncomment
|
||||
-- --
|
||||
-- -- else make comment
|
||||
-- -- set lines
|
||||
-- end
|
||||
|
||||
-- vim.keymap.set("n", "gcc1", function()
|
||||
-- print("buf_cs", buf_cs)
|
||||
-- local buf_cs_before, buf_cs_after = buf_cs:match("^(.*)%%s(.*)$")
|
||||
--
|
||||
-- local capture = ("^(%%s*)(%s)(.*)(%s)$"):format(buf_cs_before, buf_cs_after)
|
||||
--
|
||||
-- print("capture", capture)
|
||||
--
|
||||
-- local c_leading_space, c_buf_cs_before, c_line, c_buf_cs_after =
|
||||
-- vim.api.nvim_get_current_line():match(capture)
|
||||
--
|
||||
-- print("|", c_leading_space, "|")
|
||||
--
|
||||
-- print("c_leading_space", "|" .. c_leading_space .. "|")
|
||||
-- print("c_buf_cs_before", "|" .. c_buf_cs_before .. "|")
|
||||
-- print("c_line", "|" .. c_line .. "|")
|
||||
-- print("c_buf_cs_after", "|" .. c_buf_cs_after .. "|")
|
||||
--
|
||||
-- -- if line:find(("^%%s*(%s).*(%s)$"):format(buf_cs_before, buf_commentstring_after)) then
|
||||
-- -- print("yes!")
|
||||
-- -- return
|
||||
-- -- end
|
||||
-- --
|
||||
-- -- local leading_space, line = vim.api.nvim_get_current_line():match("(%s*)(.*)")
|
||||
-- --
|
||||
-- -- local new_line = table.concat({
|
||||
-- -- leading_space,
|
||||
-- -- buf_cs_before,
|
||||
-- -- " ",
|
||||
-- -- line,
|
||||
-- -- buf_commentstring_after
|
||||
-- -- })
|
||||
-- --
|
||||
-- -- local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
-- --
|
||||
-- -- vim.api.nvim_buf_set_lines(0, row - 1, row, true, { new_line })
|
||||
-- end)
|
Loading…
Reference in New Issue