~geb/tiles

ceadb51cee684c1cb999e82e5737e5565693e277 — John Gebbie 6 months ago 97d990f
temp add tiles-editor
2 files changed, 396 insertions(+), 0 deletions(-)

A bin/tiles-editor
A etc/nvim/init.vim
A bin/tiles-editor => bin/tiles-editor +2 -0
@@ 0,0 1,2 @@
#!/bin/sh
exec nvim -u /etc/tiles/nvim/init.vim "$@"

A etc/nvim/init.vim => etc/nvim/init.vim +394 -0
@@ 0,0 1,394 @@
" TODO timeout (surrounding and Escape)
" TODO easy capitalize
" TODO force spaces in commentstring?
" TODO stop : indenting
" TODO gc indenting
" TODO add :help?
" TODO fix gC on blank line above
" TODO gc breaks with end all the line comment
" TODO substitute prompt/shortcut
" TODO mb show substitute split
" TODO make macros repeatable with . (note @: repeats a command)
" TODO 2. after gc
"#TODO change in argument target: (...,  or  ,...,  or  ,...)
" TODO shorthand for c-x c-l
" ... is it possible to auto complete lines after c-x c-l
" TODO ca"

" Set the <Leader> key used in mappings to the Space key
let mapleader=" "

set number relativenumber
set noexpandtab
set tabstop=4
set shiftwidth=4
" Make Ctrl+w and Ctrl+u not stop where Insert-mode was entered
set backspace=3

highlight StatusLine ctermfg=yellow
highlight StatusLineNC ctermfg=darkgray

" Highlight trailing whitespace
highlight BadSpace ctermbg=red guibg=red
autocmd BufWinEnter <buffer> match BadSpace /\s\+$/
autocmd InsertEnter <buffer> match BadSpace /\s\+\%#\@<!$/
autocmd InsertLeave <buffer> match BadSpace /\s\+$/
autocmd BufWinLeave <buffer> call clearmatches()

augroup basic
	autocmd!
	" Disable continuation of comments to the next line
	autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
	" Recognize the .h file extension as C not C++
	autocmd BufRead,BufNewFile *.h set filetype=c
augroup END

" TODO causes delay when leaving Insert-mode
" Fix Ctrl+Left and Ctrl+Right in urxvt
map <Esc>Od <C-Left>
map! <Esc>Od <C-Left>
map <Esc>Oc <C-Right>
map! <Esc>Oc <C-Right>

" Ctrl+BackSpace to delete a word
noremap! <C-h> <C-w>

" Disable PageDown and PageUp in Insert-mode
inoremap <PageDown> <nop>
inoremap <PageUp> <nop>

" Make Home key like ^ not 0
noremap <Home> ^
inoremap <Home> <C-o>^

" U to redo
nnoremap U <C-r>

" A count before v/V/<C-v> to select that many chars/lines/cells
nnoremap <expr> v '@_v"_y' . v:count1 . "v"
nnoremap <expr> V "@_V" . (v:count>1 ? (v:count-1)."j" : "")
nnoremap <expr> <C-v> "@_\<C-v>" . (v:count>1 ? (v:count-1)."j" : "")

" Ctrl+f to autocomplete filenames
inoremap <C-f> <C-x><C-f>

" Alt+p/n after using Ctrl+p/n to autocomplete the next words too
" (You can also use Alt+p/n instead of Ctrl+p/n in the first place)
inoremap <A-p> <C-x><C-p>
inoremap <A-n> <C-x><C-n>

" Alt+r to duplicate lines
nnoremap <A-r> yy']p
nnoremap <A-R> yyP

" <Leader> then y for yanking to the system clipboard
map <Leader>y "+y
map <Leader>Y "+Y
" <Leader> then p to put from the system clipboard
map <Leader>p "+p
map <Leader>P "+P
map <Leader>gp "+gp
map <Leader>gP "+gP

" <Leader> then c to toggle the cursor going where there are no characters
nnoremap <silent> <Leader>c :<C-u>exec 'set virtualedit=' . (&virtualedit == '' ? 'all' : '')<CR>
xnoremap <silent> <Leader>c :<C-u>exec 'set virtualedit=' . (&virtualedit == '' ? 'all' : '')<CR>gv



