markdown.lua

dotfiles.git > main > 9d528a7 > files / nvim / ftplugin / markdown.lua

local ol = vim.opt_local
ol.wrap = true
ol.linebreak = true
ol.spell = true
ol.columns = 80
ol.showbreak = " "

--- Registers the predicate the wikilink highlights use
require("wikilink")
vim.treesitter.start()

--- Obsidian shows the note's name as a heading above it, so do the same instead of writing # Titles
local function set_title()
  local name = vim.fn.expand("%:t:r")
  vim.b.header_lines = name ~= "" and {{{"# " .. name, "@markup.heading.1"}}} or nil
end
set_title()
vim.api.nvim_create_autocmd("BufFilePost", {buffer = 0, callback = set_title})

local follow = function(fallback) return function() require("wikilink").follow(fallback) end end
vim.keymap.set("n", "gd", follow("gd"), {buffer = true})
vim.keymap.set("n", "gf", follow("gf"), {buffer = true})