Skip to content

Commit dbe6c12

Browse files
Marc TalcottMarc Talcott
authored andcommitted
Add obsidian and nvim-tmux-navigator
1 parent f5d2078 commit dbe6c12

File tree

3 files changed

+326
-0
lines changed

3 files changed

+326
-0
lines changed

init.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ vim.keymap.set('n', '<leader>wc', '<C-w>c', { desc = '[C]lose window' })
196196
vim.keymap.set('n', '<leader>w+', '<C-w>+', { desc = 'Increase size' })
197197
vim.keymap.set('n', '<leader>w-', '<C-w>-', { desc = 'Decrease size' })
198198

199+
vim.keymap.set('n', '<c-k>', ':wincmd k<CR>')
200+
vim.keymap.set('n', '<c-j>', ':wincmd j<CR>')
201+
vim.keymap.set('n', '<c-h>', ':wincmd h<CR>')
202+
vim.keymap.set('n', '<c-l>', ':wincmd l<CR>')
203+
199204
-- vim.keymap.set('n', '<leader>wh', '<C-w><C-h>', { desc = 'Move focus to the left window' })
200205
-- vim.keymap.set('n', '<leader>wl', '<C-w><C-l>', { desc = 'Move focus to the right window' })
201206
-- vim.keymap.set('n', '<leader>wj', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
@@ -281,3 +286,6 @@ vim.keymap.set('n', '-', '<CMD>Oil<CR>', { desc = 'Open parent directory' })
281286

282287
-- Neogit plugin
283288
vim.keymap.set('n', '<Leader>gg', ':Neogit<CR>', { desc = 'Neogit open' })
289+
290+
-- set conceal level bc obsidian plugin requires this:
291+
vim.opt.conceallevel = 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
return {
2+
'christoomey/vim-tmux-navigator',
3+
vim.keymap.set('n', 'C-h', ':TmuxNavigatorLeft<CR>'),
4+
vim.keymap.set('n', 'C-j', ':TmuxNavigatorDown<CR>'),
5+
vim.keymap.set('n', 'C-k', ':TmuxNavigatorUp<CR>'),
6+
vim.keymap.set('n', 'C-l', ':TmuxNavigatorRight<CR>'),
7+
}

lua/plugins/obsidian.lua

Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
return {
2+
'epwalsh/obsidian.nvim',
3+
version = '*', -- recommended, use latest release instead of latest commit
4+
lazy = true,
5+
ft = 'markdown',
6+
-- Replace the above line with this if you only want to load obsidian.nvim for markdown files in your vault:
7+
-- event = {
8+
-- -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand'.
9+
-- -- E.g. "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/**.md"
10+
-- "BufReadPre path/to/my-vault/**.md",
11+
-- "BufNewFile path/to/my-vault/**.md",
12+
-- },
13+
dependencies = {
14+
-- Required.
15+
'nvim-lua/plenary.nvim',
16+
17+
-- see below for full list of optional dependencies 👇
18+
},
19+
config = function()
20+
require('obsidian').setup {
21+
workspaces = {
22+
{
23+
name = 'personal',
24+
path = '~/Library/Mobile Documents/iCloud~md~obsidian/Documents/MarcsDailyNotes',
25+
},
26+
{
27+
name = 'commonplace',
28+
path = '~/Library/Mobile Documents/iCloud~md~obsidian/Documents/Marcs Common Place Vault',
29+
},
30+
{
31+
name = 'archive',
32+
path = '~/Library/Mobile Documents/iCloud~md~obsidian/Documents/ArchivedTalcottUniverse',
33+
},
34+
},
35+
notes_subdir = 'notes',
36+
log_level = vim.log.levels.INFO,
37+
daily_notes = {
38+
-- Optional, if you keep daily notes in a separate directory.
39+
folder = 'notes/dailies',
40+
-- Optional, if you want to change the date format for the ID of daily notes.
41+
date_format = '%Y-%m-%d',
42+
-- Optional, if you want to change the date format of the default alias of daily notes.
43+
alias_format = '%B %-d, %Y',
44+
-- Optional, default tags to add to each new daily note created.
45+
default_tags = { 'daily-notes' },
46+
-- Optional, if you want to automatically insert a template from your template directory like 'daily.md'
47+
template = nil,
48+
},
49+
-- Optional, completion of wiki links, local markdown links, and tags using nvim-cmp.
50+
completion = {
51+
-- Set to false to disable completion.
52+
nvim_cmp = true,
53+
-- Trigger completion at 2 chars.
54+
min_chars = 2,
55+
},
56+
57+
-- Optional, configure key mappings. These are the defaults. If you don't want to set any keymappings this
58+
-- way then set 'mappings = {}'.
59+
mappings = {
60+
-- Overrides the 'gf' mapping to work on markdown/wiki links within your vault.
61+
['gf'] = {
62+
action = function()
63+
return require('obsidian').util.gf_passthrough()
64+
end,
65+
opts = { noremap = false, expr = true, buffer = true },
66+
},
67+
-- Toggle check-boxes.
68+
['<leader>ch'] = {
69+
action = function()
70+
return require('obsidian').util.toggle_checkbox()
71+
end,
72+
opts = { buffer = true },
73+
},
74+
-- Smart action depending on context, either follow link or toggle checkbox.
75+
['<cr>'] = {
76+
action = function()
77+
return require('obsidian').util.smart_action()
78+
end,
79+
opts = { buffer = true, expr = true },
80+
},
81+
}, -- end mappings
82+
83+
-- Where to put new notes. Valid options are
84+
-- * "current_dir" - put new notes in same directory as the current buffer.
85+
-- * "notes_subdir" - put new notes in the default notes subdirectory.
86+
new_notes_location = 'notes_subdir',
87+
88+
-- Optional, customize how note IDs are generated given an optional title.
89+
---@param title string|?
90+
---@return string
91+
note_id_func = function(title)
92+
-- Create note IDs in a Zettelkasten format with a timestamp and a suffix.
93+
-- In this case a note with the title 'My new note' will be given an ID that looks
94+
-- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md'
95+
local suffix = ''
96+
if title ~= nil then
97+
-- If title is given, transform it into valid file name.
98+
suffix = title:gsub(' ', '-'):gsub('[^A-Za-z0-9-]', ''):lower()
99+
else
100+
-- If title is nil, just add 4 random uppercase letters to the suffix.
101+
for _ = 1, 4 do
102+
suffix = suffix .. string.char(math.random(65, 90))
103+
end
104+
end
105+
return tostring(os.time()) .. '-' .. suffix
106+
end,
107+
108+
-- Optional, customize how note file names are generated given the ID, target directory, and title.
109+
---@param spec { id: string, dir: obsidian.Path, title: string|? }
110+
---@return string|obsidian.Path The full path to the new note.
111+
note_path_func = function(spec)
112+
-- This is equivalent to the default behavior.
113+
local path = spec.dir / tostring(spec.id)
114+
return path:with_suffix '.md'
115+
end,
116+
117+
-- Optional, customize how wiki links are formatted. You can set this to one of:
118+
-- * "use_alias_only", e.g. '[[Foo Bar]]'
119+
-- * "prepend_note_id", e.g. '[[foo-bar|Foo Bar]]'
120+
-- * "prepend_note_path", e.g. '[[foo-bar.md|Foo Bar]]'
121+
-- * "use_path_only", e.g. '[[foo-bar.md]]'
122+
-- Or you can set it to a function that takes a table of options and returns a string, like this:
123+
wiki_link_func = function(opts)
124+
return require('obsidian.util').wiki_link_id_prefix(opts)
125+
end,
126+
127+
-- Optional, customize how markdown links are formatted.
128+
markdown_link_func = function(opts)
129+
return require('obsidian.util').markdown_link(opts)
130+
end,
131+
132+
-- Either 'wiki' or 'markdown'.
133+
preferred_link_style = 'wiki',
134+
135+
-- Optional, customize the default name or prefix when pasting images via `:ObsidianPasteImg`.
136+
---@return string
137+
image_name_func = function()
138+
-- Prefix image names with timestamp.
139+
return string.format('%s-', os.time())
140+
end,
141+
142+
-- Optional, boolean or a function that takes a filename and returns a boolean.
143+
-- `true` indicates that you don't want obsidian.nvim to manage frontmatter.
144+
disable_frontmatter = false,
145+
146+
-- Optional, alternatively you can customize the frontmatter data.
147+
---@return table
148+
note_frontmatter_func = function(note)
149+
-- Add the title of the note as an alias.
150+
if note.title then
151+
note:add_alias(note.title)
152+
end
153+
154+
local out = { id = note.id, aliases = note.aliases, tags = note.tags }
155+
156+
-- `note.metadata` contains any manually added fields in the frontmatter.
157+
-- So here we just make sure those fields are kept in the frontmatter.
158+
if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
159+
for k, v in pairs(note.metadata) do
160+
out[k] = v
161+
end
162+
end
163+
164+
return out
165+
end,
166+
167+
-- Optional, for templates (see below).
168+
templates = {
169+
folder = '3 Resources/Templates',
170+
date_format = '%Y-%m-%d',
171+
time_format = '%H:%M',
172+
-- A map for custom variables, the key should be the variable and the value a function
173+
substitutions = {},
174+
},
175+
176+
-- Optional, by default when you use `:ObsidianFollowLink` on a link to an external
177+
-- URL it will be ignored but you can customize this behavior here.
178+
---@param url string
179+
follow_url_func = function(url)
180+
-- Open the URL in the default web browser.
181+
vim.fn.jobstart { 'open', url } -- Mac OS
182+
-- vim.fn.jobstart({"xdg-open", url}) -- linux
183+
end,
184+
185+
-- Optional, set to true if you use the Obsidian Advanced URI plugin.
186+
-- https://github.com/Vinzent03/obsidian-advanced-uri
187+
use_advanced_uri = false,
188+
189+
-- Optional, set to true to force ':ObsidianOpen' to bring the app to the foreground.
190+
open_app_foreground = false,
191+
192+
picker = {
193+
-- Set your preferred picker. Can be one of 'telescope.nvim', 'fzf-lua', or 'mini.pick'.
194+
name = 'telescope.nvim',
195+
-- Optional, configure key mappings for the picker. These are the defaults.
196+
-- Not all pickers support all mappings.
197+
mappings = {
198+
-- Create a new note from your query.
199+
new = '<C-x>',
200+
-- Insert a link to the selected note.
201+
insert_link = '<C-l>',
202+
},
203+
},
204+
205+
-- Optional, sort search results by "path", "modified", "accessed", or "created".
206+
-- The recommend value is "modified" and `true` for `sort_reversed`, which means, for example,
207+
-- that `:ObsidianQuickSwitch` will show the notes sorted by latest modified time
208+
sort_by = 'modified',
209+
sort_reversed = true,
210+
211+
-- Set the maximum number of lines to read from notes on disk when performing certain searches.
212+
search_max_lines = 1000,
213+
214+
-- Optional, determines how certain commands open notes. The valid options are:
215+
-- 1. "current" (the default) - to always open in the current window
216+
-- 2. "vsplit" - to open in a vertical split if there's not already a vertical split
217+
-- 3. "hsplit" - to open in a horizontal split if there's not already a horizontal split
218+
open_notes_in = 'current',
219+
220+
-- Optional, define your own callbacks to further customize behavior.
221+
callbacks = {
222+
-- Runs at the end of `require("obsidian").setup()`.
223+
---@param client obsidian.Client
224+
post_setup = function(client) end,
225+
226+
-- Runs anytime you enter the buffer for a note.
227+
---@param client obsidian.Client
228+
---@param note obsidian.Note
229+
enter_note = function(client, note) end,
230+
231+
-- Runs anytime you leave the buffer for a note.
232+
---@param client obsidian.Client
233+
---@param note obsidian.Note
234+
leave_note = function(client, note) end,
235+
236+
-- Runs right before writing the buffer for a note.
237+
---@param client obsidian.Client
238+
---@param note obsidian.Note
239+
pre_write_note = function(client, note) end,
240+
241+
-- Runs anytime the workspace is set/changed.
242+
---@param client obsidian.Client
243+
---@param workspace obsidian.Workspace
244+
post_set_workspace = function(client, workspace) end,
245+
},
246+
247+
-- Optional, configure additional syntax highlighting / extmarks.
248+
-- This requires you have `conceallevel` set to 1 or 2. See `:help conceallevel` for more details.
249+
ui = {
250+
enable = true, -- set to false to disable all additional syntax features
251+
update_debounce = 200, -- update delay after a text change (in milliseconds)
252+
max_file_length = 5000, -- disable UI features for files with more than this many lines
253+
-- Define how various check-boxes are displayed
254+
checkboxes = {
255+
-- NOTE: the 'char' value has to be a single character, and the highlight groups are defined below.
256+
[' '] = { char = '󰄱', hl_group = 'ObsidianTodo' },
257+
['x'] = { char = '', hl_group = 'ObsidianDone' },
258+
['>'] = { char = '', hl_group = 'ObsidianRightArrow' },
259+
['~'] = { char = '󰰱', hl_group = 'ObsidianTilde' },
260+
['!'] = { char = '', hl_group = 'ObsidianImportant' },
261+
-- Replace the above with this if you don't have a patched font:
262+
-- [" "] = { char = "☐", hl_group = "ObsidianTodo" },
263+
-- ["x"] = { char = "✔", hl_group = "ObsidianDone" },
264+
265+
-- You can also add more custom ones...
266+
},
267+
-- Use bullet marks for non-checkbox lists.
268+
bullets = { char = '', hl_group = 'ObsidianBullet' },
269+
external_link_icon = { char = '', hl_group = 'ObsidianExtLinkIcon' },
270+
-- Replace the above with this if you don't have a patched font:
271+
-- external_link_icon = { char = "", hl_group = "ObsidianExtLinkIcon" },
272+
reference_text = { hl_group = 'ObsidianRefText' },
273+
highlight_text = { hl_group = 'ObsidianHighlightText' },
274+
tags = { hl_group = 'ObsidianTag' },
275+
block_ids = { hl_group = 'ObsidianBlockID' },
276+
hl_groups = {
277+
-- The options are passed directly to `vim.api.nvim_set_hl()`. See `:help nvim_set_hl`.
278+
ObsidianTodo = { bold = true, fg = '#f78c6c' },
279+
ObsidianDone = { bold = true, fg = '#89ddff' },
280+
ObsidianRightArrow = { bold = true, fg = '#f78c6c' },
281+
ObsidianTilde = { bold = true, fg = '#ff5370' },
282+
ObsidianImportant = { bold = true, fg = '#d73128' },
283+
ObsidianBullet = { bold = true, fg = '#89ddff' },
284+
ObsidianRefText = { underline = true, fg = '#c792ea' },
285+
ObsidianExtLinkIcon = { fg = '#c792ea' },
286+
ObsidianTag = { italic = true, fg = '#89ddff' },
287+
ObsidianBlockID = { italic = true, fg = '#89ddff' },
288+
ObsidianHighlightText = { bg = '#75662e' },
289+
},
290+
},
291+
292+
-- Specify how to handle attachments.
293+
attachments = {
294+
-- The default folder to place images in via `:ObsidianPasteImg`.
295+
-- If this is a relative path it will be interpreted as relative to the vault root.
296+
-- You can always override this per image by passing a full path to the command instead of just a filename.
297+
img_folder = '3 Resources/Assets/imgs', -- This is the default
298+
-- A function that determines the text to insert in the note when pasting an image.
299+
-- It takes two arguments, the `obsidian.Client` and an `obsidian.Path` to the image file.
300+
-- This is the default implementation.
301+
---@param client obsidian.Client
302+
---@param path obsidian.Path the absolute path to the image file
303+
---@return string
304+
img_text_func = function(client, path)
305+
path = client:vault_relative_path(path) or path
306+
return string.format('![%s](%s)', path.name, path)
307+
end,
308+
},
309+
}
310+
end,
311+
}

0 commit comments

Comments
 (0)