1
0
Fork 0

.config/nvim: update

main
urosm 2024-04-11 19:15:09 +02:00
parent 45e31c9118
commit 937768b0cc
8 changed files with 160 additions and 251 deletions

View File

@ -0,0 +1,4 @@
-- options ---------------------------------------------------------------------
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true

View File

@ -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}<esc>", {})
keymap_set("n", "[h", "?\\_^#.*\\ze\\n\\{2}<esc>", {})

View File

@ -0,0 +1,4 @@
-- options ---------------------------------------------------------------------
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true

View File

@ -0,0 +1,4 @@
-- options ---------------------------------------------------------------------
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true

View File

@ -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 "\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\_.\{-}\]" 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:

View File

@ -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)

View File

@ -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" }, "<space>", "<nop>", { 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", "<esc>", function()
vim.cmd.nohlsearch()
local keymap_set = vim.keymap.set
keymap_set( "n", "<esc>", function()
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" })
keymap_set("c", "<m-h>", "<left>", { desc = "Left in c-mode" })
keymap_set("c", "<m-l>", "<right>", { desc = "Right in c-mode" })
-- 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" })
keymap_set("n", "<leader>f", ":find ", { desc = ":find" })
keymap_set("n", "<leader>b", ":buffer ", { desc = ":buffer" })
keymap_set("n", "<leader>h", ":help ", { desc = ":help" })
-- 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()
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" })
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" })
keymap_set("n", "<leader>d", "<cmd>enew<cr><cmd>bd #<cr>", { desc = "Delete buffer" })
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" })
keymap_set("n", "]b", "<cmd>bnext<cr>", { desc = "Next buffer" })
keymap_set("n", "[b", "<cmd>bprev<cr>", { desc = "Previous buffer" })
keymap_set("n", "]t", "<cmd>tabnext<cr>", { desc = "Next tab" })
keymap_set("n", "[t", "<cmd>tabprevious<cr>", { desc = "Previous tab" })
keymap_set("n", "]q", "<cmd>cnext<cr>zz", { desc = "Next quickfix item" })
keymap_set("n", "[q", "<cmd>cprev<cr>zz", { desc = "Previous quickfix item" })
-- vimgrep ---------------------------------------------------------------------
vim.keymap.set("n", "<leader>g", ":vimgrep / **/*<c-left><c-left>/")
keymap_set("n", "<leader>co", "<cmd>copen<cr>", { desc = "Open quickfix window" })
keymap_set("n", "<leader>cc", "<cmd>cclose<cr>", { 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", "<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" })
keymap_set("n", "<leader>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", "<leader>.", "<cmd>Explore .<cr>",
g.netrw_use_errorwindow = 0
g.netrw_banner = 0
g.netrw_bufsettings = "noma nomod nowrap ro nobl"
g.netrw_fastbrowse = 0
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
})

View File

@ -1,112 +0,0 @@
" Vim syntax file
" Language: Markdown
" Maintainer: urosm <urosm@kompot.si>
" Last Change: 2024 Feb 14
if exists("b:current_syntax")
finish
endif
syntax spell toplevel
" emphasis
syn region markdownItalic matchgroup=markdownDelimiter start=/\\\@1<!\(\_^\|\s\|[[:punct:]]\)\@<=\*\S\@=/ skip=/\(\*\*\|__\)/ end=/\*\([[:punct:]]\|\s\|\_$\)\@=/ contains=@Spell
syn region markdownItalic matchgroup=markdownDelimiter start=/\\\@1<!\(\_^\|\s\|[[:punct:]]\)\@<=_\S\@=/ skip=/\(\*\*\|__\)/ end=/\S\@1<=_\([[:punct:]]\|\s\|\_$\)\@=/ contains=@Spell
" bold
syn region markdownBold matchgroup=markdownDelimiter start=/\(\\\@<!\*\)\{2}/ end=/\(\\\@<!\*\)\{2}/ contains=@Spell
syn region markdownBold matchgroup=markdownDelimiter start=/__/ end=/__/ contains=@Spell
" bold italic
syn region markdownBoldItalic matchgroup=markdownDelimiter start=/\*\{3}\(\S[^*]*\(\*\S\|\n[^*]*\*\S\)\)\@=/ end=/\S\@<=\*\{3}/ contains=@Spell
syn region markdownBoldItalic matchgroup=markdownDelimiter start=/\(___\)\S\@=/ end=/\S\@<=___/ contains=@Spell
syn region markdownBoldInItalic matchgroup=markdownDelimiter start=/\*\*/ end=/\*\*/ contained containedin=markdownItalic contains=@Spell
syn region markdownBoldInItalic matchgroup=markdownDelimiter start=/__/ end=/__/ contained containedin=markdownItalic contains=@Spell
hi def link markdownBoldInItalic markdownBoldItalic
syn region markdownItalicInBold matchgroup=markdownDelimiter start=/\\\@1<!\(\_^\|\s\|[[:punct:]]\)\@<=\*\S\@=/ skip=/\(\*\*\|__\)/ end=/\S\@<=\*\([[:punct:]]\|\s\|\_$\)\@=/ contained containedin=markdownBold contains=@Spell
syn region markdownItalicInBold matchgroup=markdownDelimiter start=/\\\@<!\(\_^\|\s\|[[:punct:]]\)\@<=_\S\@=/ skip=/\(\*\*\|__\)/ end=/\S\@<=_\([[:punct:]]\|\s\|\_$\)\@=/ contained containedin=markdownBold contains=@Spell
hi def link markdownItalicInBold markdownBoldItalic
" link
syn match markdownLink /!\=\[\_.\{-}\](\_.\{-})/ contains=markdownLinkLabel,markdownLinkURL
syn match markdownLinkLabel /\[\zs.*\ze\]/ contained
hi def link markdownLinkLabel markdownLabel
syn match markdownLinkURL /.*(\zs.*\ze)/ contained
hi def link markdownLinkURL markdownUnderlined
" automatic link
syn match markdownAutomaticLink /<\(https\{0,1}.\{-}\|[A-Za-z0-9!#$%&'*+\-/=?^_`{|}~.]\{-}@[A-Za-z0-9\-]\{-}\.\w\{-}\)>/
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=/<!--/ end=/-->/ 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: