diff --git a/.config/nvim/after/ftplugin/css.lua b/.config/nvim/after/ftplugin/css.lua new file mode 100644 index 0000000..8c62149 --- /dev/null +++ b/.config/nvim/after/ftplugin/css.lua @@ -0,0 +1,4 @@ +-- options --------------------------------------------------------------------- +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true diff --git a/.config/nvim/after/ftplugin/markdown.lua b/.config/nvim/after/ftplugin/markdown.lua index e31932f..46248b6 100644 --- a/.config/nvim/after/ftplugin/markdown.lua +++ b/.config/nvim/after/ftplugin/markdown.lua @@ -2,4 +2,8 @@ vim.bo.tabstop = 2 vim.bo.shiftwidth = 2 vim.bo.expandtab = true -vim.bo.textwidth = 72 + +-- keymaps --------------------------------------------------------------------- +local keymap_set = vim.keymap.set +keymap_set("n", "]h", "/\\_^#.*\\ze\\n\\{2}", {}) +keymap_set("n", "[h", "?\\_^#.*\\ze\\n\\{2}", {}) diff --git a/.config/nvim/after/ftplugin/sh.lua b/.config/nvim/after/ftplugin/sh.lua new file mode 100644 index 0000000..4d2c74e --- /dev/null +++ b/.config/nvim/after/ftplugin/sh.lua @@ -0,0 +1,4 @@ +-- options --------------------------------------------------------------------- +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true diff --git a/.config/nvim/after/ftplugin/template.lua b/.config/nvim/after/ftplugin/template.lua new file mode 100644 index 0000000..8c62149 --- /dev/null +++ b/.config/nvim/after/ftplugin/template.lua @@ -0,0 +1,4 @@ +-- options --------------------------------------------------------------------- +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true diff --git a/.config/nvim/after/syntax/markdown.vim b/.config/nvim/after/syntax/markdown.vim new file mode 100644 index 0000000..70bc5a9 --- /dev/null +++ b/.config/nvim/after/syntax/markdown.vim @@ -0,0 +1,22 @@ +if exists("b:current_syntax") + unlet! b:current_syntax +endif + +" yaml +syntax clear markdownYamlHead +syntax region markdownYamlHead start="^-\{3}\n\S" end="\S\n\%(-\|\.\)\{3}$" keepend contains=@markdownYamlTop,@Spell + + +" citation +syntax match markdownPCite "\^\@~/]*\_.\{-}\]" contains=@markdownInline,markdownCiteKey +syn match markdownICite "@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\s\[.\{-1,}\]" contains=markdownCiteKey,@Spell display +syn match markdownCiteKey /\(-\=@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\)/ containedin=markdownPCite,markdownICite contains=@NoSpell display + +hi def link markdownPCite Comment +hi def link markdownICite Comment +hi def link markdownCiteKey markdownLabel +hi def link markdownLabel Label + +let b:current_syntax = "markdown" + +" vim:set sw=2: diff --git a/.config/nvim/colors/basic.lua b/.config/nvim/colors/basic.lua index 752b4e4..0d34d83 100644 --- a/.config/nvim/colors/basic.lua +++ b/.config/nvim/colors/basic.lua @@ -87,7 +87,8 @@ 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 +local nvim_set_hl = vim.api.nvim_set_hl +local function set_hl(group, def) nvim_set_hl(0, group, def) end -- normal ---------------------------------------------------------------------- local normal_h = {} @@ -326,5 +327,12 @@ local markdown_delimiter_h = H:new():fg(blue_c) local markdown_underline_h = H:new():fg(blue_c):attr("underline") set_hl("markdownLabel", markdown_label_h) -set_hl("markdownDelimiter", markdown_delimiter_h) -set_hl("markdownUnderlined", markdown_underline_h) +set_hl("markdownHeadingDelimiter", markdown_delimiter_h) +set_hl("markdownItalicDelimiter", markdown_delimiter_h) +set_hl("markdownBoldDelimiter", markdown_delimiter_h) +set_hl("markdownBoldItalicDelimiter", markdown_delimiter_h) +set_hl("markdownStrikeDelimiter", markdown_delimiter_h) +set_hl("markdownCodeDelimiter", markdown_delimiter_h) + +set_hl("yamlBlockMappingKey", syntax_comment_h) +set_hl("yamlPlainScalar", syntax_constant_h) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 50def57..28b76d1 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,52 +1,59 @@ +local opt, api, cmd = vim.opt, vim.api, vim.cmd +local fn, ui = vim.fn, vim.ui + +cmd.colorscheme("basic") + -- options --------------------------------------------------------------------- --- colorscheme -vim.cmd.colorscheme("basic") +opt.undofile = true +opt.backup = false +opt.writebackup = false +opt.mouse = {} +opt.title = true --- leader -vim.g.mapleader = " " -vim.g.maplocalleader = " " -vim.keymap.set({ "n", "v" }, "", "", { silent = true }) +opt.shortmess:append({ I = true }) +opt.number = true +opt.relativenumber = true +opt.signcolumn = "number" +opt.textwidth = 80 +opt.colorcolumn = "+1" --- general -vim.opt.undofile = true -vim.opt.backup = false -vim.opt.writebackup = false -vim.opt.mouse = {} -vim.opt.title = true +opt.showtabline = 2 +opt.winbar = "%f%( %h%m%r%y%)" +opt.laststatus = 3 --- 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" +local statusline_group = api.nvim_create_augroup("Statusline", {}) +local wordcount = fn.wordcount() +api.nvim_create_autocmd({ "TextChanged", "WinEnter", "BufEnter" }, { + group = statusline_group, + callback = function() + wordcount = fn.wordcount() + end +}) +local cwd = fn.pathshorten(vim.fn.getcwd()) +api.nvim_create_autocmd({ "DirChanged" }, { + group = statusline_group, + callback = function() + cwd = fn.pathshorten(vim.fn.getcwd()) + end +}) --- 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 + cwd, + " %=", + " <%b> ", + wordcount.visual_chars or wordcount.cursor_chars, "/", wordcount.chars, " ", + wordcount.visual_words or wordcount.cursor_words, "/", wordcount.words }) end -vim.opt.statusline = "%!v:lua.statusline()" +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 = { +opt.ignorecase = true +opt.infercase = true +opt.smartcase = true +opt.smartindent = true +opt.clipboard = "unnamedplus" +opt.whichwrap = { ["b"] = true, ["s"] = true, ["h"] = true, @@ -57,121 +64,89 @@ vim.opt.whichwrap = { ["["] = true, ["]"] = true } -vim.opt.wildoptions = { "fuzzy" } -vim.opt.wildignorecase = true +opt.wildoptions = { "fuzzy" } +opt.wildignorecase = true --- path -vim.opt.path = ".,,**" --- local root = vim.fs.find({ ".git" }, { upward = true })[1] +opt.path = ".,,**" --- completion -vim.opt.completeopt = { +opt.completeopt = { "menuone", "preview", - "noinsert", - "noselect" } +local terminal_group = api.nvim_create_augroup("Terminal", {}) +api.nvim_create_autocmd({ "TermOpen" }, { + group = terminal_group, + callback = function() + local opt_l = vim.opt_local + opt_l.number = false + opt_l.relativenumber = false + end +}) + -- keymaps --------------------------------------------------------------------- --- clear hlsearch -vim.keymap.set( "n", "", function() - vim.cmd.nohlsearch() +local keymap_set = vim.keymap.set + +keymap_set( "n", "", function() + cmd.nohlsearch() end, { desc = "Stop the highlighting for the 'hlsearch' option" }) --- move cursor with alt in c-mode -vim.keymap.set("c", "", "", { desc = "Left" }) -vim.keymap.set("c", "", "", { desc = "Right" }) +keymap_set("c", "", "", { desc = "Left in c-mode" }) +keymap_set("c", "", "", { desc = "Right in c-mode" }) --- move cursor with alt in i-mode -vim.keymap.set("i", "", "", { desc = "Left" }) -vim.keymap.set("i", "", "", { desc = "Down" }) -vim.keymap.set("i", "", "", { desc = "Up" }) -vim.keymap.set("i", "", "", { desc = "Right" }) +keymap_set("n", "f", ":find ", { desc = ":find" }) +keymap_set("n", "b", ":buffer ", { desc = ":buffer" }) +keymap_set("n", "h", ":help ", { desc = ":help" }) --- move cursor with alt in t-mode -vim.keymap.set("t", "", "", { desc = "Left" }) -vim.keymap.set("t", "", "", { desc = "Down" }) -vim.keymap.set("t", "", "", { desc = "Up" }) -vim.keymap.set("t", "", "", { desc = "Right" }) - --- navigate windows -vim.keymap.set("n", "", "h", { desc = "Navigate window left"}) -vim.keymap.set("n", "", "j", { desc = "Navigate window down"}) -vim.keymap.set("n", "", "k", { desc = "Navigate window up"}) -vim.keymap.set("n", "", "l", { desc = "Navigate window right"}) -vim.keymap.set("i", "", "h", { desc = "Navigate window left"}) -vim.keymap.set("i", "", "j", { desc = "Navigate window down"}) -vim.keymap.set("i", "", "k", { desc = "Navigate window up"}) -vim.keymap.set("i", "", "l", { desc = "Navigate window right"}) -vim.keymap.set("t", "", "h", { desc = "Navigate window left"}) -vim.keymap.set("t", "", "j", { desc = "Navigate window down"}) -vim.keymap.set("t", "", "k", { desc = "Navigate window up"}) -vim.keymap.set("t", "", "l", { desc = "Navigate window right"}) - --- navigate buffer -vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "", "zz") - --- cmdline history navigation -vim.keymap.set("c", "", "") -vim.keymap.set("c", "", "") - --- menus -vim.keymap.set("n", "f", ":find ", { desc = ":find" }) -vim.keymap.set("n", "b", ":buffer ", { desc = ":buffer" }) -vim.keymap.set("n", "h", ":help ", { desc = ":help" }) - --- spell -vim.keymap.set("n", "s", function() +keymap_set("n", "s", function() vim.opt_local.spell = not(vim.opt_local.spell:get()) end, { desc = "Toggle spell" }) --- make -vim.keymap.set("n", "m", "make", { desc = ":make" }) +keymap_set("n", "m", "make", { desc = ":make" }) --- buffers --------------------------------------------------------------------- -vim.keymap.set("n", "]b", "bnext", { desc = "Next buffer" }) -vim.keymap.set("n", "[b", "bprev", { desc = "Previous buffer" }) -vim.keymap.set("n", "d", "enewbd #", { desc = "Delete buffer" }) -vim.keymap.set("n", "D", "bd", { desc = "Delete buffer and close window" }) +keymap_set("n", "d", "enewbd #", { desc = "Delete buffer" }) +keymap_set("n", "D", "bd", { desc = "Delete buffer and close window" }) --- tabs ------------------------------------------------------------------------ -vim.keymap.set("n", "]t", "tabnext", { desc = "Next tab" }) -vim.keymap.set("n", "[t", "tabprevious", { desc = "Previous tab" }) +keymap_set("n", "]b", "bnext", { desc = "Next buffer" }) +keymap_set("n", "[b", "bprev", { desc = "Previous buffer" }) +keymap_set("n", "]t", "tabnext", { desc = "Next tab" }) +keymap_set("n", "[t", "tabprevious", { desc = "Previous tab" }) +keymap_set("n", "]q", "cnextzz", { desc = "Next quickfix item" }) +keymap_set("n", "[q", "cprevzz", { desc = "Previous quickfix item" }) --- vimgrep --------------------------------------------------------------------- -vim.keymap.set("n", "g", ":vimgrep / **/*/") +keymap_set("n", "co", "copen", { desc = "Open quickfix window" }) +keymap_set("n", "cc", "cclose", { desc = "Close quickfix window" }) -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", "copen", { desc = "Open quickfix window" }) -vim.keymap.set("n", "cc", "cclose", { desc = "Close quickfix window" }) -vim.keymap.set("n", "]q", "cnextzz", { desc = "Next quickfix item" }) -vim.keymap.set("n", "[q", "cprevzz", { desc = "Previous quickfix item" }) +keymap_set("n", "g", function() + local pattern + ui.input({ prompt = ":vimgrep " }, function(input) + if not input then return end + if input:match("/.+/[gjf]*") then + pattern = input + else + pattern = ("/%s/g"):format(input) + end + end) + if not pattern then return end + local file + ui.input({ + prompt = (":vimgrep %s "):format(pattern), + default = "**/*" + }, function(input) + if not input then return end + file = input + end) + if not file then return end + cmd.vimgrep(pattern, file) +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 +local g = vim.g -vim.keymap.set("n", ".", "Explore .", +g.netrw_use_errorwindow = 0 +g.netrw_banner = 0 +g.netrw_bufsettings = "noma nomod nowrap ro nobl" +g.netrw_fastbrowse = 0 + +keymap_set("n", ".", "Explore .", { 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", "", "Rexplore", - { buffer = true, desc = "Return to/from Explorer" }) - end -}) diff --git a/.config/nvim/syntax/markdown.vim b/.config/nvim/syntax/markdown.vim deleted file mode 100644 index ea97471..0000000 --- a/.config/nvim/syntax/markdown.vim +++ /dev/null @@ -1,112 +0,0 @@ -" Vim syntax file -" Language: Markdown -" Maintainer: urosm -" Last Change: 2024 Feb 14 - -if exists("b:current_syntax") - finish -endif - -syntax spell toplevel - -" emphasis -syn region markdownItalic matchgroup=markdownDelimiter start=/\\\@1/ -hi def link markdownAutomaticLink markdownUnderlined - -" wikilink -" NOTE: update to support newlines in titles -syn match markdownWikilink /\[\[.*\]\]/ contains=markdownWikilinkLabel,markdownWikilinkURL -syn match markdownWikilinkLabel /\[\[\zs.\{-}\ze|.*\]\]/ contained -hi def link markdownWikilinkLabel markdownLabel -syn match markdownWikilinkURL /\%(\[\[\||\)\zs[^|]*\ze\]\]/ contained -hi def link markdownWikilinkURL markdownUnderlined - -" footnote reference -syn match markdownFootnoteReference /\[\zs\^.\{-}\ze\]/ -hi def link markdownFootnoteReference markdownLabel - -" reference key -syn match markdownReferenceKey /@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&-+?<>~\/]*/ -hi def link markdownReferenceKey markdownLabel - -" html comment -syn region markdownHTMLcomment start=// keepend contains=@Spell -hi def link markdownHTMLcomment markdownComment - -" yaml -syn include @YAML syntax/yaml.vim -unlet! b:current_syntax -syn region markdownYAMLHeader start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=@YAML containedin=TOP - -" styling -hi def link markdownComment Comment -hi def link markdownConstant Constant -hi def link markdownString String -hi def link markdownCharacter Character -hi def link markdownNumber Number -hi def link markdownBoolean Boolean -hi def link markdownFloat Float -hi def link markdownIdentifier Identifier -hi def link markdownFunction Function -hi def link markdownStatement Statement -hi def link markdownConditional Conditional -hi def link markdownRepeat Repeat -hi def link markdownLabel Label -hi def link markdownOperator Operator -hi def link markdownKeyword Keyword -hi def link markdownException Exception -hi def link markdownPreProc PreProc -hi def link markdownInclude Include -hi def link markdownDefine Define -hi def link markdownMacro Macro -hi def link markdownPreCondit PreCondit -hi def link markdownType Type -hi def link markdownStorageClass StorageClass -hi def link markdownStructure Structure -hi def link markdownTypedef Typedef -hi def link markdownSpecial Special -hi def link markdownSpecialChar SpecialChar -hi def link markdownTag Tag -hi def link markdownDelimiter Delimiter -hi def link markdownSpecialComment SpecialComment -hi def link markdownDebug Debug -hi def link markdownUnderlined Underlined -hi def link markdownIgnore Ignore -hi def link markdownError Error - -hi def link markdownItalic Italic -hi def link markdownBold Bold -hi def link markdownBoldItalic BoldItalic -hi def link markdownStrike Strike -hi def link markdownTitle Title - -let b:current_syntax = "markdown" - -" vim:set sw=2: