dotfiles

dot files
git clone git://git.rr3.xyz/dotfiles
Log | Files | Refs

visrc.lua (2634B)


      1 require('vis')
      2 
      3 -- Vis bug?: <C-M-Down> != <M-C-Down> and similarly for Up
      4 
      5 local modes = vis.modes
      6 local events = vis.events
      7 
      8 -- Filetype-specific configuration
      9 local ftrun = nil -- TODO
     10 local ftcomment = nil
     11 
     12 events.subscribe(events.INIT, function()
     13 	vis.ftdetect.filetypes.mp = {ext = {"%.mp$"}}
     14 	vis.ftdetect.filetypes.suq = {ext = {"%.suq$"}}
     15 	vis.ftdetect.filetypes.lean = {ext = {"%.lean$"}}
     16 	vis.ftdetect.filetypes.glsl = {ext = {"%.glsl$"}}
     17 	vis:command("set theme custom")
     18 end)
     19 
     20 events.subscribe(events.WIN_OPEN, function(win)
     21 	vis:command("set relativenumber")
     22 	vis:command("set tabwidth 4")
     23 	vis:command("set cc 80")
     24 	vis:command("set autoindent")
     25 
     26 	-- qq to record and Q to reply
     27 	vis:command("map! normal Q @q")
     28 
     29 	-- Indent and unindent
     30 	vis:command("map! normal <Tab> >>")
     31 	vis:command("map! normal <S-Tab> <<")
     32 	vis:command("map! visual <Tab> >")
     33 	vis:command("map! visual <S-Tab> <")
     34 	vis:command("map! visual-line <Tab> >")
     35 	vis:command("map! visual-line <S-Tab> <")
     36 
     37 	-- Create new cursors
     38 	vis:command("map! normal <C-Up> <C-k>")
     39 	vis:command("map! normal <C-Down> <C-j>")
     40 
     41 	-- Scroll 5 lines at a time without moving cursor
     42 	vis:command("map! normal <M-C-Up> <C-y><C-y><C-y><C-y><C-y>")
     43 	vis:command("map! normal <M-C-Down> <C-e><C-e><C-e><C-e><C-e>")
     44 	vis:command("map! insert <M-C-Up> <C-x><C-y><C-x><C-y><C-x><C-y><C-x><C-y><C-x><C-y>")
     45 	vis:command("map! insert <M-C-Down> <C-x><C-e><C-x><C-e><C-x><C-e><C-x><C-e><C-x><C-e>")
     46 
     47 	-- Jump around block
     48 	vis:command("map! normal <S-Up> {")
     49 	vis:command("map! normal <S-Down> }")
     50 	vis:command("map! visual-line <S-Up> {")
     51 	vis:command("map! visual-line <S-Down> }")
     52 
     53 	-- Commenting
     54 	vis:map(modes.NORMAL, "<C-/>", function()
     55 		if ftcomment == nil then
     56 			vis:info("Commenting not implemented for this filetype")
     57 			return
     58 		end
     59 		vis:command("x/")
     60 		local sel = vis.win.selection
     61 		local pos = sel.pos
     62 		vis.win.file:insert(sel.pos - sel.col + 1, ftcomment .. " ")
     63 		sel.pos = pos + #ftcomment + 1
     64 	end)
     65 -- 	vis:map(modes.NORMAL, "<C-/>", function()
     66 -- 		if ftcomment == nil then
     67 -- 			vis:info("Commenting not implemented for this filetype")
     68 -- 			return
     69 -- 		end
     70 -- 		local sel = vis.win.selection
     71 -- 		local pos = sel.pos
     72 -- 		vis.win.file:insert(sel.pos - sel.col + 1, ftcomment .. " ")
     73 -- 		sel.pos = pos + #ftcomment + 1
     74 -- 	end)
     75 
     76 	if win.syntax == "haskell"
     77 			or win.syntax == "lean"
     78 			or win.syntax == "fsharp" then
     79 		vis:command("set expandtab true")
     80 	end
     81 end)
     82 
     83 events.subscribe(events.WIN_OPEN, function(win)
     84 	local fttab = {
     85 		lua = {
     86 			comment = "--"
     87 		}
     88 	}
     89 
     90 	local ft = fttab[win.syntax]
     91 	if ft == nil then return end
     92 
     93 	ftcomment = ft.comment
     94 end)