mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Merge branch 'main' into special_links
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
- [ ] yt video
|
||||
|
||||
## Dones
|
||||
- [x] preview images
|
||||
- [x] insert link to image, with preview
|
||||
- [x] sorting file picker: devicons, ...
|
||||
- [x] dailies and weeklies: don't display whole paths: fix entries: display values
|
||||
- [x] added option parameter `i` to `toggle_todo(opts)` and `insert_link(opts)` to enter insert mode.
|
||||
- [x] find_friends()
|
||||
|
||||
196
README.md
196
README.md
@@ -1,6 +1,7 @@
|
||||
# telekasten.nvim
|
||||
|
||||
A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](https://takesmartnotes.com/) / Wiki and mixing it with a journal, based on [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim).
|
||||
A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](https://takesmartnotes.com/) / Wiki and
|
||||
mixing it with a journal, based on [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim).
|
||||
|
||||
#### Highlights:
|
||||
|
||||
@@ -14,18 +15,29 @@ A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](htt
|
||||
- calendar support
|
||||
- paste images from clipboard
|
||||
- toggle [ ] todo status of line
|
||||
- insert links to images
|
||||
- **image previews**, via extension _(Linux only)_
|
||||
|
||||
##### New features are being announced in the [discussions](https://github.com/renerocksai/telekasten.nvim/discussions)!
|
||||
|
||||
---
|
||||
|
||||
Telekasten.nvim can optionally plug into [calendar-vim](https://github.com/renerocksai/calendar-vim): Selecting a day in the calendar will open up a telescope search with preview that lets you open the daily note (or cancel out and keep browsing your calendar). The daily note will be created if it doesn't exist. Days with daily notes get marked in the calendar.
|
||||
Telekasten.nvim can optionally plug into [calendar-vim](https://github.com/renerocksai/calendar-vim): Selecting a day in
|
||||
the calendar will open up a telescope search with preview that lets you open the daily note (or cancel out and keep
|
||||
browsing your calendar). The daily note will be created if it doesn't exist. Days with daily notes get marked in the
|
||||
calendar.
|
||||
|
||||
If you have `xclip` installed, Telekasten.nvim can even **paste images from the clipboard** into a dedicated sub-directory and insert a wiki or markdown link at the current cursor position!
|
||||
If you have `xclip` installed, Telekasten.nvim can even **paste images from the clipboard** into a dedicated
|
||||
sub-directory and insert a wiki or markdown link at the current cursor position!
|
||||
|
||||
After having written the infamous [sublime_zk](https://github.com/renerocksai/sublime_zk) for SublimeText, having moved on to my standalone [sublimeless_zk](https://github.com/renerocksai/sublimeless_zk), having tried [Roam Research](https://roamresearch.com) and [Obsidian.md](https://obsidian.md) (which I still use sparingly), I have eventually arrived back at the editor I feel at home the most: Neovim 😄! I can literally **live** inside of nvim now, not only for writing code.
|
||||
After having written the infamous [sublime_zk](https://github.com/renerocksai/sublime_zk) for SublimeText, having moved
|
||||
on to my standalone [sublimeless_zk](https://github.com/renerocksai/sublimeless_zk), having tried
|
||||
[Roam Research](https://roamresearch.com) and [Obsidian.md](https://obsidian.md) (which I still use sparingly), I have
|
||||
eventually arrived back at the editor I feel at home the most: Neovim 😄! I can literally **live** inside of nvim now,
|
||||
not only for writing code.
|
||||
|
||||
This is the result of my first days of hacking neovim with lua (more features have been added since, see [Use it](#use-it) below the screenshots):
|
||||
This is the result of my first days of hacking neovim with lua (more features have been added since, see
|
||||
[Use it](#2-use-it) below the screenshots):
|
||||
|
||||

|
||||
|
||||
@@ -35,12 +47,18 @@ This is the result of my first days of hacking neovim with lua (more features ha
|
||||
|
||||
## Search-based navigation
|
||||
|
||||
Every navigation action, like following a link, is centered around a Telescope search: a Telescope search popup is opened, and in the case of following a link, the search-text is pre-filled with the target. So, instead of opening the linked note, you get a preview in Telescope and can decide if you actually want to go there. Since the search is often likely to show up more than one result, you can preview related notes immediately.
|
||||
Every navigation action, like following a link, is centered around a Telescope search: a Telescope search popup is
|
||||
opened, and in the case of following a link, the search-text is pre-filled with the target. So, instead of opening the
|
||||
linked note, you get a preview in Telescope and can decide if you actually want to go there. Since the search is often
|
||||
likely to show up more than one result, you can preview related notes immediately.
|
||||
|
||||
### The preview is a powerful feature
|
||||
Leaving the opening of the note to Telescope, you can decide with one keypress whether you want to open the note in a split or in the current window - or if you've seen enough.
|
||||
Leaving the opening of the note to Telescope, you can decide with one keypress whether you want to open the note in a
|
||||
split or in the current window - or if you've seen enough.
|
||||
|
||||
I find that pressing the enter key to confirm the search does not interrupt my flow, and I really enjoy being able to check the preview. I often get enough information from it alone so I don't actually have to "visit" every note in terms of being able to edit it.
|
||||
I find that pressing the enter key to confirm the search does not interrupt my flow, and I really enjoy being able to
|
||||
check the preview. I often get enough information from it alone so I don't actually have to "visit" every note in terms
|
||||
of being able to edit it.
|
||||
|
||||
|
||||
## Contents
|
||||
@@ -48,45 +66,53 @@ I find that pressing the enter key to confirm the search does not interrupt my f
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
* [Install and setup](#install-and-setup)
|
||||
* [0. Prerequisites](#0-prerequisites)
|
||||
* [Telescope](#telescope)
|
||||
* [calendar-vim Plugin (optional)](#calendar-vim-plugin-optional)
|
||||
* [For pasting images: xclip (optional)](#for-pasting-images-xclip-optional)
|
||||
* [1. Install the plugin](#1-install-the-plugin)
|
||||
* [Other useful plugins](#other-useful-plugins)
|
||||
* [2. Configure telekasten.nvim](#2-configure-telekastennvim)
|
||||
* [3. Configure your own colors](#3-configure-your-own-colors)
|
||||
* [Get Help](#get-help)
|
||||
* [Use it](#use-it)
|
||||
* [Note templates](#note-templates)
|
||||
* [Template files](#template-files)
|
||||
* [Using the calendar](#using-the-calendar)
|
||||
* [Bind it](#bind-it)
|
||||
* [The hardcoded stuff](#the-hardcoded-stuff)
|
||||
* [0. Install and setup](#0-install-and-setup)
|
||||
* [0.0 Prerequisites](#00-prerequisites)
|
||||
* [0.0.1 Telescope](#001-telescope)
|
||||
* [0.0.2 calendar-vim Plugin (optional)](#002-calendar-vim-plugin-optional)
|
||||
* [0.0.3 For pasting images: xclip (optional)](#003-for-pasting-images-xclip-optional)
|
||||
* [0.0.4 For image previews: telescope-media-files.nvim (optional)](#004-for-image-previews-telescope-media-filesnvim-optional)
|
||||
* [0.1 Install the plugin](#01-install-the-plugin)
|
||||
* [0.1.0 Other useful plugins](#010-other-useful-plugins)
|
||||
* [0.2 Configure telekasten.nvim](#02-configure-telekastennvim)
|
||||
* [0.3 Configure your own colors](#03-configure-your-own-colors)
|
||||
* [1. Get Help](#1-get-help)
|
||||
* [2. Use it](#2-use-it)
|
||||
* [3. Note templates](#3-note-templates)
|
||||
* [3.1 Template files](#31-template-files)
|
||||
* [3.2 Using the calendar](#32-using-the-calendar)
|
||||
* [4. Bind it](#4-bind-it)
|
||||
* [5. The hardcoded stuff](#5-the-hardcoded-stuff)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Install and setup
|
||||
## 0. Install and setup
|
||||
|
||||
|
||||
### 0. Prerequisites
|
||||
### 0.0 Prerequisites
|
||||
|
||||
#### Telescope
|
||||
#### 0.0.1 Telescope
|
||||
Since this plugin uses [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim), you need to install it first.
|
||||
|
||||
[Neovim (v0.5.1)](https://github.com/neovim/neovim/releases/tag/v0.5.1) or the latest neovim nighly commit is required for `telescope.nvim` to work.
|
||||
[Neovim (v0.5.1)](https://github.com/neovim/neovim/releases/tag/v0.5.1) or the latest neovim nighly commit is required
|
||||
for `telescope.nvim` to work.
|
||||
|
||||
---
|
||||
|
||||
#### calendar-vim Plugin (optional)
|
||||
#### 0.0.2 calendar-vim Plugin (optional)
|
||||
|
||||
Telekasten.nvim can optionally plug into **my bugfixed version of** [calendar-vim](https://github.com/renerocksai/calendar-vim): Selecting a day in the calendar will open up a telescope search with preview that lets you open the daily note (or cancel out). The daily note will be created if it doesn't exist. Days with daily notes get marked in the calendar.
|
||||
Telekasten.nvim can optionally plug into **my bugfixed version of**
|
||||
[calendar-vim](https://github.com/renerocksai/calendar-vim): Selecting a day in the calendar will open up a telescope
|
||||
search with preview that lets you open the daily note (or cancel out). The daily note will be created if it doesn't
|
||||
exist. Days with daily notes get marked in the calendar.
|
||||
|
||||
See below for installing and using it.
|
||||
|
||||
#### For pasting images: xclip (optional)
|
||||
Telekasten.nvim supports pasting images from the clipboard. Currently, this is
|
||||
only implemented for systems that have the `xclip` utility installed.
|
||||
---
|
||||
|
||||
#### 0.0.3 For pasting images: xclip (optional)
|
||||
Telekasten.nvim supports pasting images from the clipboard. Currently, this is only implemented for systems that have
|
||||
the `xclip` utility installed.
|
||||
|
||||
On Ubuntu/Debian like systems:
|
||||
|
||||
@@ -94,20 +120,43 @@ On Ubuntu/Debian like systems:
|
||||
$ sudo apt-get install xclip
|
||||
```
|
||||
|
||||
### 1. Install the plugin
|
||||
---
|
||||
|
||||
#### 0.0.4 For image previews: telescope-media-files.nvim (optional)
|
||||
|
||||
**ONLY supported on Linux**
|
||||
|
||||
To preview images, PDFs, etc. in Telescope while searching for an image to insert a link to, you need to install the
|
||||
Telescope extension [telescope-media-files.nvim](https://github.com/nvim-telescope/telescope-media-files.nvim).
|
||||
|
||||
This extension has its own list of prerequisites, of which I recommend (and use) the following:
|
||||
|
||||
* [Überzug](https://github.com/seebye/ueberzug) (required for image support)
|
||||
* [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer) (optional, for video preview support)
|
||||
* [pdftoppm](https://linux.die.net/man/1/pdftoppm) (optional, for pdf preview support)
|
||||
|
||||
Here is a demo from the original authors of
|
||||
[telescope-media-files.nvim](https://github.com/nvim-telescope/telescope-media-files.nvim):
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
### 0.1 Install the plugin
|
||||
Install with your plugin manager of choice. Mine is [Vundle](https://github.com/VundleVim/Vundle.vim).
|
||||
|
||||
```vim
|
||||
Plugin 'renerocksai/telekasten.nvim'
|
||||
```
|
||||
|
||||
I higly recommend using the calendar integration. For that you'll need [calendar-vim](https://github.com/renerocksai/calendar-vim):
|
||||
I higly recommend using the calendar integration. For that you'll need
|
||||
[calendar-vim](https://github.com/renerocksai/calendar-vim):
|
||||
|
||||
```vim
|
||||
Plugin 'renerocksai/calendar-vim'
|
||||
```
|
||||
|
||||
#### Other useful plugins
|
||||
#### 0.1.0 Other useful plugins
|
||||
|
||||
Other plugins I find useful in my day-to-day zettelkasten work:
|
||||
|
||||
@@ -116,7 +165,7 @@ Other plugins I find useful in my day-to-day zettelkasten work:
|
||||
- [vim-markdown-toc](https://github.com/mzlogin/vim-markdown-toc)
|
||||
- [telescope-media-files](https://github.com/nvim-telescope/telescope-media-files.nvim)
|
||||
|
||||
### 2. Configure telekasten.nvim
|
||||
### 0.2 Configure telekasten.nvim
|
||||
Somewhere in your vim config, put a snippet like this:
|
||||
|
||||
```lua
|
||||
@@ -206,14 +255,15 @@ The calendar support has its own options, contained in `calendar_opts`:
|
||||
| | 'right' : mark to the right of the day| |
|
||||
|
||||
|
||||
### 3. Configure your own colors
|
||||
### 0.3 Configure your own colors
|
||||
Telekasten.nvim allows you to color your `[[links]]` by providing two syntax groups:
|
||||
|
||||
- `tkLink` : the link title inside the brackets
|
||||
- `tkBrackets` : the brackets surrounding the link title
|
||||
- `tkHighlight` : ==highlighted== text (non-standard markdown)
|
||||
|
||||
The last one, `tkHighlight`, has nothing to do with links but I added it anyway, since I like highlighting text when taking notes 😄.
|
||||
The last one, `tkHighlight`, has nothing to do with links but I added it anyway, since I like highlighting text when
|
||||
taking notes 😄.
|
||||
|
||||
You can assign colors to the new syntax groups in your `init.vim`:
|
||||
|
||||
@@ -231,7 +281,7 @@ hi tkBrackets ctermfg=gray
|
||||
hi tkHighlight ctermbg=yellow ctermfg=darkred cterm=bold
|
||||
```
|
||||
|
||||
## Get Help
|
||||
## 1. Get Help
|
||||
Telekasten.nvim now comes with its own help file. So you can always:
|
||||
|
||||
```vim
|
||||
@@ -244,32 +294,52 @@ or
|
||||
|
||||
or .. **just use telescope**: `:Telescope help_tags` and search for `telekasten`.
|
||||
|
||||
## Use it
|
||||
## 2. Use it
|
||||
|
||||
The plugin defines the following functions.
|
||||
|
||||
- `new_note()` : prompts for title and creates new note by template, then shows it in Telescope
|
||||
- `new_templated_note()` : prompts for title and then uses telescope for choosing a template. When a template is selected, a new note is created with it and opened. Should the note exist, it is opened immediately
|
||||
- `new_templated_note()` : prompts for title and then uses telescope for choosing a template. When a template is
|
||||
selected, a new note is created with it and opened. Should the note exist, it is opened immediately
|
||||
- `find_notes()` : find notes by file name (title), via Telescope
|
||||
- `find_daily_notes()` : find daily notes by date (file names, sorted, most recent first), via Telescope. If today's daily note is not present, it can be created optionally, honoring the configured template
|
||||
- `goto_today()` : pops up a Telescope window with today's daily note pre-selected. Today's note can optionally be created if not present, using the configured template
|
||||
- `find_weekly_notes()` : find weekly notes by week (file names, sorted, most recent first), via Telescope. If this week's weekly note is not present, it can be created optionally, honoring the configured template
|
||||
- `goto_thisweek()` : pops up a Telescope window with this week's weekly note pre-selected. This week's note can optionally be created if not present, using the configured template
|
||||
- `find_daily_notes()` : find daily notes by date (file names, sorted, most recent first), via Telescope. If today's
|
||||
daily note is not present, it can be created optionally, honoring the configured template
|
||||
- `goto_today()` : pops up a Telescope window with today's daily note pre-selected. Today's note can optionally be
|
||||
created if not present, using the configured template
|
||||
- `find_weekly_notes()` : find weekly notes by week (file names, sorted, most recent first), via Telescope. If this
|
||||
week's weekly note is not present, it can be created optionally, honoring the configured template
|
||||
- `goto_thisweek()` : pops up a Telescope window with this week's weekly note pre-selected. This week's note can
|
||||
optionally be created if not present, using the configured template
|
||||
- `search_notes()`: live grep for word under cursor in all notes (search in notes), via Telescope
|
||||
- `insert_link()` : select a note by name, via Telescope, and place a `[[link]]` at the current cursor position
|
||||
- **note**:
|
||||
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#bind-it).
|
||||
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is
|
||||
useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#4-bind-it).
|
||||
- example: `insert_link({ i=true })`
|
||||
- `follow_link()`: take text between brackets (linked note) and open a Telescope file finder with it: selects note to open (incl. preview) - with optional note creation for non-existing notes, honoring the configured template
|
||||
- `follow_link()`: take text between brackets (linked note) and open a Telescope file finder with it: selects note to
|
||||
open (incl. preview) - with optional note creation for non-existing notes, honoring the configured template
|
||||
- `yank_notelink()` : yank a link to the current note, ready to paste
|
||||
- `show_calendar()` : opens up the calendar in a properly-sized vertical split at the very right
|
||||
- `paste_img_and_link()` : pastes an image from the clipboard into a file under `image_subdir` and inserts a link to it at the current cursor position
|
||||
- `paste_img_and_link()` : pastes an image from the clipboard into a file under `image_subdir` and inserts a link to it
|
||||
at the current cursor position
|
||||
- `toggle_todo()` : turn a line into a `- [ ] ` line, or toggle between `- [ ]`, `- [x]`, and `- `.
|
||||
- **note**:
|
||||
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#bind-it).
|
||||
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is
|
||||
useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#4-bind-it).
|
||||
- example: `toggle_todo({ i=true })`
|
||||
- `show_backlinks()` : opens a telescope search for notes that `[[link]]` back to the current note.
|
||||
- `find_friends()` : opens a telescope search for notes that also `[[link]]` to the link under the cursor.
|
||||
- `insert_img_link()` : opens a telescope search for all media (PDFs, images, videos (MP4, webm)) and places a markdown
|
||||
image link to the picked one at the cursor position.
|
||||
- **note**:
|
||||
- if the `telescope-media-files.nvim` plugin is installed, **a preview of images / media files will be given**
|
||||
during the search.
|
||||
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is
|
||||
useful for being able to continue to type after link insertion. See also: [Bind it](#4-bind-it).
|
||||
- example: `insert_link({ i=true })`
|
||||
- `preview_img()` : uses the `telescope-media-files.nvim` extension to preview the image / media file under the cursor
|
||||
of a markdown image link: ``. The cursor must be between `(the two parenthesis)`.
|
||||
- **note**: this requires the `telescope-media-files.nvim` plugin to be installed.
|
||||
- `setup(opts)`: used for configuring paths, file extension, etc.
|
||||
|
||||
To use one of the functions above, just run them with the `:lua ...` command.
|
||||
@@ -278,9 +348,11 @@ To use one of the functions above, just run them with the `:lua ...` command.
|
||||
:lua require("telekasten").find_daily_notes()
|
||||
```
|
||||
|
||||
### Note templates
|
||||
### 3. Note templates
|
||||
|
||||
The functions `goto_today`, `goto_thisweek`, `find_daily_notes`, `find_weekly_notes`, and `follow_link` can create non-existing notes. This allows you to 'go to today' without having to create today's note beforehand. When you just type `[[some link]]` and then call `follow_link`, the 'some link' note can be generated.
|
||||
The functions `goto_today`, `goto_thisweek`, `find_daily_notes`, `find_weekly_notes`, and `follow_link` can create
|
||||
non-existing notes. This allows you to 'go to today' without having to create today's note beforehand. When you just
|
||||
type `[[some link]]` and then call `follow_link`, the 'some link' note can be generated.
|
||||
|
||||
The following table shows which command relies on what config option:
|
||||
|
||||
@@ -297,9 +369,10 @@ The following table shows which command relies on what config option:
|
||||
|
||||
If the associated option is `true`, non-existing notes will be created.
|
||||
|
||||
#### Template files
|
||||
#### 3.1 Template files
|
||||
|
||||
The options `template_new_note`, `template_new_daily`, and `template_new_weekly` are used to specify the paths to template text files that are used for creating new notes.
|
||||
The options `template_new_note`, `template_new_daily`, and `template_new_weekly` are used to specify the paths to
|
||||
template text files that are used for creating new notes.
|
||||
|
||||
Currently, the following substitutions will be made during new note creation:
|
||||
|
||||
@@ -353,12 +426,15 @@ date: {{hdate}}
|
||||
## Sunday link
|
||||
```
|
||||
|
||||
### Using the calendar
|
||||
### 3.2 Using the calendar
|
||||
|
||||
When invoking `show_calendar()`, a calendar showing the previous, current, and next month is shown at the right side of vim.
|
||||
When invoking `show_calendar()`, a calendar showing the previous, current, and next month is shown at the right side of
|
||||
vim.
|
||||
|
||||
- days that have a daily note associated with them are marked with a + sign and a different color
|
||||
- pressing enter on a day will open up a telescope finder with the associated daily note selected and previewed. The daily note will be created if it doesn't exist. If you choose to not open the note, you will return to the calender so you can preview other notes.
|
||||
- pressing enter on a day will open up a telescope finder with the associated daily note selected and previewed. The
|
||||
daily note will be created if it doesn't exist. If you choose to not open the note, you will return to the calender so
|
||||
you can preview other notes.
|
||||
|
||||
If you want to see a big calendar showing the current month that fills your entire window, you can issue the following
|
||||
command in vim:
|
||||
@@ -367,7 +443,7 @@ command in vim:
|
||||
:CalendarT
|
||||
```
|
||||
|
||||
## Bind it
|
||||
## 4. Bind it
|
||||
Usually, you would set up some key bindings, though:
|
||||
|
||||
```vim
|
||||
@@ -386,6 +462,8 @@ nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR>
|
||||
nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
|
||||
nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
|
||||
nnoremap <leader>zF :lua require('telekasten').find_friends()<CR>
|
||||
nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR>
|
||||
nnoremap <leader>zp :lua require('telekasten').preview_img()<CR>
|
||||
|
||||
" we could define [[ in **insert mode** to call insert link
|
||||
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
|
||||
@@ -404,7 +482,7 @@ hi tkBrackets ctermfg=gray
|
||||
hi tkHighlight ctermbg=yellow ctermfg=darkred cterm=bold
|
||||
```
|
||||
|
||||
## The hardcoded stuff
|
||||
## 5. The hardcoded stuff
|
||||
|
||||
Currently, the following things are hardcoded:
|
||||
- the file naming format for daily note files: `YYYY-MM-DD.ext` (e.g. `2021-11-21.md`)
|
||||
|
||||
@@ -436,6 +436,33 @@ telekasten.find_friends()~
|
||||
Opens a telescope search for notes that also `[[link]]` to the link under the
|
||||
cursor.
|
||||
|
||||
*telekasten.insert_img_link()*
|
||||
telekasten.insert_img_link({opts})~
|
||||
Opens a telescope search for all media (PDFs, images, videos (MP4, webm)) and
|
||||
places a markdown image link to the picked one at the cursor position.
|
||||
|
||||
Note:~
|
||||
If the `telescope-media-files.nvim` plugin is installed, a preview of
|
||||
images / media files will be given during the search.
|
||||
|
||||
Valid keys for {opts}
|
||||
|
||||
i:~
|
||||
If `true`, it will enter input mode by pressing the <A> key. This is useful
|
||||
for being able to continue typing after the link has been inserted.
|
||||
See also: |telekasten.mappings|
|
||||
|
||||
Default: `nil`
|
||||
|
||||
*telekasten.preview_img()*
|
||||
telekasten.preview_img()~
|
||||
Uses the `telescope-media-files.nvim` extension to preview the image / media
|
||||
file under the cursor of a markdown image link: ``. The
|
||||
cursor must be between `(the two parenthesis)`.
|
||||
|
||||
Note:~
|
||||
This requires the `telescope-media-files.nvim` plugin to be installed.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
Section 3.1: Templates *telekasten.templates*
|
||||
|
||||
@@ -565,6 +592,8 @@ However, here are some suggestions:
|
||||
nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
|
||||
nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
|
||||
nnoremap <leader>zF :lua require('telekasten').find_friends()<CR>
|
||||
nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR>
|
||||
nnoremap <leader>zp :lua require('telekasten').preview_img()<CR>
|
||||
|
||||
" we could define [[ in **insert mode** to call insert link
|
||||
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
|
||||
|
||||
@@ -6,6 +6,7 @@ local finders = require("telescope.finders")
|
||||
local conf = require("telescope.config").values
|
||||
local scan = require("plenary.scandir")
|
||||
local utils = require("telescope.utils")
|
||||
local previewers = require("telescope.previewers")
|
||||
|
||||
-- declare locals for the nvim api stuff to avoid more lsp warnings
|
||||
local vim = vim
|
||||
@@ -219,12 +220,31 @@ local function create_note_from_template(title, filepath, templatefn, calendar_i
|
||||
ofile:close()
|
||||
end
|
||||
|
||||
local function num_path_elems(p)
|
||||
return #vim.split(p, "/")
|
||||
end
|
||||
|
||||
local function path_to_linkname(p)
|
||||
local fn = vim.split(p, "/")
|
||||
fn = fn[#fn]
|
||||
fn = vim.split(fn, M.Cfg.extension)
|
||||
fn = fn[1]
|
||||
return fn
|
||||
local ln
|
||||
|
||||
local special_dir = false
|
||||
if num_path_elems(p:gsub(M.Cfg.dailies .. "/", "")) == 1 then
|
||||
ln = p:gsub(M.Cfg.dailies .. "/", "")
|
||||
special_dir = true
|
||||
end
|
||||
|
||||
if num_path_elems(p:gsub(M.Cfg.weeklies .. "/", "")) == 1 then
|
||||
ln = p:gsub(M.Cfg.weeklies .. "/", "")
|
||||
special_dir = true
|
||||
end
|
||||
|
||||
if special_dir == false then
|
||||
ln = p:gsub(M.Cfg.home .. "/", "")
|
||||
end
|
||||
|
||||
local title = vim.split(ln, M.Cfg.extension)
|
||||
title = title[1]
|
||||
return title
|
||||
end
|
||||
|
||||
local function order_numeric(a, b)
|
||||
@@ -256,6 +276,33 @@ local function filter_filetypes(flist, ftypes)
|
||||
return new_fl
|
||||
end
|
||||
|
||||
local media_files_base_directory = "../telescope-media-files.nvim"
|
||||
local defaulter = utils.make_default_callable
|
||||
local media_preview = defaulter(function(opts)
|
||||
local preview_cmd = media_files_base_directory .. "/scripts/vimg"
|
||||
if vim.fn.executable(preview_cmd) == 0 then
|
||||
return conf.file_previewer(opts)
|
||||
end
|
||||
return previewers.new_termopen_previewer({
|
||||
get_command = opts.get_command or function(entry)
|
||||
local tmp_table = vim.split(entry.value, "\t")
|
||||
local preview = opts.get_preview_window()
|
||||
opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
|
||||
if vim.tbl_isempty(tmp_table) then
|
||||
return { "echo", "" }
|
||||
end
|
||||
return {
|
||||
preview_cmd,
|
||||
tmp_table[1],
|
||||
preview.col,
|
||||
preview.line + 1,
|
||||
preview.width,
|
||||
preview.height,
|
||||
}
|
||||
end,
|
||||
})
|
||||
end, {})
|
||||
|
||||
-- find_files_sorted(opts)
|
||||
-- like builtin.find_files, but:
|
||||
-- - uses plenary.scan_dir synchronously instead of external jobs
|
||||
@@ -265,11 +312,14 @@ end
|
||||
-- - displays subdirs if necessary
|
||||
-- - e.g. when searching for daily notes, no subdirs are displayed
|
||||
-- - but when entering a date in find_notes, the daily/ and weekly/ subdirs are displayed
|
||||
-- - optionally previews media (pdf, images, mp4, webm)
|
||||
-- - this requires the telescope-media-files.nvim extension
|
||||
local function find_files_sorted(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local file_list = scan.scan_dir(opts.cwd, {})
|
||||
file_list = filter_filetypes(file_list, M.Cfg.filter_extensions)
|
||||
local filter_extensions = opts.filter_extensions or M.Cfg.filter_extensions
|
||||
file_list = filter_filetypes(file_list, filter_extensions)
|
||||
table.sort(file_list, order_numeric)
|
||||
|
||||
-- display with devicons
|
||||
@@ -292,6 +342,12 @@ local function find_files_sorted(opts)
|
||||
end
|
||||
end
|
||||
|
||||
-- for media_files
|
||||
local popup_opts = {}
|
||||
opts.get_preview_window = function()
|
||||
return popup_opts.preview
|
||||
end
|
||||
|
||||
local function make_entry(entry)
|
||||
local iconic_entry = {}
|
||||
iconic_entry.value = entry
|
||||
@@ -300,14 +356,29 @@ local function find_files_sorted(opts)
|
||||
return iconic_entry
|
||||
end
|
||||
|
||||
pickers.new(opts, {
|
||||
local previewer = conf.file_previewer(opts)
|
||||
if opts.preview_type == "media" then
|
||||
previewer = media_preview.new(opts)
|
||||
end
|
||||
|
||||
local picker = pickers.new(opts, {
|
||||
finder = finders.new_table({
|
||||
results = file_list,
|
||||
entry_maker = make_entry,
|
||||
}),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
previewer = conf.file_previewer(opts),
|
||||
}):find()
|
||||
|
||||
previewer = previewer,
|
||||
})
|
||||
|
||||
-- for media_files:
|
||||
local line_count = vim.o.lines - vim.o.cmdheight
|
||||
if vim.o.laststatus ~= 0 then
|
||||
line_count = line_count - 1
|
||||
end
|
||||
popup_opts = picker:get_window_options(vim.o.columns, line_count)
|
||||
|
||||
picker:find()
|
||||
end
|
||||
|
||||
--
|
||||
@@ -419,6 +490,40 @@ local function FollowLink(opts)
|
||||
})
|
||||
end
|
||||
|
||||
--
|
||||
-- PreviewImg:
|
||||
-- -----------
|
||||
--
|
||||
-- preview media
|
||||
--
|
||||
local function PreviewImg(_)
|
||||
vim.cmd("normal yi)")
|
||||
local fname = vim.fn.getreg('"0')
|
||||
|
||||
-- check if fname exists anywhere
|
||||
local fexists = file_exists(M.Cfg.home .. "/" .. fname)
|
||||
|
||||
if fexists == true then
|
||||
find_files_sorted({
|
||||
prompt_title = "Preview image/media",
|
||||
cwd = M.Cfg.home,
|
||||
default_text = fname,
|
||||
find_command = M.Cfg.find_command,
|
||||
filter_extensions = { ".png", ".jpg", ".bmp", ".gif", ".pdf", ".mp4", ".webm" },
|
||||
preview_type = "media",
|
||||
|
||||
attach_mappings = function(prompt_bufnr, _)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
else
|
||||
print("File not found: " .. M.Cfg.home .. "/" .. fname)
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- FindFriends:
|
||||
-- -----------
|
||||
@@ -501,6 +606,37 @@ local function FindNotes(_)
|
||||
})
|
||||
end
|
||||
|
||||
--
|
||||
-- InsertImgLink:
|
||||
-- --------------
|
||||
--
|
||||
-- Insert link to image / media, with optional preview
|
||||
--
|
||||
local function InsertImgLink(opts)
|
||||
opts = opts or {}
|
||||
find_files_sorted({
|
||||
prompt_title = "Find image/media",
|
||||
cwd = M.Cfg.home,
|
||||
find_command = M.Cfg.find_command,
|
||||
filter_extensions = { ".png", ".jpg", ".bmp", ".gif", ".pdf", ".mp4", ".webm" },
|
||||
preview_type = "media",
|
||||
|
||||
attach_mappings = function(prompt_bufnr, _)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
local fn = selection.value
|
||||
fn = fn:gsub(M.Cfg.home .. "/", "")
|
||||
vim.api.nvim_put({ "" }, "", false, true)
|
||||
if opts.i then
|
||||
vim.api.nvim_feedkeys("A", "m", false)
|
||||
end
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
--
|
||||
-- SearchNotes:
|
||||
-- ------------
|
||||
@@ -774,7 +910,7 @@ local function Setup(cfg)
|
||||
end
|
||||
|
||||
-- TODO: this is obsolete:
|
||||
if vim.fn.executable("rg") then
|
||||
if vim.fn.executable("rg") == 1 then
|
||||
M.Cfg.find_command = { "rg", "--files", "--sortr", "created" }
|
||||
else
|
||||
M.Cfg.find_command = nil
|
||||
@@ -831,5 +967,7 @@ M.paste_img_and_link = imgFromClipboard
|
||||
M.toggle_todo = ToggleTodo
|
||||
M.show_backlinks = ShowBacklinks
|
||||
M.find_friends = FindFriends
|
||||
M.insert_img_link = InsertImgLink
|
||||
M.preview_img = PreviewImg
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user