neorg
neorg copied to clipboard
Syntax highlighting in Telescope
Issues
- [X] I have checked existing issues and there are no existing ones with the same request.
Feature description
At the moment, when I open nvim and then telescope (e.g. find_files), there is no syntax highlighting for norg files. Syntax highlighting does show up once I have opened a norg file with the current neovim instance. It would be great if the highlighting showed up even without yet having opened any norg files. This is how all other filetypes (afaik) are supported.
I guess this is due to Neorg lazy-loading most of itself only once it encounters a norg file.
Help
Yes, but I don't know how to start. I would need guidance
Implementation help
No response
I think a similar issue arises in other plugins. For instance, nvim-ufo can't highlight the fold text in neorg files. (It generally doesn't deal well with neorg folds, which might be related).
Hmm yeah this issue may be a bit difficult to resolve. I'll give it a try some other day, I feel like I'd burn myself out if i tried now :p
No problem at all! Thanks for taking a look :)
This works now! :partying_face:
@jghauser May I ask how you achieve this? I don't have any syntax highlighting in Telescope preview window, even after opening a .norg
file in the current session. I'm using lazy.nvim and here's my Neorg config:
return {
"nvim-neorg/neorg",
ft = "norg",
dependencies = { "nvim-treesitter/nvim-treesitter" },
build = ":Neorg sync-parsers",
opts = {
load = {
["core.defaults"] = {},
["core.clipboard"] = {},
["core.clipboard.code-blocks"] = {},
["core.completion"] = {
config = {
engine = "nvim-cmp",
},
},
["core.concealer"] = {
config = {
dim_code_blocks = {
enabled = true,
conceal = true,
content_only = true,
adaptive = true,
},
icon_preset = "diamond",
},
},
},
}
}
Related (without answer so far): https://github.com/nvim-neorg/neorg/discussions/279
Hmm, this sounds like a different issue (for me it always showed the highlighting once Neorg
registered the filetype (or at least that's what I think happened when first opening a .norg
file). Also, ever since :NeorgStart
was deprecated, things have worked without any setup at all. While I'm using Packer (still), my config doesn't seem to be all that different otherwise (I have norg
as ensure_installed
in my treesitter config, but I'm neither sure that's necessary nor do I think it'd make a difference). I'm sorry, I'm not of much help here, maybe someone else can chime in!
@xfzv had you find a solution to your problem because I have exactly the same.
I have my treesitter plugin which is well installed for neorg and then in neorg I have syntax highlighting but when I open a search in telescope for files I just see my files in plain text.
I find it personally annoying so I would like to know if over time you had found a solution or not.
@gungun974 No, I haven't.
I'm having this issue as well. My lazy setup is as follows:
return {
"nvim-neorg/neorg",
build = ":Neorg sync-parsers",
ft = "norg",
cmd = "Neorg",
priority = 30,
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
"nvim-neorg/neorg-telescope",
"folke/zen-mode.nvim",
"jbyuki/nabla.nvim",
},
config = function()
require("neorg").setup(...)
...
If I use the :Neorg
command before opening telescope, I get syntax highlighting in the previewer. If I open a .norg
file using my file-tree before opening telescope, I get syntax highlighting in the previewer. However, if I use Telescope's find_files
to open a .norg
file, in both the previewer and the .norg
file I get no syntax highlighting. I also get no syntax highlighting when I open subsequent .norg
files, no matter the method of opening them (file tree, :e
, find_files
).
Additionally, if I open a .norg
file using Telescope and get no syntax highlighting, later using :Neorg workspace ...
to open a .norg
file still results in no syntax highlighting, despite Neorg being loaded. I have to quit Neovim and re-open it. I've been trying to see if I can hook into events to lazy-load Neorg before telescope's previewer loads, but I've been unsuccessful.
@linguini1
Loading Neorg before Telescope seems to fix the issue on my end:
return {
"nvim-telescope/telescope.nvim",
cmd = "Telescope",
dependencies = {
{
"nvim-lua/plenary.nvim",
lazy = true,
},
{
"nvim-lua/popup.nvim",
lazy = true,
},
"tsakirist/telescope-lazy.nvim",
"jvgrootveld/telescope-zoxide",
"nvim-neorg/neorg"
},
config = function()
require("telescope").setup({
...
)}
}
My Neorg config:
return {
"nvim-neorg/neorg",
ft = "norg",
dependencies = { "nvim-treesitter/nvim-treesitter" },
build = ":Neorg sync-parsers",
opts = {
load = {
["core.defaults"] = {},
["core.clipboard"] = {},
["core.clipboard.code-blocks"] = {},
["core.completion"] = {
config = {
engine = "nvim-cmp",
},
},
["core.concealer"] = {
config = {
dim_code_blocks = {
enabled = true,
conceal = true,
content_only = true,
adaptive = true,
},
icon_preset = "diamond",
},
},
},
}
}
With this, I'm getting syntax highlighting in Telescope previewer even when running find_files
just after opening Neovim (and with any other method you mentioned).
in both the previewer and the .norg file I get no syntax highlighting.
Syntax highlighting has always worked in the buffer on my end, maybe you should open a new issue for this. Your setup looks similar to mine, not sure why this would occur.
Loading Neorg before Telescope seems to fix the issue on my end:
@xfzv Thanks for the help! I just don't think this solves my particular issue.
Your solution does the same on my end. The problem is that I want to lazy-load Neorg on both ft
and the :Neorg
command. If I do what's in your config, Neorg is loaded whenever Telescope is loaded (which for me is on startup), and that's not what I want. I'm hoping to load and enable the tree-sitter highlights before Neorg is loaded (so it appears in Telescope) or at least when a .norg
file is opened from Telescope. The ideal scenario would to load Neorg when the Telescope previewer shows a .norg
file. I have tried several events (BufEnter
, BufRead
, WinNew
, etc) in the event option of lazy.nvim, but Telescope seems not to trigger any of these events when the previewer shows a file.
and that's not what I want.
Me neither, I'm also using ft = "norg"
so this workaround breaks the lazy loading, indeed.
I found another workaround which works for me after reading this:
vim.api.nvim_create_autocmd("User", {
pattern = "TelescopePreviewerLoaded",
callback = function(args)
if args.data.filetype == "norg" then
vim.bo.filetype = "norg"
end
end,
})
@xfzv This solves my problem! Thank you!
I am going to open a bug about this regardless in case there's something Neorg can do to prevent this issue natively. I made a slight modification to the code snippet you provided to prevent unnecessary autocommand firing:
-- Hacky workaround to have Neorg highlights in the preview
local hl_group = vim.api.nvim_create_augroup("norg-telescope-hl", { clear = true })
vim.api.nvim_create_autocmd("User", {
group = hl_group,
pattern = "TelescopePreviewerLoaded",
callback = function(args)
if args.data.filetype == "norg" then
vim.bo.filetype = "norg"
vim.api.nvim_del_augroup_by_id(hl_group) -- Clear up once Neorg is loaded properly
end
end,
})
This will just delete the autocommand once Neorg is loaded.
Nice improvement, thanks for sharing!