vis-config

lua scripts to configure vis editor

git clone https://9o.is/git/vis-config.git

visrc.lua

(4697B)


      1 require('vis')
      2 require('plugins/commentary')
      3 require('plugins/surround')
      4 require('plugins/modelines')
      5 require('lib/x11')
      6 require('lib/status')
      7 require('lib/session')
      8 require('lib/router')
      9 require('lib/search')
     10 require('lib/utils')
     11 
     12 local ctags = require('lib/ctags')
     13 local lspc = require('plugins/vis-lspc')
     14 lspc.enabled = true
     15 lspc.autostart = false
     16 lspc.menu_cmd = 'fzy'
     17 lspc.confirm_cmd = 'fzy'
     18 lspc.universal_root_globs = {'*.git'}
     19 
     20 local m = vis.modes
     21 local ll = ' '			 -- left leader
     22 local lr = '<Backspace>' -- right leader
     23 
     24 vis.events.subscribe(vis.events.INIT, function()
     25 	vis:command('set autoindent on')
     26 	vis:command('set ignorecase on')
     27 	vis:command('set layout v')
     28 
     29 	-- navigation
     30 	map({m.NORMAL, m.INSERT}, '<M-Up>',    	'<vis-window-prev>')
     31 	map({m.NORMAL, m.INSERT}, '<M-Down>',  	'<vis-window-next>')
     32 	map({m.NORMAL, m.INSERT}, '<M-Left>',  	'<vis-router-back>')
     33 	map({m.NORMAL, m.INSERT}, '<M-Right>', 	'<vis-router-forward>')
     34 	map({m.NORMAL, m.INSERT}, '<M-q>',     	cmd('q'), 'Quit')
     35 	map({m.NORMAL, m.INSERT}, '<F1>',		cmd("tabnew +help-fullscreen"), 'Help fullscreen')
     36 	
     37 	-- navigation via search
     38 	map({m.NORMAL, m.VISUAL}, '-',   	 cmd('find'),         	'File search')
     39 	map({m.NORMAL, m.VISUAL}, '_',   	 cmd('mru'),         	'Most recently used files')
     40 	map({m.NORMAL, m.VISUAL}, lr..'f',   cmd('find'),         	'[F]ile search')
     41 	map({m.NORMAL, m.VISUAL}, lr..'d',   cmd('dfind'),      	'[D]irectory search')
     42 	map({m.NORMAL, m.VISUAL}, lr..'g',   cmd('grep'),         	'[G]rep search')
     43 	map({m.NORMAL, m.VISUAL}, ll..'e',   cmd('explore'),      	'[E]xplore')
     44 	map({m.NORMAL, m.VISUAL}, lr..'F',   cmd('scope find'),     '[F]ile scoped search')
     45 	map({m.NORMAL, m.VISUAL}, lr..'G',   cmd('scope grep'),     '[G]rep scoped search')
     46 	map({m.NORMAL, m.VISUAL}, lr..'D',   cmd('scope dfind'),   	'[D]irectory scoped search')
     47 	map({m.NORMAL, m.VISUAL}, lr..'tf',  cmd('tab find'),      	'[T]ab [F]ile search')
     48 	map({m.NORMAL, m.VISUAL}, lr..'tg',  cmd('tab grep'),      	'[T]ab [G]rep search')
     49 	map({m.NORMAL, m.VISUAL}, lr..'te',  cmd('tab explore'),   	'[T]ab [E]xplore')
     50 	map({m.NORMAL, m.VISUAL}, lr..'td',  cmd('tab dfind'),   	'[T]ab [D]irectory search')
     51 	map({m.NORMAL, m.VISUAL}, lr..'tF',  cmd('tab scope find'), '[T]ab [F]ile scoped search')
     52 	map({m.NORMAL, m.VISUAL}, lr..'tG',  cmd('tab scope grep'), '[T]ab [G]rep scoped search')
     53 	map({m.NORMAL, m.VISUAL}, lr..'tD',  cmd('tab scope dfind'),'[T]ab [D]irectory scoped search')
     54 
     55 	-- misc
     56 	map(m.NORMAL, 'go', ins('o<Escape>'))
     57 	map(m.NORMAL, 'gO', ins('O<Escape>'))
     58 
     59 	-- system clipboard by default
     60 	map(m.NORMAL,      'y', '<vis-register>+<vis-operator-yank>')
     61 	map(m.VISUAL,      'y', '<vis-register>+<vis-operator-yank>')
     62 	map(m.VISUAL_LINE, 'y', '<vis-register>+<vis-operator-yank>')
     63 	map(m.NORMAL,      'd', '<vis-register>+<vis-operator-delete>')
     64 	map(m.VISUAL,      'd', '<vis-register>+<vis-operator-delete>')
     65 	map(m.VISUAL_LINE, 'd', '<vis-register>+<vis-operator-delete>')
     66 	map(m.NORMAL,      'p', '<vis-register>+<vis-put-after>')
     67 	map(m.VISUAL,      'p', '<vis-register>+<vis-put-after>')
     68 	map(m.VISUAL_LINE, 'p', '<vis-register>+<vis-put-after>')
     69 	map(m.NORMAL,      'P', '<vis-register>+<vis-put-before>')
     70 	map(m.VISUAL,      'P', '<vis-register>+<vis-put-before>')
     71 	map(m.VISUAL_LINE, 'P', '<vis-register>+<vis-put-before>')
     72 
     73 	-- center
     74 	map(m.NORMAL, 'n', '<vis-motion-search-repeat-forward>zz')
     75 	map(m.NORMAL, 'N', '<vis-motion-search-repeat-backward>zz')
     76 end)
     77 
     78 vis.events.subscribe(vis.events.WIN_OPEN, function(win)
     79 	vis:command('set tabwidth 4')
     80 
     81 	if 'Shakefile' == win.file.path:match('([^/]+)$') then
     82 		win:set_syntax('bash')
     83 	end
     84 end)
     85 
     86 settings = {
     87 	c = function(win)
     88 		if start_lspc(lspc, 'clangd') then
     89 			return
     90 		end
     91 
     92 		vis:command('set ctags on')
     93 
     94 		ctags.add(win, '.tags', {
     95 			path = '.',
     96 			flags = '-R --extras=+q-F --fields=+SzK --languages=c,c++',
     97 			autosave = true,
     98 		})
     99 
    100 		ctags.add(win, '.tags.system', {
    101 			path = '/usr/include',
    102 			flags = '-R --extras=+q-F --fields=+SzK --languages=c,c++',
    103 		})
    104 
    105 		mapwin(win, m.NORMAL, lr..'r', cmd('tag-search .tags'), '[S]earch [T]ags')
    106 		mapwin(win, {m.NORMAL, m.VISUAL}, 'K', function()
    107 			local sec = vis.count
    108 			local name = content(vis.win)
    109 			vis.count = nil
    110 
    111 			if runq(string.format('whatis %s %s', sec and '-s '..sec or '', name)) then
    112 				vis:command(string.format('terminal man %s %s', sec or '', name))
    113 			end
    114 		end, 'Man')
    115 	end,
    116 }
    117 
    118 -- useful for startup (vis +help-fullscreen)
    119 vis:command_register('help-fullscreen', function(argv)
    120 	vis:command('help')
    121 	vis:feedkeys('<vis-window-prev>')
    122 	vis:command('q')
    123 end)
    124 
    125 vis:command_register('normal', function(argv)
    126 	vis.mode = vis.modes.NORMAL
    127 	vis:feedkeys(table.concat(argv))
    128 end)