-- Leo's gemini proxy

-- Connecting to atyh.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;

ATYH

-----------------------------------------------------------------------------

home

about me

contact info

-----------------------------------------------------------------------------

Creating a gemini markdown based Vimwiki style notes system in Vim


I created a notes system which uses gemini markdown in Vim. It operates in a similar way to vimwiki, but without any plugins. Now, when I change the working directory of Vim using :cd ~/my/directory, and open up or create the index.gmi (the start page for the notebook), I can write, create headings and lists as normal with # and *, and when I create a new link with "=> my-new-note.gmi Note description", and I place the cursor over my-new-note.gmi and hit <leader>gf, the document is created automatically, the link is created, and I can start writing in the new document. I probably dont need to explain the benefits of this. Your notebook can be dropped on a gemini server, and you have a working gemsite. No conversion required. You dont have to do this of course. You can just use it to manage notebooks. But I wanted one simple tool to do both. So now I will be managing all my notes, and my gemini site using the same system.


Here is what is required:

Vim (duh)

Gemini syntax highlighting (which can be found at the link below)

Gemini syntax highlighting for Vim

One line in your vimrc.


Optional:

An additional line in your vimrc which creates a simple snippet insert system with no additional plugins, so you can autowrite any header info like ascii art, or a navigation menu, etc.





How to set it up:


1. LINK CREATION:

To create new documents from links, you need the following line in your vimrc:


> nnoremap <leader>gf :edit %:h/<cfile><CR>


This line tells Vim, when you hover over a link like "=> my-link.gmi" in normal mode, and then press your leader key followed by g and f, it should create that file in the current directory, and open it in a new buffer, so you can start to write. Optionally, if you would rather it open in a new tab, you could use:


> nnoremap <leader>gf :tabedit %:h/<cfile><CR>


(If you would like more of a description of what this line of Vimscript does and why, I will include that at the bottom.)


This single line makes writing new posts seamless, and very quick. Now you can open your index.gmi in Vim, and write, "=> 2022-05-24-gemini-and-vim.gmi Gemini and Vim", place the cursor over the link, hit <leader>gf, and you're writing.



2.SNIPPET CREATION:

If you have ascii art, or page heading text which you use in every page, you dont want to have to type that out every time. Or maybe you do. But I dont.A simple way to make this quick is to create your own snippet engine in Vim. And this is very easy to do. First, add this line to your vimrc:


> nnoremap ,gmi :-1read $HOME/.vim/skeletons/skeleton.gmi<CR>


This command tells vim the following:

When you are in normal mode, with an open document, and you hit the keys ,gmi in succession, vim should read the contents of the file ~/.vim/skeletons/skeleton.gmi, and paste what is in that file to the current document. You could of course choose any location you want, like ~/Documents/snippets/ or whatever. The main point is, You can create a bunch of these lines in your vimrc each referencing different snippet documents, and create key bindings to insert whenever you like. I will describe with more detail what this command means, and how it works at the bottom.


So that is it. With these two simple lines, you have notes, or gemini site management with instant link creation, and a snippet engine you can create and manage yourself, all without plugins.


However...


Caveats:


This system works well (im using it right now as I write this), but it relies on one very specific caveat... No subdirectories. In order for it to work quicky and seamlessly, you cannot introduce subdirectories into the mix. This is not a problem for notes, as most note plugins for Vim (even Vimwiki) put all notes in one directory, and rely on links in the document for navigation. But when it comes to websites, many people believe they need subdirectories to keep things organized. I would like to challenge that paradigm, and offer the following idea:


Rather than creating a "posts" directory where you keep all of your posts, use file naming instead to organize your files, and keep them all in one directory. What I mean is this... Rather than /posts/my-post.gmi, name the file "post-2022-05-25-my-special-brilliant-post.gmi" and keep all of them in the same single directory. Why would you do this? You would be suprised by what this can do for you. First, this notes system will work for you. Second, by naming and dating your posts, they all group together in order in a sequential list in your file manager. Third, you can use simple unix tools to list, and manipulate files. When all of your files are in one directory, and you use file names as a sort of tagging system, you can do things like "ls ~/notes | grep "vim" which will show you all posts with "vim" in the name. In fact, you can take this idea much further (which I have). But that is a subject for another post. Ill leave it at, if this simple way of managing notes/gemsites appeals to you, subdirectories is all you lose out on.


Anyway, so this is what Ive done for myself, I hope it helps someone else!


GnuPG


If you want to add the ability to automatically encrypt certain notes, you can add jamessans's gnupg plugin for Vim which enables transparent editing of gnupg encrypted files. This way, when you write the link, you write" => secretnote.gpg", when you create the note it is encrypted automatically using your key. Read through the documentation with :help gnupg for instructions on how to set it up.


jamessan's gnupg plugin


-----------------------------------------------------------------------------


More about the Vim commands:


1.

> nnoremap <leader>gf :edit %:h/<cfile><CR>


nnoremap = a keybinding for normal mode

<leader> = whatever you have set your leader to with let mapleader=" " (\ by default)

gf = the keys g and f

:edit = (kinda self explanitory)

% = references the current file you have open in the buffer

:h/ = references the directory of the current file open in the buffer when it comes after %

*<cfile> = create file

<CR> = simulate the Enter key (carriage return)


Put them together and you get:

When in normal mode, and the leader key followed by g and f are pressed, take the link under the cursor and create that file so it can be edited, using the working directory of the file which is currently open. Enter.



2.

> nnoremap ,gmi :-1read $HOME/.vim/skeletons/skeleton.gmi<CR>


nnoremap = a keybinding for vim normal mode

,gmi = the keys comma, g, m, and i, pressed in succession

:-1read = read from the following file, and paste it into where the cursor is, minus one line.

<CR> = send vim a simulated Enter key press


Put them together and you get:

When in normal mode, and ,gmi are pressed, read from the file listed here, and insert it where the cursor is, then move the whole thing one line up. Enter.


-----------------------------------------------------------------------------


Send me a comment


go back to home


   *                .            .                .            .
           .     .      .              *     .          .
       *              .    .   *    .      .      *          *
            .     *    .      .   .    .       .    .    .        .
 .      .      .          .       /\      *                 .
           .       . /\ .  /\    /  \  *     /\    *    .
     *           *  /vv\ ./vv\  /vvvv\  /\  /vv\ .    .    .  .     *
         .    .    /    \/    \/      \/  \/    \
                  /     /      \           \     \  .        .
  .    ^         /     / __|_______.__||___       \      ^
      /|\       /       /   __        __   \       \    /|\    ^
     //|\\     /       /   |  |      [__]   \       \  //|\\  /|\
     //|\\    /    ,__|    | .|              |       \ //|\\ //|\\
     / | \   /        \____|__|_______^__^___/'       \/ | \ / | \
       |                |             0  0               |     |



-- Response ended

-- Page fetched on Sun May 19 06:32:04 2024