From 82b02ae2f2af439a8c678ed6b55a43121055f279 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 12 Oct 2024 11:23:31 +0200 Subject: fix(runtime): clean up one-off scripts Problem: Some runtime files no longer spark joy. Solution: Kondo the place up. Still sparks _some_ joy (moved to new `runtime/scripts` folder): * `macros/less.*` * `mswin.vim` * `tools/emoji_list.lua` No longer sparks joy (removed): * `macmap.vim` (gvimrc file; not useful in Nvim) * `tools/check_colors.vim` (no longer useful with new default colorscheme and treesitter) * `macros/editexisting.vim` (throws error on current Nvim) * `macros/justify.vim` (obsolete shim for `packadd! justify`) * `macros/matchit.vim` (same) * `macros/shellmenu.vim` (same) * `macros/swapmous.vim` (same) --- runtime/scripts/emoji_list.lua | 19 ++ runtime/scripts/less.bat | 10 + runtime/scripts/less.sh | 26 +++ runtime/scripts/less.vim | 407 +++++++++++++++++++++++++++++++++++++++++ runtime/scripts/mswin.vim | 149 +++++++++++++++ 5 files changed, 611 insertions(+) create mode 100644 runtime/scripts/emoji_list.lua create mode 100644 runtime/scripts/less.bat create mode 100755 runtime/scripts/less.sh create mode 100644 runtime/scripts/less.vim create mode 100644 runtime/scripts/mswin.vim (limited to 'runtime/scripts') diff --git a/runtime/scripts/emoji_list.lua b/runtime/scripts/emoji_list.lua new file mode 100644 index 0000000000..63bbbe4371 --- /dev/null +++ b/runtime/scripts/emoji_list.lua @@ -0,0 +1,19 @@ +-- Script to fill the window with emoji characters, one per line. +-- Source this script: :source % + +if vim.bo.modified then + vim.cmd.new() +else + vim.cmd.enew() +end + +local lnum = 1 +for c = 0x100, 0x1ffff do + local cs = vim.fn.nr2char(c) + if vim.fn.charclass(cs) == 3 then + vim.fn.setline(lnum, string.format('|%s| %d', cs, vim.fn.strwidth(cs))) + lnum = lnum + 1 + end +end + +vim.bo.modified = false diff --git a/runtime/scripts/less.bat b/runtime/scripts/less.bat new file mode 100644 index 0000000000..f80bf9209e --- /dev/null +++ b/runtime/scripts/less.bat @@ -0,0 +1,10 @@ +@echo off +rem batch file to start Vim with less.vim. +rem Read stdin if no arguments were given. +rem Written by Ken Takata. + +if "%1"=="" ( + nvim --cmd "let no_plugin_maps = 1" -c "runtime! scripts/less.vim" - +) else ( + nvim --cmd "let no_plugin_maps = 1" -c "runtime! scripts/less.vim" %* +) diff --git a/runtime/scripts/less.sh b/runtime/scripts/less.sh new file mode 100755 index 0000000000..4ff32b0529 --- /dev/null +++ b/runtime/scripts/less.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Shell script to start Vim with less.vim. +# Read stdin if no arguments were given and stdin was redirected. + +if test -t 1; then + if test $# = 0; then + if test -t 0; then + echo "Missing filename" 1>&2 + exit + fi + nvim --cmd 'let no_plugin_maps = 1' -c 'runtime! scripts/less.vim' - + else + nvim --cmd 'let no_plugin_maps = 1' -c 'runtime! scripts/less.vim' "$@" + fi +else + # Output is not a terminal, cat arguments or stdin + if test $# = 0; then + if test -t 0; then + echo "Missing filename" 1>&2 + exit + fi + cat + else + cat "$@" + fi +fi diff --git a/runtime/scripts/less.vim b/runtime/scripts/less.vim new file mode 100644 index 0000000000..8df29d96e6 --- /dev/null +++ b/runtime/scripts/less.vim @@ -0,0 +1,407 @@ +" Vim script to work like "less" +" Maintainer: The Vim Project +" Last Change: 2024 Feb 15 +" Former Maintainer: Bram Moolenaar + +" Avoid loading this file twice, allow the user to define his own script. +if exists("loaded_less") + finish +endif +let loaded_less = 1 + +" If not reading from stdin, skip files that can't be read. +" Exit if there is no file at all. +if argc() > 0 + let s:i = 0 + while 1 + if filereadable(argv(s:i)) + if s:i != 0 + sleep 3 + endif + break + endif + if isdirectory(argv(s:i)) + echomsg "Skipping directory " . argv(s:i) + elseif getftime(argv(s:i)) < 0 + echomsg "Skipping non-existing file " . argv(s:i) + else + echomsg "Skipping unreadable file " . argv(s:i) + endif + echo "\n" + let s:i = s:i + 1 + if s:i == argc() + quit + endif + next + endwhile +endif + +" we don't want 'compatible' here +if &cp + set nocp +endif + +" enable syntax highlighting if not done already +if !get(g:, 'syntax_on', 0) + syntax enable +endif + +set so=0 +set hlsearch +set incsearch +nohlsearch +" Don't remember file names and positions +set shada= +set nows +" Inhibit screen updates while searching +let s:lz = &lz +set lz + +" Allow the user to define a function, which can set options specifically for +" this script. +if exists('*LessInitFunc') + call LessInitFunc() +endif + +" Used after each command: put cursor at end and display position +if &wrap + noremap L L0:redraw:file + au VimEnter * normal! L0 +else + noremap L Lg0:redraw:file + au VimEnter * normal! Lg0 +endif + +" When reading from stdin don't consider the file modified. +au VimEnter * set nomod + +" Can't modify the text or write the file. +set nomodifiable readonly + +" Give help +noremap h :call Help() +map H h +fun! s:Help() + echo " One page forward b One page backward" + echo "d Half a page forward u Half a page backward" + echo " One line forward k One line backward" + echo "G End of file g Start of file" + echo "N% percentage in file" + echo "\n" + echo "/pattern Search for pattern ?pattern Search backward for pattern" + echo "n next pattern match N Previous pattern match" + if &foldmethod != "manual" + echo "\n" + echo "zR open all folds zm increase fold level" + endif + echo "\n" + echo ":n Next file :p Previous file" + echo "\n" + echo "q Quit v Edit file" + let i = input("Hit Enter to continue") +endfun + +" Scroll one page forward +noremap