-- Leo's gemini proxy

-- Connecting to drsudo.com:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

 _
/ \
| |     ,----------------------------------,
| |    | ,---.,---.   ,---.,-.,-.,---.,---. \
|  \___| | O || O_|  (  --'| || || O || O |  \
|   ___| |   || \ \   )-- \| \/ ||   ||   |   |=====-
|  /   | |__/ |_|_|. (____)\____/|__/ \___/  /
| |    |                                    /
| |     '=================================='
\_/                                            -SBR-

Editing gmi files in Vim


I love how simple the gmi file format is. It is a relief to be able to freely type without thinking much about formatting. The only hangup I have had in editing it has been that line breaks are all literal. I appreciate the simplicity of this, but it makes editing it a bit of a pain, especially in Vim.


With Vim, when you navigate up or down a line, it moves you a full line, irrespective of display lines. So if this line is wrapped to take three lines on the screen, Vim will move the cursor three lines down when I press down (ie j in Vim). However :help gj shows that there are variants of the keys to move by display lines. So with some quick mappings, we have intuitive cursor movements:


nnoremap <buffer> j gj
nnoremap <buffer> k gk
vnoremap <buffer> j gj
vnoremap <buffer> k gk
snoremap <buffer> j gj
snoremap <buffer> k gk

nnoremap <buffer> $ g$
nnoremap <buffer> ^ g^
vnoremap <buffer> $ g$
vnoremap <buffer> ^ g^
snoremap <buffer> $ g$
snoremap <buffer> ^ g^

That done, there is the annoyance of how wide the text is. With no line breaks, the text is as wide as the terminal is. My terminals are generally fullscreen, so that is a couple hundred columns. This is not easy to read, so I limit the screen width with a vertical split:


setlocal wrap linebreak

vnew | wincmd p | vertical resize 80 |

The set makes Vim wrap lines at word breaks. The three commands below that open a new vertical split and set the width to 80 columns. Now I can use the rest of the horizontal window space for other things.


This is almost usable, except whenever I resize the terminal, the split width is automatically resized. Fortunately Vim provides a VimResized autocommand that can be used to remedy this.


autocmd VimResized <buffer> * vertical resize 80 | redraw!

No whenever I resize the terminal, my split is kept at 80 columns. This is still not an absolutely perfect solution, but it is surprisingly workable for how hacky it looks.


I put this in a ftplugin file called gmi.vim which looks like this:


" Copyright Stephen Robinson, 2020
" Published under 3-Clause BSD License

setlocal spell wrap linebreak

command -buffer SoftWrap
      \ vnew |
      \ wincmd p |
      \ vertical resize 80 |
      \ autocmd VimResized <buffer> * vertical resize 80 | redraw!

nnoremap <buffer> j gj
nnoremap <buffer> k gk
vnoremap <buffer> j gj
vnoremap <buffer> k gk
snoremap <buffer> j gj
snoremap <buffer> k gk

nnoremap <buffer> $ g$
nnoremap <buffer> ^ g^
vnoremap <buffer> $ g$
vnoremap <buffer> ^ g^
snoremap <buffer> $ g$
snoremap <buffer> ^ g^

For now I am a happy camper with this.


<= Back to my gemlog


stephen@drsudo.com

CC BY-SA 4.0

-- Response ended

-- Page fetched on Thu Oct 28 05:14:39 2021