Skip to content

Commit 9d62ac7

Browse files
authored
Merge pull request #1 from jakebark/config
config
2 parents a68a138 + 8e7b098 commit 9d62ac7

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
# notes.nvim
22

3-
4-
<img src="./img/demo.gif" width="650">
3+
Persistent notes window in neovim.
54

65
## Installation
76

87
packer:
9-
```
8+
```lua
109
use('jakebark/notes.nvim')
1110
```
1211
vim plug:
13-
```
12+
```lua
1413
use('jakebark/notes.nvim')
1514
```
1615
lazy:
17-
```
16+
```lua
1817
{
1918
'jakebark/notes.nvim',
2019
config = function() require("notes") end,
2120
}
2221
```
2322
manual:
24-
```
23+
```bash
2524
git clone https://github.com/jakebark/notes.nvim.git ~/.local/share/nvim/site/pack/notes/start/notes.nvim
2625
```
2726

27+
## Configuration
28+
29+
```lua
30+
require("notes").setup({
31+
height = 20, -- window height
32+
width = 80, -- window width
33+
relative_numbers = true, -- false for absolute
34+
notes_file_path = "~/notes.md" -- path to your notes file
35+
})
36+
```
2837

lua/notes.lua

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
local M = {}
22

3+
-- default config
4+
local config = {
5+
height = 20,
6+
width = 80,
7+
relative_numbers = true, -- false for absolute
8+
notes_file_path = vim.fn.expand("$HOME") .. "/notes.md" -- default notes file path
9+
}
10+
11+
-- overide default config
12+
function M.setup(user_config)
13+
user_config = user_config or {}
14+
config = vim.tbl_deep_extend("force", config, user_config)
15+
end
16+
317
function M.open_notes()
4-
local notes_file = vim.fn.expand("$HOME") .. "/notes.md"
18+
local notes_file = config.notes_file_path
519

620
if not vim.fn.filereadable(notes_file) then
721
vim.fn.writefile({}, notes_file)
@@ -29,21 +43,23 @@ function M.open_notes()
2943
vim.api.nvim_buf_set_option(buf, "filetype", "markdown")
3044
vim.api.nvim_buf_set_option(buf, "buftype", "")
3145

32-
local width = 80
33-
local height = 20
34-
3546
local win = vim.api.nvim_open_win(buf, true, {
3647
relative = 'editor',
3748
row = math.floor((vim.o.lines - height) / 2),
3849
col = math.floor((vim.o.columns - width) / 2),
39-
width = width,
40-
height = height,
50+
width = config.width,
51+
height = config.width,
4152
style = 'minimal',
4253
border = 'single',
4354
})
4455

45-
vim.api.nvim_buf_set_option(buf, 'number', true)
46-
vim.api.nvim_buf_set_option(buf, 'relativenumber', true)
56+
if config.relative_numbers then
57+
vim.api.nvim_buf_set_option(buf, 'relativenumber', true)
58+
vim.api.nvim_buf_set_option(buf, 'number', true)
59+
else
60+
vim.api.nvim_buf_set_option(buf, 'number', true)
61+
vim.api.nvim_buf_set_option(buf, 'relativenumber', false)
62+
end
4763

4864
-- focus on floating window
4965
vim.api.nvim_set_current_win(win)

0 commit comments

Comments
 (0)