""" BUFFERS AND WINDOWS

" Navigating buffers
nnoremap <A-n> :bn<CR>
nnoremap <A-p> :bp<CR>
" Switch buffer prompt
nnoremap <Leader>b :ls<CR>:b<Space>
" Edit file prompt
nnoremap <Leader>e :e<Space>
" View file prompt
nnoremap <Leader>r :view<Space>
" Shortcuts
nnoremap <A-w> :w<CR>
nnoremap <A-q> :q<CR>
nnoremap <A-Q> :q!<CR>
nnoremap <Leader>w :w<CR>
nnoremap <Leader>q :q<CR>
nnoremap <Leader>Q :q!<CR>
" Close buffer but not window
nnoremap <Leader>x :bp<bar>sp<bar>bn<bar>bd<CR>

" Opening windows
set splitbelow
set splitright
nnoremap <A-v> :vsplit<CR>
nnoremap <A-h> :split<CR>
nnoremap <Leader>v :vsplit<CR>
nnoremap <Leader>h :split<CR>
" Navigating windows (in lots of modes)
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
nnoremap <A-Left> <C-w>h
nnoremap <A-Down> <C-w>j
nnoremap <A-Up> <C-w>k
nnoremap <A-Right> <C-w>l
inoremap <A-h> <ESC><C-w>h
inoremap <A-j> <ESC><C-w>j
inoremap <A-k> <ESC><C-w>k
inoremap <A-l> <ESC><C-w>l
inoremap <A-Left> <ESC><C-w>h
inoremap <A-Down> <ESC><C-w>j
inoremap <A-Up> <ESC><C-w>k
inoremap <A-Right> <ESC><C-w>l
tnoremap <A-Left> <C-\><C-n><C-w>h
tnoremap <A-Down> <C-\><C-n><C-w>j
tnoremap <A-Up> <C-\><C-n><C-w>k
tnoremap <A-Right> <C-\><C-n><C-w>l
" Cycling round windows
nnoremap <A-c> <C-w>w
inoremap <A-c> <ESC><C-w>w
tnoremap <A-c> <C-\><C-n><C-w>w
nnoremap <A-C> <C-w>W
inoremap <A-C> <ESC><C-w>W
tnoremap <A-C> <C-\><C-n><C-w>W
" Fullscreen window
nnoremap <A-f> <C-w>_<C-w><Bar>
" Equalize windows
nnoremap <A-=> <C-w>=

" Tabs
nnoremap <A-t> :tabnext<CR>
nnoremap <A-T> :tabprevious<CR>



""" EMBEDDED TERMINAL

" Escape key to exit Terminal-mode (Insert-mode equivalent in :terminal)
tnoremap <Esc> <C-\><C-n>

augroup terminal
    autocmd!
	" Disable line numbers in embedded terminals
    autocmd TermOpen * :setlocal nonumber norelativenumber
	" Don't highlight trailing whitespace in embedded terminals
	autocmd TermOpen * call clearmatches()
	" Always pass through Ctrl+c to embedded terminals
    autocmd TermOpen * nnoremap <buffer> <C-c> i<C-c>
augroup END



""" * AND # SEARCHING THE VISUAL MODE SELECTION

function! s:VSetSearch(cmdtype)
  let temp = @s
  norm! gv"sy
  let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g')
  let @s = temp
endfunction

xnoremap * :<C-u>call <SID>VSetSearch('/')<CR>/<C-R>=@/<CR><CR>
xnoremap # :<C-u>call <SID>VSetSearch('?')<CR>?<C-R>=@/<CR><CR>



""" COMMENTING LINES

" Set the default comment to '# '
set commentstring=#\ %s
augroup comments
	autocmd!
	" Use // instead of /* */ for comments
	autocmd FileType c,cpp,cs,java,arduino setlocal commentstring=//\ %s
augroup END

