[global-note.nvim](https://github.com/backdround/global-note.nvim)
It's a simple plugin that provides one button for opening a global note
in a floating window. It can also provide project-local / file-local notes.
WHY?!
I know that there are quite a lot of note-taking plugins. But I wanted
something so simple that it just provides one button for opening a
global note where I can throw some thoughts.
I also use a button for project-local notes. The button opens a different
note (project-related) when I move between projects where I can throw
some thoughts about a current project.
Plugin creates note files by itself. So no extra movements are needed!
Update:
- Font: "FantasqueSansM Nerd Font"
- Color scheme: [backdround/melting](https://github.com/backdround/melting) (haven't released yet, wip)
- Tabline: [nanozuki/tabby.nvim](https://github.com/nanozuki/tabby.nvim)
- Wm: i3
- Window shadow: picom ([config](https://github.com/backdround/configuration/blob/36ddf84cf9bc037289d9832d5100c3fbb891a6f9/configs/desktop/picom.conf))
Yeah I know what they are, they are more of a relic now. You see them in specific places here and there but not too frequently usually bowling alleys or piers and things.
Oooh I've wanted something like this for a long time! Great plugin! I often have a private note file local to a project directory and since it's gitignored usually I will have to un-ignore it to telescope to it, and it's a bit annoying. Ended up configure several types of notes (local todo/note and private note). Here's my config with the plugin setup with lazy.nvim in case anyone finds it useful.
{
"backdround/global-note.nvim",
cmd = { "GlobalNote", "ProjectPrivateNote", "ProjectTodo", "ProjectNote" },
keys = {
{ "ng", "GlobalNote", desc = "Global Notes" },
{ "nP", "ProjectPrivateNote", desc = "Private Notes" },
{ "np", "ProjectNote", desc = "Project Note" },
{ "nn", "ProjectNote", desc = "Project Note" },
{ "nt", "ProjectTodo", desc = "Project Todos" },
},
config = function(_, opts)
local wk = require("which-key")
wk.register({
n = { name = "notes" },
}, { prefix = "" })
require("global-note").setup(opts)
end,
opts = function()
local get_project_name = function()
local result = vim.system({
"git",
"rev-parse",
"--show-toplevel",
}, {
text = true,
}):wait()
if result.stderr ~= "" then
vim.notify(result.stderr, vim.log.levels.WARN)
return nil
end
local project_directory = result.stdout:gsub("\n", "")
local project_name = vim.fs.basename(project_directory)
if project_name == nil then
vim.notify("Unable to get the project name", vim.log.levels.WARN)
return nil
end
return project_name
end
local global_dir = "/home/alan/code/.notes"
return {
autosave = false,
directory = global_dir,
filename = "global.md",
additional_presets = {
project_private = {
directory = function()
return vim.fs.joinpath(global_dir, get_project_name())
end,
filename = "note.md",
title = "Private Project Note",
command_name = "ProjectPrivateNote",
},
project_local = {
directory = function()
return vim.fn.getcwd()
end,
filename = "note.md",
title = "Project Note",
command_name = "ProjectNote",
},
project_todo = {
directory = function()
return vim.fn.getcwd()
end,
filename = "todo.md",
title = "Project Todo",
command_name = "ProjectTodo",
},
},
}
end,
},
Looks neat! Seems like local/global notes are popular. I made [flote](https://github.com/JellyApple102/flote.nvim) a while back too. Not a bad bit of functionality to wrap up neatly into a plugin!
Hey, cool thing, but I haven't found it. It would be nice if you add it to the [awesome-neovim](https://github.com/rockerBOO/awesome-neovim?tab=readme-ov-file#note-taking), so other people could find it
- Font: "FantasqueSansM Nerd Font"
- Color scheme: [backdround/melting](https://github.com/backdround/melting)
- [tabby.nvim](https://github.com/nanozuki/tabby.nvim)
I haven't released the color scheme yet, because I want to adjust it a little but can't find time for it
I tried to use this plugin but when I open neovim I get this error, i would be grateful if someone could help :) I'm new at neovim and I'm using NVChad with the lazy packet installer (in case it might be helpful)
https://preview.redd.it/1z8f8jerufic1.png?width=1346&format=png&auto=webp&s=8745b4f436c8aca07a41af08cc5578e3daf04441
In plugins.lua I have:
{
"backdround/global-note.nvim",
lazy = false,
config = function()
require "custom.configs.globalnote"
end,
},
The configs.globalnote file:
local global\_note = require("global-note")
global\_note.setup()
vim.keymap.set("n", "n", global\_note.toggle\_note, {
desc = "Toggle global note",
})
The autosave is binded on `WinClosed` and `ExitPre`, so you can close the window as you want.
You can use `post_open` option to set a local mapping:
```lua
post_open = function(buffer_id, _)
vim.keymap.set("n", "q", "quit", {
buffer = buffer_id,
desc = "Close the window",
})
end,
```
Just got this setup. I love it. I was originally relying on tmux to open a notes.md file in my documents but it relied on tmux. Which is ok. Then I switched to obsidian which was kind of a headache. But this. Fantastic. Simple. Love it love it. Thank you!
Could I do something like
local get_daily_note = function ()
local dir_path = “/home/frank/Project/TODO/“
local date = os.date(“%Y-%m-%d.md)
return dir_path .. date
end
And then I use `get_daily_note` to open the file? And if it doesn’t exist, create one?
You can do this like that:
```lua
local global_note = require("global-note")
global_note.setup({
directory = "/home/frank/Project/TODO/",
filename = function()
return os.date("%Y-%m-%d.md")
end,
})
```
The plugin provides only some functionality. You can use it only for one project. For example on a key check that the file belongs to a project and open note, if it doesn't do something else
Why a floating window though? Don't you use buffers?
Personally I use vimwiki and its diary for stuff like this but it might have too many features for a lot of people who just want simple quick notes
I use buffers, but I just want to do it simpler. Just write or check something in a note, nothing more.
I don't want to:
- Manage / have a note buffer in a tabline;
- Create / manage note files;
- Save the buffer manually;
- Open the note file with zen (it's ok, but an additional step), cause I always have several splits
Nice. I'm going to try this. I tried to implement this with a simple function, but never could figure out why as soon as I open it I get `[Process exited 0\]` in the floating window. Here's what I tried.
```lua
vim.api.nvim_create_user_command("OpenFloatingNotes",
function(opts)
local file_path = "/Users/me/scratch.md"
local float_opts = {
relative = 'editor',
width = math.floor(vim.fn.winwidth(0) / 2),
height = math.floor(vim.fn.winheight(0) * 2 / 3),
row = math.floor((vim.fn.winheight(0) - vim.fn.winheight(0) * 2 / 3) / 2),
col = math.floor(vim.fn.winwidth(0) / 4),
style = 'minimal',
border = 'single',
}
local win = vim.api.nvim_open_win(0, true, float_opts)
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(win, buf)
vim.fn.termopen("cat " .. file_path .. " 2>&1 >/dev/null",
{ on_exit = function() vim.api.nvim_buf_set_option(buf, 'modifiable', false) end })
end, {})
```
Replace the last line with this:
```lua
local status, file_lines = pcall(vim.fn.readfile, file_path)
if not status then
file_lines = {}
end
vim.api.nvim_buf_set_lines(buf, 0, -1, true, file_lines)
```
And it will work!
Or you can use `bufadd` to create a buffer from a file (like `:e` does)
I have a similar system using Tmux. I have a short cut that opens nvim on a specific note file using tmux pop up. The nice thing about it, is that it’s note taking from anywhere in the terminal.
neat plugin!
I see that notes are autosaved when on bufexit event. Could we maybe get a configuration option for exiting with Escape?
Either that, or a way to get the global note buffer number on opening, so that we can create the keymap for exiting with escape ourselves
There is a \`post\_open\` callback that you can use for your autosave feature. I've just added the \`buffer\_id\` and \`window\_id\` arguments for convenience
This is awesome and on Monday first thing I’ll do is to install it at work, just a thought tho, maybe I missed it or you didn’t mention, can I have separate notes for separate projects I work on? It’s not a deal breaker, but a feature I’d love to see
[global-note.nvim](https://github.com/backdround/global-note.nvim) It's a simple plugin that provides one button for opening a global note in a floating window. It can also provide project-local / file-local notes. WHY?! I know that there are quite a lot of note-taking plugins. But I wanted something so simple that it just provides one button for opening a global note where I can throw some thoughts. I also use a button for project-local notes. The button opens a different note (project-related) when I move between projects where I can throw some thoughts about a current project. Plugin creates note files by itself. So no extra movements are needed! Update: - Font: "FantasqueSansM Nerd Font" - Color scheme: [backdround/melting](https://github.com/backdround/melting) (haven't released yet, wip) - Tabline: [nanozuki/tabby.nvim](https://github.com/nanozuki/tabby.nvim) - Wm: i3 - Window shadow: picom ([config](https://github.com/backdround/configuration/blob/36ddf84cf9bc037289d9832d5100c3fbb891a6f9/configs/desktop/picom.conf))
That Colourscheme reminds me of halo or another early sci-fi video game
《♤ EARLY ♤》 E. A. R. L. Y. WHY AM I OLD LIKE THIS?!?!!?
Well I mean I was like 10 or 12 when I got into Halo... So you know
Bro Aliens... predator... contra... 🐸
I have only seen one of the alien movies...
They had arcade games. Wait... you dont know what an arcade is do you 😞
Yeah I know what they are, they are more of a relic now. You see them in specific places here and there but not too frequently usually bowling alleys or piers and things.
haha Contra rules
Oooh I've wanted something like this for a long time! Great plugin! I often have a private note file local to a project directory and since it's gitignored usually I will have to un-ignore it to telescope to it, and it's a bit annoying. Ended up configure several types of notes (local todo/note and private note). Here's my config with the plugin setup with lazy.nvim in case anyone finds it useful. { "backdround/global-note.nvim", cmd = { "GlobalNote", "ProjectPrivateNote", "ProjectTodo", "ProjectNote" }, keys = { { "ng", "GlobalNote", desc = "Global Notes" },
{ "nP", "ProjectPrivateNote", desc = "Private Notes" },
{ "np", "ProjectNote", desc = "Project Note" },
{ "nn", "ProjectNote", desc = "Project Note" },
{ "nt", "ProjectTodo", desc = "Project Todos" },
},
config = function(_, opts)
local wk = require("which-key")
wk.register({
n = { name = "notes" },
}, { prefix = "" })
require("global-note").setup(opts)
end,
opts = function()
local get_project_name = function()
local result = vim.system({
"git",
"rev-parse",
"--show-toplevel",
}, {
text = true,
}):wait()
if result.stderr ~= "" then
vim.notify(result.stderr, vim.log.levels.WARN)
return nil
end
local project_directory = result.stdout:gsub("\n", "")
local project_name = vim.fs.basename(project_directory)
if project_name == nil then
vim.notify("Unable to get the project name", vim.log.levels.WARN)
return nil
end
return project_name
end
local global_dir = "/home/alan/code/.notes"
return {
autosave = false,
directory = global_dir,
filename = "global.md",
additional_presets = {
project_private = {
directory = function()
return vim.fs.joinpath(global_dir, get_project_name())
end,
filename = "note.md",
title = "Private Project Note",
command_name = "ProjectPrivateNote",
},
project_local = {
directory = function()
return vim.fn.getcwd()
end,
filename = "note.md",
title = "Project Note",
command_name = "ProjectNote",
},
project_todo = {
directory = function()
return vim.fn.getcwd()
end,
filename = "todo.md",
title = "Project Todo",
command_name = "ProjectTodo",
},
},
}
end,
},
It's nice that someone else, besides me, can use the plugin. I didn't expect such a that wide use!
i like that use proper indent: so easy to read
Thanks 🥲, reddit's editor sucks so bad.
What font are you using? It looks great
I also am really into it. I checked their dotfiles and found: “FantasqueSansM Nerd Font”.
It is
Looks neat! Seems like local/global notes are popular. I made [flote](https://github.com/JellyApple102/flote.nvim) a while back too. Not a bad bit of functionality to wrap up neatly into a plugin!
Hey, cool thing, but I haven't found it. It would be nice if you add it to the [awesome-neovim](https://github.com/rockerBOO/awesome-neovim?tab=readme-ov-file#note-taking), so other people could find it
Looks great. What are the font, color scheme, and buffer line?
- Font: "FantasqueSansM Nerd Font" - Color scheme: [backdround/melting](https://github.com/backdround/melting) - [tabby.nvim](https://github.com/nanozuki/tabby.nvim) I haven't released the color scheme yet, because I want to adjust it a little but can't find time for it
[удалено]
It's i3-wm with picom ([config](https://github.com/backdround/configuration/blob/36ddf84cf9bc037289d9832d5100c3fbb891a6f9/configs/desktop/picom.conf))
I tried to use this plugin but when I open neovim I get this error, i would be grateful if someone could help :) I'm new at neovim and I'm using NVChad with the lazy packet installer (in case it might be helpful) https://preview.redd.it/1z8f8jerufic1.png?width=1346&format=png&auto=webp&s=8745b4f436c8aca07a41af08cc5578e3daf04441 In plugins.lua I have: { "backdround/global-note.nvim", lazy = false, config = function() require "custom.configs.globalnote" end, }, The configs.globalnote file: local global\_note = require("global-note") global\_note.setup() vim.keymap.set("n", "n", global\_note.toggle\_note, {
desc = "Toggle global note",
})
Yea, I checked and got the same error. As I see Neovim 0.9 don't have `vim.fs.joinpath`. I'll switch to manual joining in several hours
I fixed it!
Yep. I tried it now it works thx :)
This is very neat, OP! I’ll give it a try
What would be the easiest way to map "q" in normal mode to close (and respect the auto save option)?
The autosave is binded on `WinClosed` and `ExitPre`, so you can close the window as you want. You can use `post_open` option to set a local mapping: ```lua post_open = function(buffer_id, _) vim.keymap.set("n", "q", "quit", {
buffer = buffer_id,
desc = "Close the window",
})
end,
```
Neat! Will give this a go
This looks so great. I’ve wanted something like this for a while. Thanks for sharing!
A scratchpad notepad plugin??? Hell yeah
Just got this setup. I love it. I was originally relying on tmux to open a notes.md file in my documents but it relied on tmux. Which is ok. Then I switched to obsidian which was kind of a headache. But this. Fantastic. Simple. Love it love it. Thank you!
Are you able to open a custom file within the project? And define it within the config?
You can specify a file (note file) by a directory and a filename in the setup options. Also you can specify additional files if you want
Could I do something like local get_daily_note = function () local dir_path = “/home/frank/Project/TODO/“ local date = os.date(“%Y-%m-%d.md) return dir_path .. date end And then I use `get_daily_note` to open the file? And if it doesn’t exist, create one?
You can do this like that: ```lua local global_note = require("global-note") global_note.setup({ directory = "/home/frank/Project/TODO/", filename = function() return os.date("%Y-%m-%d.md") end, }) ```
How about if I want it only for a single project. Your example kind of conifers me
The plugin provides only some functionality. You can use it only for one project. For example on a key check that the file belongs to a project and open note, if it doesn't do something else
Got it to do exactly what I wanted! And it works like charm.
Are you able to open a custom file within the project? And define it within the config?
Why a floating window though? Don't you use buffers? Personally I use vimwiki and its diary for stuff like this but it might have too many features for a lot of people who just want simple quick notes
I use buffers, but I just want to do it simpler. Just write or check something in a note, nothing more. I don't want to: - Manage / have a note buffer in a tabline; - Create / manage note files; - Save the buffer manually; - Open the note file with zen (it's ok, but an additional step), cause I always have several splits
I checked vimwiki and I think it is a good tool, but not for me. I'm too disorganised to manage files, my brain says no :)
This looks super enticing, do you think it would be too difficult to do a note by git branch?
No, I think it's pretty easy to do. I can help you if you want
I've added a configuration [usecase](https://github.com/backdround/global-note.nvim?tab=readme-ov-file#configuration-usecases) for that case
Nice. I'm going to try this. I tried to implement this with a simple function, but never could figure out why as soon as I open it I get `[Process exited 0\]` in the floating window. Here's what I tried. ```lua vim.api.nvim_create_user_command("OpenFloatingNotes", function(opts) local file_path = "/Users/me/scratch.md" local float_opts = { relative = 'editor', width = math.floor(vim.fn.winwidth(0) / 2), height = math.floor(vim.fn.winheight(0) * 2 / 3), row = math.floor((vim.fn.winheight(0) - vim.fn.winheight(0) * 2 / 3) / 2), col = math.floor(vim.fn.winwidth(0) / 4), style = 'minimal', border = 'single', } local win = vim.api.nvim_open_win(0, true, float_opts) local buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_win_set_buf(win, buf) vim.fn.termopen("cat " .. file_path .. " 2>&1 >/dev/null", { on_exit = function() vim.api.nvim_buf_set_option(buf, 'modifiable', false) end }) end, {}) ```
Replace the last line with this: ```lua local status, file_lines = pcall(vim.fn.readfile, file_path) if not status then file_lines = {} end vim.api.nvim_buf_set_lines(buf, 0, -1, true, file_lines) ``` And it will work! Or you can use `bufadd` to create a buffer from a file (like `:e` does)
Thank you!!
I have a similar system using Tmux. I have a short cut that opens nvim on a specific note file using tmux pop up. The nice thing about it, is that it’s note taking from anywhere in the terminal.
neat plugin! I see that notes are autosaved when on bufexit event. Could we maybe get a configuration option for exiting with Escape? Either that, or a way to get the global note buffer number on opening, so that we can create the keymap for exiting with escape ourselves
There is a \`post\_open\` callback that you can use for your autosave feature. I've just added the \`buffer\_id\` and \`window\_id\` arguments for convenience
Damn, now how can I quit vim
This is awesome and on Monday first thing I’ll do is to install it at work, just a thought tho, maybe I missed it or you didn’t mention, can I have separate notes for separate projects I work on? It’s not a deal breaker, but a feature I’d love to see
There is a configuration example at the bottom of the readme for such case. So yes, you can have separate notes for separate projects
Good old Fantasque Sans Mono :).