From 4143ec4a0bc75c3d9abf9c9d62d567a42e762458 Mon Sep 17 00:00:00 2001 From: simonkellet Date: Thu, 14 Oct 2021 11:55:28 +0100 Subject: [PATCH] added comments, remaps and git suport --- nvim/autoload/gemini_protocol.vim | 135 ++++++++++++++++++++++++++++++ nvim/init.vim | 42 +++++++++- nvim/spell/en.utf-8.add | 5 ++ nvim/spell/en.utf-8.add.spl | Bin 380 -> 442 bytes 4 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 nvim/autoload/gemini_protocol.vim diff --git a/nvim/autoload/gemini_protocol.vim b/nvim/autoload/gemini_protocol.vim new file mode 100644 index 0000000..6b12bd2 --- /dev/null +++ b/nvim/autoload/gemini_protocol.vim @@ -0,0 +1,135 @@ +if !has_key(g:, 'gemini_follow_redirects') + " Do not set to false with the current gmni version + " It doesn't output redirect header to stdout + " Only use with submodule version + let g:gemini_follow_redirects = v:true +endif +if !has_key(g:, 'gemini_max_redirects') + let g:gemini_max_redirects = 5 +endif +if !has_key(g:, 'gemini_gmni_command') + let g:gemini_gmni_command = shellescape(get(split(globpath(&rtp, 'gmni/gmni'), '\n'), 0, 'gmni')) +endif +if !has_key(g:, 'gemini_connect_with') + let g:gemini_connect_with = 'gmni' +endif + +let s:url_regexp = '\v^[^:]+:\/\/%([^\@]+\@)?([^:\/]+)%(:(\d+))?%(\/.*)?$' + +function! s:construct_command(url) + if g:gemini_connect_with ==? 'gmni' + return g:gemini_gmni_command . ' -j once -iN ' . (g:gemini_follow_redirects ? '-R ' . g:gemini_max_redirects . ' -L ' : '') . shellescape(a:url) . ' 2>/dev/null' + endif + + let l:domain = substitute(a:url, s:url_regexp, '\1', '') + let l:port = substitute(a:url, s:url_regexp, '\2', '') + if l:port == '' + let l:port = '1965' + endif + + if g:gemini_connect_with ==? 'openssl' + return 'echo ' . shellescape(a:url . "\r") . ' | openssl s_client -connect ' . shellescape(l:domain . ':' . l:port) . ' -quiet 2>/dev/null' + endif + + if g:gemini_connect_with ==? 'ncat' + return 'echo ' . shellescape(a:url) . ' | ncat -C --ssl --no-shutdown ' . shellescape(l:domain) . ' ' . shellescape(l:port) + endif + + echoerr 'Gemini: invalid gemini_connect_with value: ' . shellescape(g:gemini_connect_with) + return 'echo' +endfunction + +let s:redirects = 0 +function! s:read_gemini(url) + let l:svpos = winsaveview() + setlocal bl ro noswapfile bh=hide fenc= + if &ft == '' + setlocal ft=gmi + else + let &ft=&ft + endif + exe '%read ++bin !' . s:construct_command(a:url) + keepjumps normal! ggJ + let l:header = getline(1) + let b:gemini_header = l:header + keepjumps 1delete _ + keepjumps call winrestview(l:svpos) + if l:header[0] == '3' + let l:new_url = trim(l:header[3:]) + if has_key(g:, 'Gemini_redirect_function') && s:redirects < g:gemini_max_redirects + let s:redirects += 1 + let l:new_url = g:Gemini_redirect_function(l:new_url) + if type(l:new_url) == 1 + " String was returned + 0file + exe 'file ' . fnameescape(l:new_url) + return s:read_gemini(l:new_url) + endif + else + " This plugin doesn't know, how to join urls, + " '/...', '//...' are not handled properly by :find + call append(0, '=> ' . l:new_url . ' Redirect') + endif + let s:redirects = 0 + return + endif + let s:redirects = 0 + if l:header[0] == '1' + let l:url = matchstr(a:url, '\v^[^\?\#]+') . '?' . s:uriencode(input(l:header[3:] . ': ')) + 0file + exe 'file ' . fnameescape(l:url) + return s:read_gemini(l:url) + endif + if l:header[0] == '2' + return + endif + if l:header == '' + let l:header = 'No data' + endif + " Output doesn't seem to work from autocommands + function! s:error_message(...) closure + redraw + echohl WarningMsg + echomsg 'Gemini: ' . l:header + echohl None + endfunction + call timer_start(0, funcref('s:error_message')) + return +endfunction + +function! s:uriencode(str) + let l:res = '' + let l:digits = '0123456789ABCDEF' + for l:i in range(len(a:str)) + let l:c = a:str[l:i] + if match(l:c, '\v^[A-Za-z0-9_]$') == -1 + let l:n = char2nr(l:c) + let l:lo = l:digits[l:n % 16] + let l:hi = l:digits[l:n / 16] + let l:c = '%' . l:hi . l:lo + endif + let l:res .= l:c + endfor + return l:res +endfunction + +aug GeminiProtocol + au! + au BufReadCmd gemini://* exe "sil doau BufReadPre ".fnameescape(expand(""))|call s:read_gemini(expand(""))|exe "sil doau BufReadPost ".fnameescape(expand("")) + au FileReadCmd gemini://* exe "sil doau FileReadPre ".fnameescape(expand(""))|call s:read_gemini(expand(""))|exe "sil doau FileReadPost ".fnameescape(expand("")) +aug END + + + + + + + + + + + + + + + diff --git a/nvim/init.vim b/nvim/init.vim index b6fa756..bd6dd98 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -28,6 +28,18 @@ Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' } Plug 'nanotee/zoxide.vim' Plug 'vimwiki/vimwiki' Plug 'mattn/calendar-vim' +Plug 'camspiers/animate.vim' +Plug 'camspiers/lens.vim' +" Better Syntax Support +Plug 'sheerun/vim-polyglot' +" File Explorer +Plug 'scrooloose/NERDTree' +" Auto pairs for '(' '[' '{' +Plug 'jiangmiao/auto-pairs' + +" Git +Plug 'airblade/vim-gitgutter' +Plug 'tpope/vim-fugitive' call plug#end() let g:molokai_original = 1 @@ -45,14 +57,40 @@ set nocompatible let g:livepreview_previewer = 'zathura' +" Map Leader let mapleader = "," +" Note taking (Mardown, Spelling) let g:vimwiki_list = [{'path': '~/vimwiki/', \ 'syntax': 'markdown', 'ext': '.md'}] -:map :setlocal spell! spelllang=en +:map :setlocal spell! spelllang=en_gb +au BufNewFile ~/vimwiki/diary/*.md :silent 0r !~/.config/nvim/generate-vimwiki-diary-template '%' + let NERDTreeMapOpenInTab='' -au BufNewFile ~/vimwiki/diary/*.md :silent 0r !~/.config/nvim/generate-vimwiki-diary-template '%' +let g:fzf_nvim_statusline = 0 " disable statusline overwriting + +"remaps +nnoremap :Files +nnoremap a :Windows +nnoremap h :History + +" Switching windows +map h +map j +map k +map l + +" Basic cmd commands +nnoremap :!touch +nnoremap :!crf +nnoremap :!mdkir +nnoremap :!mv% + +" Indents +vmap < >gv + diff --git a/nvim/spell/en.utf-8.add b/nvim/spell/en.utf-8.add index 9c0d4b9..bd47619 100644 --- a/nvim/spell/en.utf-8.add +++ b/nvim/spell/en.utf-8.add @@ -23,3 +23,8 @@ init vimwiki PlugInstall mapleader +Todo +nvim +config +lol +CSCU9A3 diff --git a/nvim/spell/en.utf-8.add.spl b/nvim/spell/en.utf-8.add.spl index 705c6c27804306eb9346f93d7718bfdacffb2ae3..6f9638ce42c103b01b1be8519cc3e94d0bced9c2 100644 GIT binary patch literal 442 zcmY*VO>4t247IfGTyn|(Xa<4a)^-#E8;q6h9%3gkb>fiE9rt(k7kAm7+`=fvLehJZ zp7fEu44rW<`Bh5&tP5=_dv;CR4dXN~_nW%)12L1K9)F;ba%zc`iVJv6@C-5~S*l1; zK@)9(JP?0@%qw9WOJw?+>IyYhuyjOUhi5{sk#jH3J_(@XTsWG$K2UPf7h>Ae8NR0l zjVcVah=gj`%>&S!_J&Dn1sMH_9FH9K# literal 380 zcmY*V%WA_g5Zqb!;9D>G4nvYJC=`RCh0=oW#*!aIvW*?bJ@!xgDeXuug&?%rUCqpn zR2HwxWSu+xh{*S2ZEV|LoFAs;y56?r*bPvH#mv3niV6cDa;Ta4m|1r9A*5Nu=6nZh z3GWFI(jAwLlpu40erZKkZgiUCRRyyH@);NABR0}otduZ;m|IvKKXGFtl%C2psUsn* z4<-rm=w{X}F~gr17jDZvp5r4LG`mJ=(5bAnJ)onlAmH~ivxInh=;@|c;XiC~?8dLk hl9#s+Jn8D$En5r)YSdYE0p5ta|nhCBENG