function! Comment(...)
	let l:firstline = line('.')
	let l:lastline = line('.') + s:commentCount - 1
	let l:prefix = split(&commentstring, '%s', 1)[0]
	let l:suffix = split(&commentstring, '%s', 1)[1]
	let l:pattern = '\V\s\*'.escape(trim(l:prefix), '\').'\.\*'.escape(trim(l:suffix), '\').'\s\*'
	let l:iscomment = 1
    for l:line in getline(l:firstline, l:lastline)
		if len(trim(l:line)) && l:line !~# l:pattern
			let l:iscomment = 0
			break
		endif
	endfor
	if l:iscomment
		for l:n in range(l:firstline, l:lastline)
			if len(trim(getline(l:n)))
				call setline(l:n, getline(l:n)[len(l:prefix):len(getline(l:n))-len(l:suffix)-1])
			endif
		endfor
	else
		for l:n in range(l:firstline, l:lastline)
			if len(trim(getline(l:n)))
				call setline(l:n, l:prefix . getline(l:n) . l:suffix)
			endif
		endfor
	endif
endfunction

function! s:setupComment()
	let s:commentCount = v:count1 * (abs(line(".") - line("v")) + 1)
	set operatorfunc=Comment
	return 'g@l'
endfunction

" gc to comment/uncomment lines
noremap <expr> gc <SID>setupComment()

" gC to duplicate lines and comment/uncomment the originals
map gC yyV']gc']p
xmap gC yV']gc']p



