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

View File

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

View File

@@ -5,6 +5,7 @@ M.config = {
token = nil,
pageSize = 50,
keymaps = {
start_memos = "<leader>mm",
-- 在列表窗口中的快捷键
list = {
add_memo = "a",
@@ -30,6 +31,15 @@ function M.setup(opts)
if not M.config.host or not M.config.token then
vim.notify("Memos: `host` and `token` must be configured.", vim.log.levels.ERROR)
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
function M.create_memo()

View File

@@ -1,4 +1,4 @@
-- 创建 Memo 命令
-- 创建 :MemosCreate 命令
vim.api.nvim_create_user_command(
'MemosCreate',
function()
@@ -10,7 +10,7 @@ vim.api.nvim_create_user_command(
}
)
-- 【新增】查看 Memos 列表的命令
-- 创建 :Memos 命令
vim.api.nvim_create_user_command(
'Memos',
function()
@@ -21,3 +21,18 @@ vim.api.nvim_create_user_command(
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)