This commit is contained in:
Elflare
2025-07-05 17:01:46 +08:00
parent 7e5ba72b71
commit 0a312d5796
4 changed files with 109 additions and 108 deletions

146
README.md
View File

@@ -6,7 +6,7 @@ A Neovim plugin to interact with [Memos](https://github.com/usememos/memos) righ
## ✨ Features ## ✨ Features
- **List Memos**: View, search, and paginate through your memos in a floating window. - **List Memos**: View, search, and paginate through your memos.
- **Create & Edit**: Create new memos or edit existing ones in a dedicated buffer with `markdown` filetype support. - **Create & Edit**: Create new memos or edit existing ones in a dedicated buffer with `markdown` filetype support.
- **Delete Memos**: Delete memos directly from the list. - **Delete Memos**: Delete memos directly from the list.
- **Customizable**: Configure API endpoints, keymaps, and more. - **Customizable**: Configure API endpoints, keymaps, and more.
@@ -19,51 +19,25 @@ Install with [lazy.nvim](https://github.com/folke/lazy.nvim):
```lua ```lua
-- lua/plugins/memos.lua -- lua/plugins/memos.lua
return { return {
-- Memos.nvim: A plugin to interact with Memos from within Neovim "Elflare/memos.nvim",
{ dependencies = { "nvim-lua/plenary.nvim" },
-- IMPORTANT: Replace with your actual GitHub username/repo config = function()
"your-github-username/memos.nvim", require("memos").setup({
host = "",
-- Optional, but good for identification in Lazy UI token = "",
name = "memos.nvim", pageSize = 50,
keymaps = {
dependencies = { "nvim-lua/plenary.nvim" }, list = {
add_memo = "a",
-- Load the plugin on these commands -- ... other list keymaps
cmd = { "Memos", "MemosCreate" }, },
buffer = {
config = function() save = "<leader>ms", -- Your desired save keymap
require("memos").setup({ },
-- REQUIRED: Your Memos host URL },
host = "https://your-memos-host.com", })
end,
-- REQUIRED: Your Memos API token (Open API)
token = "your-super-secret-token",
-- Optional: Customize keymaps
keymaps = {
-- Keymaps for the editing/creating buffer
buffer = {
save = "<leader>ms", -- Save the current memo
},
-- Keymaps for the memo list window
list = {
add_memo = "a", -- Add a new memo
edit_memo = "<CR>", -- Edit selected memo
-- ... other keymaps can be configured here
}
},
})
end,
},
-- Plenary is a required dependency
{
"nvim-lua/plenary.nvim",
lazy = true,
},
} }
``` ```
@@ -77,6 +51,12 @@ return {
### Default Keymaps ### Default Keymaps
#### Global
| Key | Action |
| ------------------ | ------------------------------------ |
| `<leader>mm` | Open the Memos list |
#### In the Memo List Window #### In the Memo List Window
| Key | Action | | Key | Action |
@@ -113,6 +93,9 @@ require("memos").setup({
-- Set to false or nil to disable a keymap -- Set to false or nil to disable a keymap
keymaps = { keymaps = {
-- Keymap to open the memos list. Default: <leader>mm
start_memos = "<leader>mm",
-- Keymaps for the memo list window -- Keymaps for the memo list window
list = { list = {
add_memo = "a", add_memo = "a",
@@ -143,7 +126,7 @@ require("memos").setup({
## ✨ 功能 ## ✨ 功能
- **列表 Memos**: 在浮动窗口中查看、搜索和翻页你的 memos。 - **列表 Memos**: 查看、搜索和翻页你的 memos。
- **创建与编辑**: 在专用的、支持 `markdown` 文件类型的缓冲区中创建新 memo 或编辑现有 memo。 - **创建与编辑**: 在专用的、支持 `markdown` 文件类型的缓冲区中创建新 memo 或编辑现有 memo。
- **删除 Memos**: 直接从列表中删除 memo。 - **删除 Memos**: 直接从列表中删除 memo。
- **可定制**: 可配置 API 地址、快捷键等。 - **可定制**: 可配置 API 地址、快捷键等。
@@ -156,51 +139,25 @@ require("memos").setup({
```lua ```lua
-- lua/plugins/memos.lua -- lua/plugins/memos.lua
return { return {
-- Memos.nvim: 一个在 Neovim 中与 Memos 交互的插件 "Elflare/memos.nvim",
{ dependencies = { "nvim-lua/plenary.nvim" },
-- 重要: 请将这里替换为你的 GitHub 用户名/仓库名 config = function()
"your-github-username/memos.nvim", require("memos").setup({
host = "",
-- 可选,但在 Lazy 管理界面中易于识别 token = "",
name = "memos.nvim", pageSize = 50,
keymaps = {
dependencies = { "nvim-lua/plenary.nvim" }, list = {
add_memo = "a",
-- 在执行这些命令时加载插件 -- ... 其他列表快捷键
cmd = { "Memos", "MemosCreate" }, },
buffer = {
config = function() save = "<leader>ms", -- 这是您想要的保存快捷键
require("memos").setup({ },
-- 必填: 你的 Memos 服务地址 },
host = "https://your-memos-host.com", })
end,
-- 必填: 你的 Memos API 令牌 (Open API)
token = "your-super-secret-token",
-- 可选: 自定义快捷键
keymaps = {
-- 编辑/创建窗口的快捷键
buffer = {
save = "<leader>ms", -- 保存当前 memo
},
-- memo 列表窗口的快捷键
list = {
add_memo = "a", -- 新增 memo
edit_memo = "<CR>", -- 编辑所选 memo
-- ... 其他快捷键也可以在这里配置
}
},
})
end,
},
-- Plenary 是一个必要的依赖
{
"nvim-lua/plenary.nvim",
lazy = true,
},
} }
``` ```
@@ -214,6 +171,12 @@ return {
### 默认快捷键 ### 默认快捷键
#### 全局快捷键
| 按键 | 功能 |
| ------------------ | ---------------------------------- |
| `<leader>mm` | 打开 Memos 列表 |
#### 在 Memo 列表窗口中 #### 在 Memo 列表窗口中
| 按键 | 功能 | | 按键 | 功能 |
@@ -250,6 +213,9 @@ require("memos").setup({
-- 设置为 false 或 nil 可以禁用某个快捷键 -- 设置为 false 或 nil 可以禁用某个快捷键
keymaps = { keymaps = {
-- 用于打开 Memos 列表的快捷键。默认值: <leader>mm
start_memos = "<leader>mm",
-- memo 列表窗口的快捷键 -- memo 列表窗口的快捷键
list = { list = {
add_memo = "a", add_memo = "a",

View File

@@ -39,22 +39,24 @@ Install with |lazy.nvim|:
>lua >lua
-- lua/plugins/memos.lua -- lua/plugins/memos.lua
return { return {
{ "Elflare/memos.nvim",
"your-github-username/memos.nvim", dependencies = { "nvim-lua/plenary.nvim" },
name = "memos.nvim", config = function()
dependencies = { "nvim-lua/plenary.nvim" }, require("memos").setup({
cmd = { "Memos", "MemosCreate" }, host = "",
config = function() token = "",
require("memos").setup({ pageSize = 50,
host = "https://your-memos-host.com", keymaps = {
token = "your-super-secret-token", list = {
}) add_memo = "a",
end, -- ... other list keymaps
}, },
{ buffer = {
"nvim-lua/plenary.nvim", save = "<leader>ms", -- Your desired save keymap
lazy = true, },
}, },
})
end,
} }
< <
============================================================================== ==============================================================================
@@ -74,6 +76,11 @@ COMMANDS *memos-commands*
DEFAULT KEYMAPS *memos-keymaps* DEFAULT KEYMAPS *memos-keymaps*
*Global Keymap:*
| Key | Action |
|--------------------|--------------------------------------|
| `<leader>mm` | Open the Memos list |
*In the Memo List Window:* *In the Memo List Window:*
| Key | Action | | Key | Action |
|--------------------|--------------------------------------| |--------------------|--------------------------------------|
@@ -111,6 +118,9 @@ require("memos").setup({
-- Set to false or nil to disable a keymap -- Set to false or nil to disable a keymap
keymaps = { keymaps = {
-- Keymap to open the memos list. Default: <leader>mm
start_memos = "<leader>mm",
-- Keymaps for the memo list window -- Keymaps for the memo list window
list = { list = {
add_memo = "a", add_memo = "a",

View File

@@ -5,6 +5,7 @@ M.config = {
token = nil, token = nil,
pageSize = 50, pageSize = 50,
keymaps = { keymaps = {
start_memos = "<leader>mm",
-- 在列表窗口中的快捷键 -- 在列表窗口中的快捷键
list = { list = {
add_memo = "a", add_memo = "a",
@@ -30,6 +31,15 @@ function M.setup(opts)
if not M.config.host or not M.config.token then if not M.config.host or not M.config.token then
vim.notify("Memos: `host` and `token` must be configured.", vim.log.levels.ERROR) vim.notify("Memos: `host` and `token` must be configured.", vim.log.levels.ERROR)
end end
if M.config.keymaps.start_memos then
vim.api.nvim_set_keymap(
"n",
M.config.keymaps.start_memos,
"<Cmd>Memos<CR>",
{ noremap = true, silent = true, desc = "Open Memos list" }
)
end
end end
function M.create_memo() function M.create_memo()

View File

@@ -1,4 +1,4 @@
-- 创建 Memo 命令 -- 创建 :MemosCreate 命令
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
'MemosCreate', 'MemosCreate',
function() function()
@@ -10,7 +10,7 @@ vim.api.nvim_create_user_command(
} }
) )
-- 【新增】查看 Memos 列表的命令 -- 创建 :Memos 命令
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
'Memos', 'Memos',
function() function()
@@ -21,3 +21,18 @@ vim.api.nvim_create_user_command(
desc = "List and search your Memos" desc = "List and search your Memos"
} }
) )
-- 【新增】创建启动快捷键
-- 使用 vim.schedule 确保在所有插件加载后执行,避免 require('memos') 失败
vim.schedule(function()
-- 我们需要先加载 memos 模块才能读取它的配置
local memos_config = require('memos').config
local key = memos_config.keymaps.start_memos
if key and key ~= "" then
vim.keymap.set('n', key, '<Cmd>Memos<CR>', {
noremap = true,
silent = true,
desc = "Open Memos list"
})
end
end)