""" SURROUNDING WITH BRACKETS ETC.

" S( to surround the visual mode selection like ( this )
" S) to surround the visual mode selection like (this)
xnoremap <silent> S( :s/\%V.*\%V.\?/( & )/<CR>`<
xnoremap <silent> S) :s/\%V.*\%V.\?/(&)/<CR>`<
xnoremap <silent> S[ :s/\%V.*\%V.\?/[ & ]/<CR>`<
xnoremap <silent> S] :s/\%V.*\%V.\?/[&]/<CR>`<
xnoremap <silent> S{ :s/\%V.*\%V.\?/{ & }/<CR>`<
xnoremap <silent> S} :s/\%V.*\%V.\?/{&}/<CR>`<
xnoremap <silent> S< :s/\%V.*\%V.\?/< & >/<CR>`<
xnoremap <silent> S> :s/\%V.*\%V.\?/<&>/<CR>`<
xnoremap <silent> S' :s/\%V.*\%V.\?/'&'/<CR>`<
xnoremap <silent> S" :s/\%V.*\%V.\?/"&"/<CR>`<
xnoremap <silent> S` :s/\%V.*\%V.\?/`&`/<CR>`<
xnoremap <silent> S* :s/\%V.*\%V.\?/*&*/<CR>`<
xnoremap <silent> S_ :s/\%V.*\%V.\?/_&_/<CR>`<
xnoremap <silent> S~ :s/\%V.*\%V.\?/\~&\~/<CR>`<

" ys( to surround a word like ( this )
" ys) to surround a word like (this)
nmap <silent> ys( viwS(
nmap <silent> ys) viwS)
nmap <silent> ys[ viwS[
nmap <silent> ys] viwS]
nmap <silent> ys{ viwS{
nmap <silent> ys} viwS}
nmap <silent> ys< viwS<
nmap <silent> ys> viwS>
nmap <silent> ys' viwS'
nmap <silent> ys" viwS"
nmap <silent> ys` viwS`
nmap <silent> ys* viwS*
nmap <silent> ys_ viwS_
nmap <silent> ys~ viwS~

" yS( to surround a WORD like ( this )
" yS) to surround a WORD like (this)
nmap <silent> yS( viWS(
nmap <silent> yS) viWS)
nmap <silent> yS[ viWS[
nmap <silent> yS] viWS]
nmap <silent> yS{ viWS{
nmap <silent> yS} viWS}
nmap <silent> yS< viWS<
nmap <silent> yS> viWS>
nmap <silent> yS' viWS'
nmap <silent> yS" viWS"
nmap <silent> yS` viWS`
nmap <silent> yS* viWS*
nmap <silent> yS_ viWS_
nmap <silent> yS~ viWS~

" ds( to remove surrounding parentheses and a inner space
" ds) to remove surrounding parentheses
nnoremap <silent> ds( lF(f)XxF(xx
nnoremap <silent> ds) lF(f)xF(x
nnoremap <silent> ds[ lF[f]XxF[xx
nnoremap <silent> ds] lF[f]xF[x
nnoremap <silent> ds{ lF{f}XxF[xx
nnoremap <silent> ds} lF{f}xF{x
nnoremap <silent> ds< lF<f>XxF<xx
nnoremap <silent> ds> lF<f>xF<x
nnoremap <silent> ds' lF'f'xF'x
nnoremap <silent> ds" lF"f"xF"x
nnoremap <silent> ds` lF`f`xF`x
nnoremap <silent> ds* lF*f*xF*x
nnoremap <silent> ds_ lF_f_xF_x
nnoremap <silent> ds~ lF~f~xF~x

" cs([ or cs)] to change surrounding parentheses to brackets
" cs)[ or cs(] would also change the spacing
for a in  ['()', '[]', '{}', '<>', "''", '""', '*', '_', '~']
	for b in  ['()', '[]', '{}', '<>', "''", '""', '*', '_', '~']
        if a[1] != b[1]
            exe 'nnoremap <silent> cs'.a[1].b[1].' lF'.a[0].'f'.a[1].'r'.b[1].'F'.a[0].'r'.b[0]
		endif
        if a[1] != b[1] && b[0] != b[1]
            exe 'nnoremap <silent> cs'.a[1].b[0].' lF'.a[0].'f'.a[1].'s '.b[1].'<Esc>F'.a[0].'s'.b[0].' <Esc>'
		endif
        if a[0] != b[1] && a[0] != a[1]
            exe 'nnoremap <silent> cs'.a[0].b[1].' lF'.a[0].'f'.a[1].'Xr'.b[1].'F'.a[0].'xr'.b[0]
		endif
        if a[0] != b[0] && a[0] != a[1] && b[0] != b[1]
            exe 'nnoremap <silent> cs'.a[0].b[0].' lF'.a[0].'f'.a[1].'r'.b[1].'F'.a[0].'r'.b[0]
		endif
	endfor
endfor



""" NUMEN VOICE CONTROL
""" https://git.sr.ht/~geb/numen/tree/master/item/extras/select.vim

" These enable visual mode selection from insert mode with Shift+Left/Right,
" and let you select your transcription using the "select" phrase.

nnoremap <S-Left> v
inoremap <S-Left> <Esc>v
vnoremap <S-Left> h
nnoremap <S-Right> v
inoremap <S-Right> <Esc>lv
vnoremap <S-Right> l

" These let you format your selection.
" For example, "score cap" makes your selection camelCase.

" kebab-case
vnoremap <silent> _- :s/\%V /-/g<CR>`>a
" dot.case
vnoremap <silent> _. :s/\%V /./g<CR>`>a
" colon::case
vnoremap <silent> _: <Esc>`>a <Esc>:s/\%V /::/g<CR>`<f s
" snake_case
vnoremap <silent> __ :s/\%V /_/g<CR>`>a
" UPPER_SNAKE_CASE
vnoremap <silent> _u :s/\%V./\u&/g <bar> s/\%V /_/g<CR>`>a
" camelCase
vnoremap <silent> _c <Esc>`>a <Esc>:s/\%V \<\(.\)/\u\1/g<CR>`<f s
" MixedCase
vnoremap <silent> _m <Esc>`>a <Esc>:s/\%V \?\<\(.\)/\u\1/g<CR>`<f s
" Title Case
vnoremap <silent> _t :s/\%V\<./\u&/g<CR>`>a
" allsmashedtogether
vnoremap <silent> _<space> <Esc>`>a <Esc>:s/\%V //g<CR>`<f s
" a, kind, of, list, case
vnoremap <silent> _, <Esc>`>a  <Esc>:s/\%V /, /g<CR>`>/  <CR>2s
" "a", "kind", "of", "quoted", "list", "case"
vnoremap <silent> _" <Esc>`>a  <Esc>:s/\%V /", "/g<CR>`<i"<Esc>`>/  <CR>2s"
" 'a', 'kind', 'of', 'quoted', 'list', 'case'
vnoremap <silent> _' <Esc>`>a  <Esc>:s/\%V /', '/g<CR>`<i'<Esc>`>/  <CR>2s'



""" SOURCE ADDITIONAL FILES

if len($XDG_CONFIG_HOME)
	for f in glob('$XDG_CONFIG_HOME/tiles-editor/additional/*.vim', 0, 1)
		execute 'source' f
	endfor
else
	for f in glob('$HOME/.config/tiles-editor/additional/*.vim', 0, 1)
		execute 'source' f
	endfor
endif