Skip to content

Instantly share code, notes, and snippets.

@frabjous
Last active January 20, 2023 17:45
Show Gist options
  • Save frabjous/b42fa5dbf85028042c76cab13e254450 to your computer and use it in GitHub Desktop.
Save frabjous/b42fa5dbf85028042c76cab13e254450 to your computer and use it in GitHub Desktop.
Main NeoVim config files as of 11 June 2022
if &background == 'dark'
let s:guishade0 = "#131518"
let s:guishade1 = "#303236"
let s:guishade2 = "#4d5053"
let s:guishade3 = "#6a6d71"
let s:guishade4 = "#878b8f"
let s:guishade5 = "#a4a8ad"
let s:guishade6 = "#c1c6ca"
let s:guishade7 = "#dee3e8"
let s:guiaccent0 = "#df8787"
let s:guiaccent1 = "#f5af71"
let s:guiaccent2 = "#ffffaf"
let s:guiaccent3 = "#afdf87"
let s:guiaccent4 = "#afdfdf"
let s:guiaccent5 = "#87afdf"
let s:guiaccent6 = "#8f5ac9"
let s:guiaccent6 = "#afdfdf"
let s:guiaccent7 = "#dfafdf"
let s:ctermshade0 = 233
let s:ctermshade1 = 59
let s:ctermshade2 = 239
let s:ctermshade3 = 242
let s:ctermshade4 = 245
let s:ctermshade5 = 248
let s:ctermshade6 = 251
let s:ctermshade7 = 254
let s:ctermaccent0 = 181
let s:ctermaccent1 = 216
let s:ctermaccent2 = 229
let s:ctermaccent3 = 151
let s:ctermaccent4 = 152
let s:ctermaccent5 = 146
let s:ctermaccent6 = 140
let s:ctermaccent7 = 9
endif
highlight clear
syntax reset
let g:colors_name = "ThemerVim-transparent"
""""""""""
" Normal "
""""""""""
"exec "hi Normal guifg=".s:guishade6." guibg=".s:guishade0
exec "hi Normal guifg=".s:guishade6
"exec "hi Normal ctermfg=".s:ctermshade6." ctermbg=".s:ctermshade0
exec "hi Normal ctermfg=".s:ctermshade6
"""""""""""""""""
" Syntax groups "
"""""""""""""""""
" Default
exec "hi Comment guifg=".s:guishade2
exec "hi Comment ctermfg=".s:ctermshade2
exec "hi Constant guifg=".s:guiaccent3
exec "hi Constant ctermfg=".s:ctermaccent3
exec "hi Character guifg=".s:guiaccent4
exec "hi Character ctermfg=".s:ctermaccent4
exec "hi Identifier guifg=".s:guiaccent2." gui=none"
exec "hi Identifier ctermfg=".s:ctermaccent2." cterm=none"
exec "hi Statement guifg=".s:guiaccent5
exec "hi Statement ctermfg=".s:ctermaccent5
exec "hi PreProc guifg=".s:guiaccent6
exec "hi PreProc ctermfg=".s:ctermaccent6
exec "hi Type guifg=".s:guiaccent7
exec "hi Type ctermfg=".s:ctermaccent7
exec "hi Special guifg=".s:guiaccent4
exec "hi Special ctermfg=".s:ctermaccent4
exec "hi Underlined guifg=".s:guiaccent5
exec "hi Underlined ctermfg=".s:ctermaccent5
exec "hi Error guifg=".s:guiaccent0." guibg=".s:guishade1
exec "hi Error ctermfg=".s:ctermaccent0." ctermbg=".s:ctermshade1
exec "hi Todo guifg=".s:guiaccent0." guibg=".s:guishade1
exec "hi Todo ctermfg=".s:ctermaccent0." ctermbg=".s:ctermshade1
exec "hi Function guifg=".s:guiaccent1
exec "hi Function ctermfg=".s:ctermaccent1
" GitGutter
exec "hi GitGutterAdd guifg=".s:guiaccent3
exec "hi GitGutterAdd ctermfg=".s:ctermaccent3
exec "hi GitGutterChange guifg=".s:guiaccent2
exec "hi GitGutterChange ctermfg=".s:ctermaccent2
exec "hi GitGutterChangeDelete guifg=".s:guiaccent2
exec "hi GitGutterChangeDelete ctermfg=".s:ctermaccent2
exec "hi GitGutterDelete guifg=".s:guiaccent0
exec "hi GitGutterDelete ctermfg=".s:ctermaccent0
" fugitive
exec "hi gitcommitComment guifg=".s:guishade3
exec "hi gitcommitComment ctermfg=".s:ctermshade3
exec "hi gitcommitOnBranch guifg=".s:guishade3
exec "hi gitcommitOnBranch ctermfg=".s:ctermshade3
exec "hi gitcommitHeader guifg=".s:guishade5
exec "hi gitcommitHeader ctermfg=".s:ctermshade5
exec "hi gitcommitHead guifg=".s:guishade3
exec "hi gitcommitHead ctermfg=".s:ctermshade3
exec "hi gitcommitSelectedType guifg=".s:guiaccent3
exec "hi gitcommitSelectedType ctermfg=".s:ctermaccent3
exec "hi gitcommitSelectedFile guifg=".s:guiaccent3
exec "hi gitcommitSelectedFile ctermfg=".s:ctermaccent3
exec "hi gitcommitDiscardedType guifg=".s:guiaccent2
exec "hi gitcommitDiscardedType ctermfg=".s:ctermaccent2
exec "hi gitcommitDiscardedFile guifg=".s:guiaccent2
exec "hi gitcommitDiscardedFile ctermfg=".s:ctermaccent2
exec "hi gitcommitUntrackedFile guifg=".s:guiaccent0
exec "hi gitcommitUntrackedFile ctermfg=".s:ctermaccent0
"""""""""""""""""""""""
" Highlighting Groups "
"""""""""""""""""""""""
" Default
exec "hi ColorColumn guibg=".s:guishade0
exec "hi ColorColumn ctermbg=".s:ctermshade0
exec "hi Conceal guifg=".s:guishade2
exec "hi Conceal ctermfg=".s:ctermshade2
exec "hi Cursor guifg=".s:guishade0
exec "hi Cursor ctermfg=".s:ctermshade0
exec "hi CursorColumn guibg=".s:guishade1
exec "hi CursorColumn ctermbg=".s:ctermshade1
exec "hi CursorLine guibg=".s:guishade0
exec "hi CursorLine ctermbg=".s:ctermshade0." cterm=none"
exec "hi Directory guifg=".s:guiaccent5
exec "hi Directory ctermfg=".s:ctermaccent5
exec "hi DiffAdd guifg=".s:guiaccent3." guibg=".s:guishade1
exec "hi DiffAdd ctermfg=".s:ctermaccent3." ctermbg=".s:ctermshade1
exec "hi DiffChange guifg=".s:guiaccent2." guibg=".s:guishade1
exec "hi DiffChange ctermfg=".s:ctermaccent2." ctermbg=".s:ctermshade1
exec "hi DiffDelete guifg=".s:guiaccent0." guibg=".s:guishade1
exec "hi DiffDelete ctermfg=".s:ctermaccent0." ctermbg=".s:ctermshade1
exec "hi DiffText guifg=".s:guiaccent2." guibg=".s:guishade2
exec "hi DiffText ctermfg=".s:ctermaccent2." ctermbg=".s:ctermshade2
exec "hi ErrorMsg guifg=".s:guishade7." guibg=".s:guiaccent0
exec "hi ErrorMsg ctermfg=".s:ctermshade7." ctermbg=".s:ctermaccent0
exec "hi VertSplit guifg=".s:guishade0." guibg=".s:guishade3
exec "hi VertSplit ctermfg=".s:ctermshade0." ctermbg=".s:ctermshade3
exec "hi Folded guifg=".s:guishade4." guibg=".s:guishade1
exec "hi Folded ctermfg=".s:ctermshade4." ctermbg=".s:ctermshade1
exec "hi FoldColumn guifg=".s:guishade4." guibg=".s:guishade1
exec "hi FoldColumn ctermfg=".s:ctermshade4." ctermbg=".s:ctermshade1
exec "hi SignColumn guibg=".s:guishade0
exec "hi SignColumn ctermbg=".s:ctermshade0
exec "hi IncSearch guifg=".s:guishade0." guibg=".s:guiaccent2
exec "hi IncSearch ctermfg=".s:ctermshade0." ctermbg=".s:ctermaccent2
exec "hi LineNr guifg=".s:guishade2." guibg=".s:guishade0
exec "hi LineNr ctermfg=".s:ctermshade2." ctermbg=".s:ctermshade0
" exec "hi CursorLineNr guifg=".s:guishade3." guibg=".s:guishade1
" exec "hi CursorLineNr ctermfg=".s:ctermshade3." ctermbg=".s:ctermshade1
exec "hi CursorLineNr guifg=".s:guiaccent5." guibg=".s:guishade1
exec "hi CursorLineNr ctermfg=".s:ctermaccent5." ctermbg=".s:ctermshade1
exec "hi MatchParen guibg=".s:guiaccent3." guifg=".s:guishade0
exec "hi MatchParen ctermbg=".s:ctermaccent3." ctermfg=".s:ctermshade0
" exec "hi MatchParen guibg=".s:guishade2
" exec "hi MatchParen ctermbg=".s:ctermshade2
exec "hi MoreMsg guifg=".s:guishade0." guibg=".s:guiaccent4
exec "hi MoreMsg ctermfg=".s:ctermshade0." ctermbg=".s:ctermaccent4
" exec "hi NonText guifg=".s:guishade2." guibg=".s:guishade0
" exec "hi NonText ctermfg=".s:ctermshade2." ctermbg=".s:ctermshade0
exec "hi NonText guifg=".s:guishade2
exec "hi NonText ctermfg=".s:ctermshade2
" exec "hi Pmenu guifg=".s:guishade1." guibg=".s:guishade6
" exec "hi Pmenu ctermfg=".s:ctermshade6." ctermbg=".s:ctermshade1
exec "hi Pmenu guifg=".s:guishade6." guibg=".s:guishade2
exec "hi Pmenu ctermfg=".s:ctermshade6." ctermbg=".s:ctermshade2
" exec "hi PmenuSel guifg=".s:guiaccent4." guibg=".s:guishade1
" exec "hi PmenuSel ctermfg=".s:ctermaccent4." ctermbg=".s:ctermshade1
exec "hi PmenuSel guifg=".s:guishade1." guibg=".s:guiaccent4
exec "hi PmenuSel ctermfg=".s:ctermshade1." ctermbg=".s:ctermaccent4
exec "hi PmenuSbar guifg=".s:guiaccent3." guibg=".s:guishade1
exec "hi PmenuSbar guifg=".s:guiaccent3." guibg=".s:guishade1
exec "hi PmenuSbar ctermfg=".s:ctermaccent3." ctermbg=".s:ctermshade1
exec "hi PmenuThumb guifg=".s:guiaccent0." guibg=".s:guishade2
exec "hi PmenuThumb ctermfg=".s:ctermaccent0." ctermbg=".s:ctermshade2
exec "hi Question guifg=".s:guishade7." guibg=".s:guishade1
exec "hi Question ctermfg=".s:ctermshade7." ctermbg=".s:ctermshade1
exec "hi Search guifg=".s:guishade0." guibg=".s:guiaccent2
exec "hi Search ctermfg=".s:ctermshade0." ctermbg=".s:ctermaccent2
exec "hi SpecialKey guifg=".s:guiaccent7." guibg=".s:guishade0
exec "hi SpecialKey ctermfg=".s:ctermaccent7." ctermbg=".s:ctermshade0
" exec "hi SpellBad guifg=".s:guiaccent0
exec "hi SpellBad ctermbg=NONE gui=undercurl cterm=undercurl"
exec "hi SpellCap guifg=".s:guiaccent2
exec "hi SpellCap ctermfg=".s:ctermaccent2." ctermbg=NONE cterm=undercurl"
exec "hi SpellLocal guifg=".s:guiaccent4
exec "hi SpellLocal ctermfg=".s:ctermaccent4
exec "hi SpellRare guifg=".s:guiaccent1
exec "hi SpellRare ctermfg=".s:ctermaccent1
exec "hi StatusLine guifg=".s:guishade4." guibg=".s:guishade1." gui=none"
exec "hi StatusLine ctermfg=".s:ctermshade4." ctermbg=".s:ctermshade1." cterm=none"
exec "hi TabLine guifg=".s:guishade5." guibg=".s:guishade1
exec "hi TabLine ctermfg=".s:ctermshade5." ctermbg=".s:ctermshade1
exec "hi TabLineFill guibg=".s:guishade1
exec "hi TabLineFill ctermbg=".s:ctermshade1
exec "hi TabLineSel guifg=".s:guiaccent5." guibg=".s:guishade0
exec "hi TabLineSel ctermfg=".s:ctermaccent5." ctermbg=".s:ctermshade0
exec "hi Title guifg=".s:guiaccent5
exec "hi Title ctermfg=".s:ctermaccent5
"exec "hi Visual guibg=".s:guishade1
"exec "hi Visual ctermbg=".s:ctermshade1
exec "hi Visual guibg=".s:guiaccent5." guifg=".s:guishade0
exec "hi Visual ctermbg=".s:ctermaccent5." ctermbg=".s:ctermshade0
exec "hi VisualNOS guifg=".s:guiaccent0." guibg=".s:guishade1
exec "hi VisualNOS ctermfg=".s:ctermaccent0." ctermbg=".s:ctermshade1
exec "hi WarningMsg guifg=".s:guiaccent0
exec "hi WarningMsg ctermfg=".s:ctermaccent0
exec "hi WildMenu guifg=".s:guiaccent4." guibg=".s:guishade1
exec "hi WildMenu ctermfg=".s:ctermaccent4." ctermbg=".s:ctermshade1
" NERDTree
exec "hi NERDTreeExecFile guifg=".s:guiaccent4
exec "hi NERDTreeExecFile ctermfg=".s:ctermaccent4
exec "hi NERDTreeDirSlash guifg=".s:guiaccent5
exec "hi NERDTreeDirSlash ctermfg=".s:ctermaccent5
exec "hi NERDTreeCWD guifg=".s:guiaccent0
exec "hi NERDTreeCWD ctermfg=".s:ctermaccent0
" Indentation lines
exec "hi IndentBlanklineIndent1 guifg=".s:guishade2." gui=nocombine"
exec "hi IndentBlanklineIndent2 guifg=".s:guishade2." gui=nocombine"
exec "hi IndentBlanklineIndent3 guifg=".s:guishade2." gui=nocombine"
exec "hi IndentBlanklineIndent4 guifg=".s:guishade2." gui=nocombine"
exec "hi IndentBlanklineIndent5 guifg=".s:guishade2." gui=nocombine"
exec "hi IndentBlanklineIndent6 guifg=".s:guishade2." gui=nocombine"
""""""""""""
" Clean up "
""""""""""""
unlet s:guishade0 s:guishade1 s:guishade2 s:guishade3 s:guishade4 s:guishade5 s:guishade6 s:guishade7 s:guiaccent0 s:guiaccent1 s:guiaccent2 s:guiaccent3 s:guiaccent4 s:guiaccent5 s:guiaccent6 s:guiaccent7
unlet s:ctermshade0 s:ctermshade1 s:ctermshade2 s:ctermshade3 s:ctermshade4 s:ctermshade5 s:ctermshade6 s:ctermshade7 s:ctermaccent0 s:ctermaccent1 s:ctermaccent2 s:ctermaccent3 s:ctermaccent4 s:ctermaccent5 s:ctermaccent6 s:ctermaccent7
-- declare a table to collect the functions
_G.kcktexfns = {}
_G.kcktexfns.handlequote = function(double)
-- return will be either left, right or straight quotation mark
local l, r, s = '`', "'", "'"
if (double) then
l, r, s = '``', "''", '"'
end
-- get cursor position
local col = vim.api.nvim_win_get_cursor(0)[2]
-- left quotation mark if at start of line
if (col==0) then
return l
end
-- read rest of line
local currline = vim.api.nvim_get_current_line()
-- get previous character
local prevchar = currline:sub(col,col)
-- if backslash return straight version
if (prevchar == '\\') then
return s
end
-- if previous character is in this group, then return left version
local lmatches = {' ','(','[','{','<','=','&'}
for i,c in ipairs(lmatches) do
if (prevchar == c) then
return l
end
end
-- anything else return right version
return r
end
_G.kcktexfns.ltclean = function()
local exitcode = os.execute("ltclean.sh")
if (exitcode == 0) then
print("LaTeX auxiliary files deleted.")
else
vim.api.nvim_echo({{'Could not clean LaTeX auxiliary files.',
'ErrorMsg'}},true,{})
end
end
_G.kcktexfns.showerror = function()
-- determine filename
local fullpath = vim.api.nvim_buf_get_name(0)
local fn = fullpath
local result, output = pcall(require("knap").get_docroot)
if (result) then
fn = output
end
local spl = vim.split(fn,'/')
local base = spl[#spl]
local rubberprocess = io.popen('cd "$(dirname "' .. fn .. '")" && ' ..
'rubber-info "' .. base .. '" 2>&1')
local rubberinfo = rubberprocess:read()
rubberprocess:close()
if (rubberinfo) and (rubberinfo ~= 'There was no error.') then
local msgparts = vim.split(rubberinfo,":", { trimempty=true })
if (#msgparts > 3) then
local errfn = msgparts[1]
-- check if error is in this file
if (vim.endswith(errfn,base)) then
-- print shorter version of error
local shorterror = vim.trim(msgparts[3])
local errline = tonumber(msgparts[2])
vim.api.nvim_win_set_cursor(0,{errline,0})
vim.api.nvim_err_writeln('Line ' .. msgparts[2]
.. ': ' .. shorterror)
-- move cursor to line with error
end
else
-- print full error
vim.api.nvim_err_writeln(rubberinfo)
end
else
print("No errors reported.")
end
end
vim.api.nvim_buf_set_keymap(0,'i',"'",'',
{ noremap = true,
silent = true,
callback = function()
return _G.kcktexfns.handlequote(false)
end,
expr = true })
vim.api.nvim_buf_set_keymap(0,'i','"','',
{ noremap = true,
silent = true,
callback = function()
return _G.kcktexfns.handlequote(true)
end,
expr = true })
vim.api.nvim_buf_set_keymap(0, 'i', '<M-e>','',
{ noremap = true,
callback = kcktexfns.showerror
})
vim.api.nvim_buf_set_keymap(0,'v','<M-e>','',
{ noremap = true,
callback = kcktexfns.showerror
})
-- Stop horrible autoindent?
vim.cmd('filetype plugin indent off')
vim.opt_local.cindent = false
-- load ~/.config/nvim/lua/plugins.lua
require "plugins"
-- load ~/.config/nvim/lua/options.lua
require "options"
-- load ~/.config/nvim/lua/functions.lua
kckfns = require "functions"
-- load ~/.config/nvim/lua/keybinds.lua
require "keybinds"
-- load ~/.config/nvim/lua/misc.lua
require "misc"
-- load ~/.config/nvim/lua/autocmd.lua
require "autocmd"
-- custom settings for KNAP
local gknapsettings = {
delay = 250,
mdoutputext = "pdf",
markdownoutputext = "pdf",
mdtohtml = "md2html5.sh %docroot% > %outputfile%",
markdowntohtml = "md2html5.sh %docroot% > %outputfile%",
mdtopdf = "md2pdf.sh %docroot% preview",
markdowntopdf = "md2pdf.sh %docroot% preview",
mdtopdfviewerlaunch = "A=%outputfile%; B=\"$(basename \"$A\")\" ; sioyek \"/tmp/$B\"",
markdowntopdfviewerlaunch = "A=%outputfile%; B=\"$(basename \"$A\")\" ; sioyek \"/tmp/$B\"",
textopdf = 'latexcompile.lua %docroot%'
}
-- set vim global variable for KNAP settings
vim.g.knap_settings = gknapsettings
-- convenience short name
local autocmd = vim.api.nvim_create_autocmd
-- make readonly files unmodifiable --
autocmd({'BufNewFile', 'BufRead'},{
pattern = {'*'},
callback = function()
vim.opt_local.modifiable = not (vim.opt_local.readonly:get())
end
})
-- get rid of "plaintex" mode, and check for xelatex --
autocmd({'BufNewFile', 'BufRead'},{
pattern={'*.tex'},
callback = function()
vim.opt_local.filetype = 'tex'
kckfns.xelatexcheck()
end
})
-- set markdown filetype for neomutt emails
autocmd({'BufNewFile', 'BufRead'},{
pattern = {'neomutt-kck-work*'},
callback = function()
vim.opt_local.filetype = 'markdown'
end
})
-- no swap file for scratchpad
autocmd({'BufNewFile', 'BufRead'},{
pattern = {'scratch.md'},
callback = function()
vim.opt_local.swapfile = false
vim.opt_local.backup = false
vim.opt_local.undofile = false
end
})
-- clean for LaTeX sampler file
autocmd({'BufReadPost'},{
pattern={os.getenv("HOME") .. "/tmp/test.tex"},
callback = function()
if (kcktexfns.ltclean ~= nil) then
kcktexfns.ltclean()
end
end
})
-- start where you left off
autocmd({'BufReadPost'},{
pattern = {'*'},
callback = function()
local ft = vim.opt_local.filetype:get()
-- don't apply to git messages
if (ft:match('commit') or ft:match('rebase')) then
return
end
-- get position of last saved edit
local markpos = vim.api.nvim_buf_get_mark(0,'"')
local line = markpos[1]
local col = markpos[2]
-- if in range, go there
if (line > 1) and (line <= vim.api.nvim_buf_line_count(0)) then
vim.api.nvim_win_set_cursor(0,{line,col})
end
end
})
-- use pandoc-syntax for md files, but without "conceal", cursorline
-- or colorcolumn
local pandoc_syntax_group = vim.api.nvim_create_augroup('pandoc_syntax', { clear = true })
autocmd({'BufNewFile','BufFilePre','BufRead'},{
pattern = {'*.md'},
group = pandoc_syntax_group,
callback = function()
vim.opt_local.filetype = 'markdown.pandoc'
vim.opt_local.conceallevel = 0
vim.opt_local.cursorline = false
vim.opt_local.colorcolumn = '0'
end
})
local fzf = require("fzf").fzf
local action = require("fzf.actions").action
local function defer_insert(n)
n = n or 10
vim.defer_fn(function()
vim.cmd('startinsert')
end, n)
end
local function get_colorschemes()
local colorscheme_vim_files = vim.fn.globpath(vim.o.rtp, "colors/*.vim", true, true)
local colorschemes = {}
for _, colorscheme_file in ipairs(colorscheme_vim_files) do
local colorscheme = vim.fn.fnamemodify(colorscheme_file, ":t:r")
table.insert(colorschemes, colorscheme)
end
return colorschemes
end
local function get_current_colorscheme()
if vim.g.colors_name then
return vim.g.colors_name
else
return 'default'
end
end
local function startchooser()
coroutine.wrap(function ()
local preview_function = action(function (args)
if args then
local colorscheme = args[1]
vim.cmd("colorscheme " .. colorscheme)
end
end)
local current_colorscheme = get_current_colorscheme()
local choices = fzf(get_colorschemes(), "--preview=" .. preview_function .. " --preview-window right:0")
if not choices then
vim.cmd("colorscheme " .. current_colorscheme)
defer_insert(100)
else
vim.cmd("colorscheme " .. choices[1])
end
defer_insert()
end)()
end
return startchooser
local P={}
P.ftpatterns = {
tex = {
is_comment = '^%s*%%',
sub_to_uncomment = {'^(%s*)%%','%1'},
sub_to_comment = {'^','%%'}
},
vim = {
is_comment = '^%s*"',
sub_to_uncomment = {'^(%s*)"','%1'},
sub_to_comment = {'^','"'}
},
php = {
is_comment = {'^%s*#','^%s*//'},
sub_to_uncomment = {'^(%s*)[#/]/?','%1'},
sub_to_comment = {'^','//'}
},
sh = {
is_comment = '^%s*#',
sub_to_uncomment = {'^(%s*)#','%1'},
sub_to_comment = {'^','#'}
},
lua = {
is_comment = '^%s*%-%-',
sub_to_uncomment = {'^(%s*)%-%-','%1'},
sub_to_comment = {'^','--'}
},
javascript = {
is_comment = '^%s*//',
sub_to_uncomment = {'^(%s*)//','%1'},
sub_to_comment = {'^','//'}
},
html = {
is_comment = '^%s*<!%-%-.*%-%->%s*$',
sub_to_uncomment = {'^(%s*)<!%-%-(.*)%-%->%s*$','%1%2'},
sub_to_comment = {'^(.*)$','<!--%1-->'}
},
markdown = {
is_comment = '^%s*<!--.*-->%s*$',
sub_to_uncomment = {'<!--(.*)-->','%1'},
sub_to_comment = {'(.*)','<!--%1-->'}
}
}
P.togglecomments = function(startline,endline)
local ft = vim.opt_local.filetype:get()
if (P.ftpatterns[ft] == nil) then
vim.api.nvim_err_writeln(
'No comment routine for type ' .. ft)
return
end
local allcommented = true
for lnum=startline,endline do
local thisline = vim.api.nvim_buf_get_lines(0,lnum-1,lnum,false)[1]
if not (thisline:match('^%s*$')) then
if type(P.ftpatterns[ft].is_comment) == 'string' then
-- only one pattern to check
if not thisline:match(P.ftpatterns[ft].is_comment) then
allcommented = false
break
end
else
--multiple patterns to check
local matchany = false
for i,p in ipairs(P.ftpatterns[ft].is_comment) do
if thisline:match(p) then
matchany = true
break
end
end
if not matchany then
allcommented = false
break
end
end
end
end
if (allcommented) then
for lnum=startline,endline do
local thisline = vim.api.nvim_buf_get_lines(0,lnum-1,lnum,false)[1]
thisline = thisline:gsub(
P.ftpatterns[ft].sub_to_uncomment[1],
P.ftpatterns[ft].sub_to_uncomment[2])
vim.api.nvim_buf_set_lines(0,lnum-1,lnum,false,{ thisline })
end
else
for lnum=startline,endline do
local thisline = vim.api.nvim_buf_get_lines(0,lnum-1,lnum,false)[1]
thisline = thisline:gsub(
P.ftpatterns[ft].sub_to_comment[1],
P.ftpatterns[ft].sub_to_comment[2])
vim.api.nvim_buf_set_lines(0,lnum-1,lnum,false,{ thisline })
end
end
end
P.togglecommentsSelection = function()
local startline = vim.api.nvim_buf_get_mark(0,'<')[1]
local endpos = vim.api.nvim_buf_get_mark(0,'>')
local endline = endpos[1]
-- only handle previous lines if cursor at start of line
if (startline ~= endline) and (endpos[2] == 0) then
endline = endline - 1
end
P.togglecomments(startline,endline)
end
P.togglecommentsSingleLine = function()
local linenbr = vim.api.nvim_win_get_cursor(0)[1]
P.togglecomments(linenbr,linenbr)
end
return P
P={}
-- default to non-opaque
P.isopaque = false
-- function to escape termcodes; see https://github.com/nanotee/nvim-lua-guide
local function t(str)
-- Adjust boolean arguments as needed
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
function defer_insert(n)
n = n or 10
vim.defer_fn(function()
vim.cmd('startinsert')
end, n)
end
P.deletesel = function()
local startpos = vim.api.nvim_buf_get_mark(0,'<')
local endpos = vim.api.nvim_buf_get_mark(0,'>')
vim.api.nvim_buf_set_text(0, startpos[1]-1, startpos[2], endpos[1]-1,
endpos[2], {})
end
P.getcitekey = function()
local fzf = require("fzf").fzf
coroutine.wrap(function()
local result = fzf(
'bibentries.lua','--multi --preview "bibsingle.lua {}"'
)
if not (result) then defer_insert() return end
local ft = vim.opt_local.filetype:get()
local ins = ''
local mdown = ((ft=='markdown') or (ft=='markdown.pandoc'))
if (mdown) then ins = '[' end
for i,k in ipairs(result) do
local ckey = vim.split(k,' = ',
{ plain = true, trimempty = true })[1]
if (i>1) then
if (mdown) then
ins = ins .. '; '
else
ins = ins .. ','
end
end
if (mdown) then ins = ins .. '@' end
ins = ins .. ckey
end
if (mdown) then ins = ins .. ']' end
vim.api.nvim_put({ins},"c",false,true)
defer_insert()
end)()
end
-- should move this to lua but nothing works yet
P.goopaque = function ()
vim.api.nvim_set_hl(0, 'Normal', {
fg='#c1c6ca',
bg='#131518',
ctermfg=251,
ctermbg=233
})
vim.api.nvim_set_hl(0, 'NonText', {
fg='#4d5053',
bg='#131518',
ctermfg=239,
ctermbg=233
})
-- for some reason don't work with lua command
vim.cmd('hi CursorLine guibg=#010101')
vim.cmd('hi ColorColumn guibg=#010101')
P.isopaque = true
end
-- should move this to lua but nothing works yet
P.gotransparent = function ()
vim.api.nvim_set_hl(0, 'Normal', {
fg='#c1c6ca',
bg='NONE',
ctermfg=251,
ctermbg='NONE'
})
vim.api.nvim_set_hl(0, 'NonText', {
fg='#4d5053',
bg='NONE',
ctermfg=239,
ctermbg='NONE'
})
-- for some reason don't work with lua command
vim.cmd('hi CursorLine guibg=#131518')
vim.cmd('hi ColorColumn guibg=#131518')
P.isopaque = false
end
P.handletab = function()
local currline = vim.api.nvim_get_current_line()
local col = vim.api.nvim_win_get_cursor(0)[2]
local prec = currline:sub(0,col)
if (prec:match('^%s*$')) then
return t'<Tab>'
end
if (vim.fn.pumvisible() == 1) then
return t'<C-n>'
end
return t'<C-p>'
end
P.opaquetoggle = function()
if (P.isopaque) then
P.gotransparent()
else
P.goopaque()
end
end
P.opennewtab = function(fromdir)
fromdir = fromdir or vim.fn.getcwd()
local fzf = require("fzf").fzf
coroutine.wrap(function()
local result = fzf(
'cd "' .. fromdir .. '" && fd --no-ignore --follow ' ..
'--strip-cwd-prefix --type file --type symlink',
'--multi --preview "file --mime-encoding {} | grep ' ..
'-q binary && echo binary file || nvimpager -c {}"'
)
if not (result) then defer_insert() return end
local bufcontents = vim.api.nvim_buf_get_lines(0,0,2,false)
local isempty = ((#bufcontents < 2) and (bufcontents[1] == ''))
for i,k in ipairs(result) do
local fp=fromdir .. '/' .. k
if ((i==1) and (isempty)) then
-- if is empty, edit in current window and delete
-- previous buffer
local currbuff = vim.api.nvim_win_get_buf(0)
local changed = vim.opt_local.modified:get()
vim.cmd('edit! ' .. fp)
if (changed) then
vim.api.nvim_buf_delete(currbuff, { force = true })
end
else
vim.cmd('tabedit ' .. fp)
end
end
defer_insert()
end)()
end
P.syntaxshow = function()
local cpos = vim.api.nvim_win_get_cursor(0)
local line = cpos[1]
local col = cpos[2]
local synidlist = vim.fn.synstack(line,col)
local synlist = ''
for i,v in ipairs(synidlist) do
if (i ~= 1) then
synlist = synlist .. ' '
end
synlist = synlist .. vim.fn.synIDattr(v,"name")
end
print(synlist)
end
P.xelatexcheck = function()
-- commented out as now using latexcompile.lua
-- local isxelatex = false
-- local fifteenlines = vim.api.nvim_buf_get_lines(0,0,15,false)
-- for l,line in ipairs(fifteenlines) do
-- if (line:lower():match("xelatex")) or
-- (line:match("\\usepackage[^}]*mathspec")) or
-- (line:match("\\usepackage[^}]*fontspec")) or
-- (line:match("\\usepackage[^}]*unicode-math")) then
-- isxelatex = true
-- break
-- end
-- end
-- if (isxelatex) then
-- local knapsettings = vim.b.knap_settings or {}
-- knapsettings["textopdf"] =
-- 'xelatex -interaction=batchmode -halt-on-error -synctex=1 %docroot%'
-- vim.b.knap_settings = knapsettings
-- print("knap settings set to XeLaTeX")
-- else
-- local knapsettings = vim.b.knap_settings or {}
-- knapsettings["textopdf"] =
-- 'pdflatex -interaction=batchmode -halt-on-error -synctex=1 %docroot%'
-- vim.b.knap_settings = knapsettings
-- print("knap settings set to PDFLaTeX")
-- end
end
P.wrapoff = function()
vim.opt_local.wrap = false
pcall(function ()
vim.api.nvim_buf_del_keymap(0,'i','<Up>')
vim.api.nvim_buf_del_keymap(0,'i','<Down>')
vim.api.nvim_buf_del_keymap(0,'i','<S-Up>')
vim.api.nvim_buf_del_keymap(0,'i','<S-Down>')
vim.api.nvim_buf_del_keymap(0,'v','<Up>')
vim.api.nvim_buf_del_keymap(0,'v','<Down>')
vim.api.nvim_buf_del_keymap(0,'v','<S-Up>')
vim.api.nvim_buf_del_keymap(0,'v','<S-Down>')
end)
end
P.wrapon = function()
vim.opt_local.wrap = true
vim.opt_local.linebreak = true
local options = { noremap = true, silent = true }
vim.api.nvim_buf_set_keymap(0,'i','<Up>', '<C-o>gk', options)
vim.api.nvim_buf_set_keymap(0,'i','<Down>', '<C-o>gj', options)
vim.api.nvim_buf_set_keymap(0,'i','<S-Up>', '<C-o>vgk<C-g>',options)
vim.api.nvim_buf_set_keymap(0,'i','<S-Down>','<C-o>vgj<C-g>',options)
vim.api.nvim_buf_set_keymap(0,'v','<Up>', '<C-c>gkgV', options)
vim.api.nvim_buf_set_keymap(0,'v','<Down>', '<C-c>gjgV', options)
vim.api.nvim_buf_set_keymap(0,'v','<S-Up>', 'gk<C-g>', options)
vim.api.nvim_buf_set_keymap(0,'v','<S-Down>','gj<C-g>', options)
end
P.wraptoggle = function()
if (vim.opt_local.wrap:get()) then
P.wrapoff()
else
P.wrapon()
end
end
return P
local runtimepaths = vim.api.nvim_list_runtime_paths()
local uv = vim.loop
local fzf = require('fzf').fzf
local function readfilecb(path, callback)
uv.fs_open(path, "r", 438, function(err, fd)
if err then
callback(err)
return
end
uv.fs_fstat(fd, function(err, stat)
if err then
callback(err)
return
end
uv.fs_read(fd, stat.size, 0, function(err, data)
if err then
callback(err)
return
end
uv.fs_close(fd, function(err)
if err then
callback(err)
return
end
return callback(nil, data)
end)
end)
end)
end)
end
local function readfile(name)
local co = coroutine.running()
readfilecb(name, function (err, data)
coroutine.resume(co, err, data)
end)
local err, data = coroutine.yield()
if err then error(err) end
return data
end
local function deal_with_tags(tagfile, cb)
local co = coroutine.running()
coroutine.wrap(function ()
local success, data = pcall(readfile, tagfile)
if success then
for i, line in ipairs(vim.split(data, "\n")) do
local items = vim.split(line, "\t")
-- escape codes for grey
local tag = string.format("%s\t\27[0;37m%s\27[0m", items[1], items[2])
local co = coroutine.running()
cb(tag, function ()
coroutine.resume(co)
end)
coroutine.yield()
end
end
coroutine.resume(co)
end)()
coroutine.yield()
end
local fzf_function = function (cb)
local total_done = 0
for i, rtp in ipairs(runtimepaths) do
local tagfile = table.concat({rtp, "doc", "tags"}, "/")
-- wrapping to make all the file reading concurrent
coroutine.wrap(function ()
deal_with_tags(tagfile, cb)
total_done = total_done + 1
if total_done == #runtimepaths then
cb(nil)
end
end)()
end
end
local startfunction = function()
coroutine.wrap(function ()
local result = fzf(fzf_function, "--nth 1 --ansi --expect=ctrl-t,ctrl-s,ctrl-h")
if not result then
return
end
local choice = vim.split(result[2], "\t")[1]
local key = result[1]
local windowcmd
if key == "" or key == "ctrl-t" then
windowcmd = "tab"
elseif key == "ctrl-s" then
windowcmd = "vertical"
elseif key == "ctrl-h" then
windowcmd = ""
else
print("Not implemented!")
error("Not implemented!")
end
vim.cmd(string.format("%s h %s", windowcmd, choice))
end)()
end
return startfunction
--[[
Note to self: fzf functions work best when called through keymap
rather than lmap in order to focus right part of popup menu (weird).
--]]
-- shorten call complexity --
local keymap = vim.api.nvim_set_keymap
local lmap = vim.keymap.set
-- most keybinds are silent and/or use noremap --
local silnrm = { silent = true, noremap = true }
local nrm = { noremap = true }
local exprsilnrm = { expr = true, silent = true, noremap = true }
-------------------------------------
------- SHIFT or NO MODIFIERS -------
-------------------------------------
-- disable escape, make C-n go to normal mode --
keymap('i','<Esc>','<Nop>',silnrm)
keymap('v','<Esc>','<Nop>',silnrm)
keymap('i','<C-n>','<C-o>',silnrm)
-- Arrow keys move in visual space, not real line space --
keymap('i','<Up>', '<C-o>gk', silnrm)
keymap('i','<Down>', '<C-o>gj', silnrm)
keymap('i','<S-Up>', '<C-o>vgk<C-g>',silnrm)
keymap('i','<S-Down>','<C-o>vgj<C-g>',silnrm)
keymap('v','<Up>', '<C-c>gkgV', silnrm)
keymap('v','<Down>', '<C-c>gjgV', silnrm)
keymap('v','<S-Up>', 'gk<C-g>', silnrm)
keymap('v','<S-Down>','gj<C-g>', silnrm)
-- backspace in visual mode deletes selection--
keymap('v','<BS>','d',silnrm)
-- Tab in visual mode indents --
keymap('v','<Tab>','>',silnrm)
-- in insert mode, either indents, starts completion, or navigates Popup --
lmap('i', '<Tab>', kckfns.handletab, {expr = true })
-- Shift-Tab in visual mode reapplies autoindent --
keymap('v','<S-Tab>','=<C-g>',silnrm)
-- in insert mode, either goes back in popup or reapplies indent --
keymap('i','<S-Tab>','pumvisible() ? "\\<C-p>" : "\\<C-o>=="',exprsilnrm)
-- Shift-Del is cut --
if (_G.kckpluginsloaded) then
keymap('v','<S-Del>','<C-c>:OSCYank<CR>gv"+x',silnrm)
else
keymap('v','<S-Del>','"+x',silnrm)
end
-- Shift-Insert is paste --
keymap('i','<S-Insert>','<C-o>"+gP',silnrm)
keymap('c','<S-Insert>','<C-r>+',silnrm)
keymap('v','<S-Insert>','<C-c>"+gP',silnrm)
------------------------
------- CONTROL --------
------------------------
-- Ctrl-A select all --
keymap('i','<C-a>','<C-o>gg<C-o>gH<C-o>G',silnrm)
keymap('o','<C-a>','<C-c>gggH<C-o>G',silnrm)
keymap('s','<C-a>','<C-c>gggH<C-o>G',silnrm)
keymap('x','<C-a>','<C-c>ggVG',silnrm)
-- except in command line, make it go to start --
keymap('c','<C-a>','<C-b>',silnrm)
-- Ctrl-B to clear highlights--
keymap('i','<C-b>','<C-o>:nohls<CR>',silnrm)
keymap('v','<C-b>','<C-c>:nohls<CR>',silnrm)
-- Ctrl-C is copy --
if (_G.kckpluginsloaded) then
keymap('i','<C-c>','<C-o>V:OSCYank<CR>',silnrm)
keymap('v','<C-c>','<C-c>:OSCYank<CR>',silnrm)
else
keymap('i','<C-c>','<C-o>yy',silnrm)
keymap('v','<C-c>','"+y`>gV',silnrm)
end
-- Ctrl-D Duplicate line--
keymap('i','<C-d>','<C-o>yy<C-o>p',silnrm)
keymap('v','<C-d>','<C-c>yy<C-c>p',silnrm)
-- Ctrl-E for command line --
keymap('i','<C-e>','<C-o>:',nrm)
keymap('v','<C-e>','<C-c>:',nrm)
-- Ctrl-F to find --
keymap('i','<C-f>','<C-o>/',nrm)
keymap('v','<C-f>','<C-c>/\\%V',nrm)
-- Ctrl-G to find again? --
keymap('i','<C-g>','<C-o>n',nrm)
keymap('v','<C-g>','n',nrm)
-- in command line, neomutt like cancel command --
keymap('c','<C-g>','<Esc>',silnrm)
-- Ctrl-H return to last editing
keymap('i','<C-h>','<C-o>``',silnrm)
-- Ctrl-J to join
keymap('i','<C-j>','<C-o>J',nrm)
keymap('v','<C-j>','J',nrm)
-- Ctrl-K kill rest of line
keymap('i','<C-k>','<C-o>C',silnrm)
keymap('v','<C-k>','x',silnrm)
-- Ctrl-L to insert citation
keymap('i','<C-l>','<C-o>:lua kckfns.getcitekey()<CR>',silnrm)
keymap('v','<C-l>','<C-c>:lua kckfns.getcitekey()<CR>',silnrm)
-- Ctrl-Q to quit--
keymap('i','<C-q>','<C-o>:q<CR>',nrm)
keymap('v','<C-q>','<C-c>:q<CR>',nrm)
-- Ctrl-R to replace--
keymap('i','<C-r>','<C-o>:%s/',nrm)
keymap('v','<C-r>',"<C-c>:'<,'>s/",nrm)
-- Ctrl-S to save --
keymap('i','<C-s>','<C-o>:update<CR>',nrm)
keymap('v','<C-s>','<C-c>:update<CR>',nrm)
-- Ctrl-T to launch FZF opener --
keymap('c', '<C-t>', '<C-e><C-u>:lua kckfns.opennewtab()<CR>',silnrm)
keymap('i', '<C-t>', '<C-o>:lua kckfns.opennewtab()<CR>',silnrm)
keymap('v', '<C-t>', '<C-c>:lua kckfns.opennewtab()<CR>',silnrm)
-- CTRL-V is Paste--
keymap('i','<C-v>','<C-o>"+gP',silnrm)
keymap('c','<C-v>','<C-r>+',silnrm)
keymap('v','<C-v>','<C-c>"+gP',silnrm)
-- Ctrl-W to toggle wrap mode --
lmap('i','<C-w>', kckfns.wraptoggle)
lmap('v','<C-w>', kckfns.wraptoggle)
-- Ctrl-X cut or delete line--
if (_G.kckpluginsloaded) then
keymap('i','<C-x>','<C-o>V:OSCYank<CR><C-o>dd',silnrm)
keymap('v','<C-x>','<C-c>:OSCYank<CR>gv"+x',silnrm)
else
keymap('i','<C-x>','<C-o>dd',silnrm)
keymap('v','<C-x>','"+x',silnrm)
end
-- Ctrl-Y redo --
keymap('i','<C-y>','<C-o><C-r>',silnrm)
keymap('v','<C-y>','<C-c><C-r>',silnrm)
-- Ctrl-Z undo --
keymap('i','<C-z>','<C-o>u',silnrm)
keymap('v','<C-z>','<C-c>u',silnrm)
-- Ctrl-Space for omnicompletion --
keymap('i','<C-Space>','<C-x><C-o>',nrm)
-- Ctrl up, Ctrl Down to add lines --
keymap('i','<C-Up>','<C-o>O',silnrm)
keymap('i','<C-Down>','<C-o>o',silnrm)
-- Ctrl-\ to pipe selection --
keymap('v','<C-\\>',':!',nrm)
-- Ctrl-Insert is copy --
if (_G.kckpluginsloaded) then
keymap('v','<C-Insert>','<C-c>:OSCYank<CR>',silnrm)
else
keymap('v','<C-Insert>','"+y',silnrm)
end
-- Ctrl F1-F12 are available --
keymap('i','<F25>','<Nop>',silnrm)
keymap('i','<F26>','<Nop>',silnrm)
keymap('i','<F27>','<Nop>',silnrm)
keymap('i','<F28>','<Nop>',silnrm)
keymap('i','<F29>','<Nop>',silnrm)
keymap('i','<F30>','<Nop>',silnrm)
keymap('i','<F31>','<Nop>',silnrm)
keymap('i','<F32>','<Nop>',silnrm)
keymap('i','<F33>','<Nop>',silnrm)
keymap('i','<F34>','<Nop>',silnrm)
keymap('i','<F35>','<Nop>',silnrm)
keymap('i','<F36>','<Nop>',silnrm)
-- Ctrl-Shift F1-F12 are available --
keymap('i','<F37>','<Nop>',silnrm)
keymap('i','<F38>','<Nop>',silnrm)
keymap('i','<F39>','<Nop>',silnrm)
keymap('i','<F40>','<Nop>',silnrm)
keymap('i','<F41>','<Nop>',silnrm)
keymap('i','<F42>','<Nop>',silnrm)
keymap('i','<F43>','<Nop>',silnrm)
keymap('i','<F44>','<Nop>',silnrm)
keymap('i','<F45>','<Nop>',silnrm)
keymap('i','<F46>','<Nop>',silnrm)
keymap('i','<F47>','<Nop>',silnrm)
keymap('i','<F48>','<Nop>',silnrm)
---------------------
-------- ALT --------
---------------------
-- Alt-A restores last selection --
keymap('i','<M-a>','<C-o>gv',silnrm)
--Alt-B to suggest alternative spelling --
keymap('i','<M-b>','<C-o>z=',nrm)
keymap('v','<M-b>','<C-c>z=',nrm)
--Alt-C to clean LaTeX files --
keymap('i','<M-c>','', { callback = function()
if (kcktexfns.ltclean ~= nil) then
kcktexfns.ltclean()
end
end, noremap = true })
keymap('v','<M-c>','', { callback = function()
if (kcktexfns.ltclean ~= nil) then
kcktexfns.ltclean()
end
end, noremap = true })
-- Alt-D for dictionary completion popup
keymap('i','<M-d>','<C-x><C-k>',nrm)
-- Alt-E left available to show errors (tex.vim) --
keymap('i','<M-e>','<Nop>',silnrm)
keymap('v','<M-e>','<Nop>',silnrm)
-- Alt-F for filename completion
keymap('i','<M-f>','<C-x><C-f>',nrm)
-- Alt-G to add to spellcheck dictionary --
keymap('i','<M-g>','<C-o>zg',nrm)
keymap('v','<M-g>','<C-c>zg',nrm)
-- Alt-H return to last editing
keymap('i','<M-h>','<C-o>``',silnrm)
-- Alt-J jump to mark --
keymap('i','<M-j>','<C-o>`',silnrm)
-- Alt-M set mark --
keymap('i','<M-m>','<C-o>m',silnrm)
-- Alt-O toggle opaque background --
lmap('i','<M-o>', kckfns.opaquetoggle)
lmap('v','<M-o>', kckfns.opaquetoggle)
-- Alt-Shift-Q to really quit! --
keymap('i','<M-Q>','<C-o>:q!<CR>',nrm)
keymap('v','<M-Q>','<C-c>:q!<CR>',nrm)
-- Alt-T to toggle a fold--
keymap('i','<M-t>','<C-o>za',nrm)
keymap('v','<M-t>','<C-c>za',nrm)
-- Alt-V restores last selection --
keymap('i','<M-v>','<C-o>gv',silnrm)
-- Alt-X for XeLaTeX check
lmap('i','<M-x>', function()
if (kckfns.xelatexcheck ~= nil) then
kckfns.xelatexcheck()
end
end)
lmap('v','<M-x>',function()
if (kckfns.xelatexcheck ~= nil) then
kckfns.xelatexcheck()
end
end)
-- Alt-up, alt-down moves lines --
keymap('i','<M-Up>','<C-o>dd<C-o>k<C-o>P',silnrm)
keymap('i','<M-Down>','<C-o>dd<C-o>p',silnrm)
keymap('v','<M-Up>','<C-c>dd<C-c>k<C-c>P',silnrm)
keymap('v','<M-Down>','<C-c>dd<C-c>p',silnrm)
-- Alt-1 through 4 template insertion
lmap('i','<M-1>', function() require("templates")(1,false) end)
lmap('i','<M-2>', function() require("templates")(2,false) end)
lmap('i','<M-3>', function() require("templates")(3,false) end)
lmap('i','<M-4>', function() require("templates")(4,false) end)
-- these don't work well with lua callback; no way to delete
lmap('v','<M-1>', function() require("templates")(1,true) end)
lmap('v','<M-2>', function() require("templates")(2,true) end)
lmap('v','<M-3>', function() require("templates")(3,true) end)
lmap('v','<M-4>', function() require("templates")(4,true) end)
-- Alt-5/% jump to matching bracket/parentheses --
keymap('i','<M-5>','<C-o>%',silnrm)
keymap('v','<M-5>','<C-c>%',silnrm)
-- Alt (/9, Alt )/0, next/previous sentence --
keymap('i','<M-)>','<C-o>)',silnrm)
keymap('i','<M-(>','<C-o>(',silnrm)
keymap('i','<M-0>','<C-o>)',silnrm)
keymap('i','<M-9>','<C-o>(',silnrm)
-- Alt ]}/{[, next/prev paragraphs --
keymap('i','<M-]>','<C-o>}',silnrm)
keymap('i','<M-[>','<C-o>{',silnrm)
keymap('i','<M-}>','<C-o>}',silnrm)
keymap('i','<M-{>','<C-o>{',silnrm)
-- Alt ./<, ,/> indents/unindents --
keymap('i','<M-.>','<C-t>',silnrm)
keymap('i','<M-,>','<C-d>',silnrm)
keymap('v','<M-.>','>',silnrm)
keymap('v','<M-,>','<',silnrm)
-- Alt-/Alt=(+) increments or deincrement numbers --
keymap('i','<M-=>','<C-o><C-a>',silnrm)
keymap('i','<M-->','<C-o><C-x>',silnrm)
keymap('v','<M-=>','<C-c><C-a>',silnrm)
keymap('v','<M-->','<C-c><C-x>',silnrm)
-- Alt-Shift-Home/Alt-Shift-End selects to end or start--
keymap('i','<S-M-End>','<C-o>vG$<C-g>',silnrm)
keymap('i','<S-M-Home>','<C-o>vgg<C-g>',silnrm)
keymap('v','<S-M-End>','G$<C-g>',silnrm)
keymap('v','<S-M-Home>','gg<C-g>',silnrm)
-- Ctrl-Tab, Alt-Tab, Alt-Shift-Tab, Ctrl-Shift-Tab next/prev tab --
keymap('i','<C-Tab>','<C-o>:tabnext<CR>',silnrm)
keymap('i','<M-Tab>','<C-o>:tabnext<CR>',silnrm)
keymap('i','<M-S-Tab>','<C-o>:tabprevious<CR>',silnrm)
keymap('i','<C-S-Tab>','<C-o>:tabprevious<CR>',silnrm)
-- Alt / toggles commented out --
lmap('i','<M-/>', function()
require("commenter").togglecommentsSingleLine()
end)
lmap('n','<M-/>', function()
require("commenter").togglecommentsSingleLine()
end)
-- visual mapping doesn't work as callback; doesn't register marks
keymap('v','<M-/>', '<C-c>:lua require("commenter").' ..
'togglecommentsSelection()<CR>gv', silnrm)
---------------------------------
-------- CTRL ALT ---------------
---------------------------------
-- Ctrl-Alt C to open color chooser
keymap('i', '<C-M-c>', '<C-o>:lua require("colorpicker")()<CR>', silnrm)
keymap('v', '<C-M-c>', '<C-c>:lua require("colorpicker")()<CR>', silnrm)
-- Ctrl-Alt T to open file from home folder
keymap('i', '<C-M-t>', '<C-o>:lua kckfns.opennewtab' ..
'(os.getenv("HOME"))<CR>',silnrm)
keymap('v', '<C-M-t>', '<C-c>:lua kckfns.opennewtab' ..
'(os.getenv("HOME"))<CR>',silnrm)
keymap('c', '<C-M-t>', '<C-e><C-u>:lua kckfns.opennewtab' ..
'(os.getenv("HOME"))<CR>',silnrm)
---------------------------------
-------- FUNCTION KEYS ----------
---------------------------------
-- F1 for help searcher
keymap('i','<F1>','<C-o>:lua require("helptagsearch")()<CR>',silnrm)
keymap('v','<F1>','<C-c>:lua require("helptagsearch")()<CR>',silnrm)
-- Shift F1/F2 navigate between tabs --
keymap('i','<F13>','<C-o>:tabprevious<CR>',silnrm)
keymap('i','<F14>','<C-o>:tabnext<CR>',silnrm)
--- F2 show syntax categories ---
lmap('i','<F2>', kckfns.syntaxshow)
lmap('v','<F2>', kckfns.syntaxshow)
-- F3 switch windows --
keymap('i','<F3>','<C-o><C-w><C-w>',silnrm)
keymap('v','<F3>','<C-c><C-w><C-w>',silnrm)
-- Shift-F3 available
keymap('i','<F15>','<Nop>',silnrm)
-- F4 is available! --
keymap('i','<F4>','<Nop>',silnrm)
-- Shift-F4 is available !
keymap('i','<F16>','<Nop>',silnrm)
--------------------- KNAP functions -----------------------------------
-- F5 processes the document once, and refreshes the view
lmap('i','<F5>', function() require("knap").process_once() end)
lmap('v','<F5>', function() require("knap").process_once() end)
lmap('n','<F5>', function() require("knap").process_once() end)
-- F6 closes the viewer application, and allows settings to be reset
lmap('i','<F6>', function() require("knap").close_viewer() end)
lmap('v','<F6>', function() require("knap").close_viewer() end)
lmap('n','<F6>', function() require("knap").close_viewer() end)
-- F7 toggles the auto-processing on and off
lmap('i','<F7>', function() require("knap").toggle_autopreviewing() end)
lmap('v','<F7>', function() require("knap").toggle_autopreviewing() end)
lmap('n','<F7>', function() require("knap").toggle_autopreviewing() end)
-- F8 invokes a SyncTeX forward search, or similar, where appropriate
lmap('i','<F8>', function() require("knap").forward_jump() end)
lmap('v','<F8>', function() require("knap").forward_jump() end)
lmap('n','<F8>', function() require("knap").forward_jump() end)
------------------------------------------------------------------------
-- F9 through F12 are available! --
keymap('i','<F9>','<Nop>',silnrm)
keymap('i','<F10>','<Nop>',silnrm)
keymap('i','<F11>','<Nop>',silnrm)
keymap('i','<F12>','<Nop>',silnrm)
-- Shift F5-F12 are available --
keymap('i','<F17>','<Nop>',silnrm)
keymap('i','<F18>','<Nop>',silnrm)
keymap('i','<F19>','<Nop>',silnrm)
keymap('i','<F20>','<Nop>',silnrm)
keymap('i','<F21>','<Nop>',silnrm)
keymap('i','<F22>','<Nop>',silnrm)
keymap('i','<F23>','<Nop>',silnrm)
keymap('i','<F24>','<Nop>',silnrm)
-------------------------
------- SPECIAL ---------
-------------------------
-- w!! write to file I don't have permissions for --
keymap('c', 'w!!', 'w !sudo tee %', { noremap = false })
-- workaround partial kludge for select and middleclick --
keymap('v', '<LeftRelease>', '"*ygv', silnrm)
local opt = vim.opt
-- automatically change directory when opening file
opt.autochdir = true
-- indent of new lines follows previous ones
opt.autoindent = true
-- backups
opt.backup = true
opt.backupdir = vim.env.HOME .. '/.local/share/nvim/backup/'
-- wrapped lines use same indent
opt.breakindent = true
-- smart indenting
opt.cindent = true
-- use system clipboard
opt.clipboard:append({'unnamedplus','unnamed'})
-- make one column a different color
opt.colorcolumn = '75'
-- use these forms of completion
opt.complete:append({'w','b','u','t','i'})
-- completion menu, even with one option; longest common string
opt.completeopt:append({'menuone','longest'})
-- highlight active line
opt.cursorline = true
-- use spaces instead of tabs
opt.expandtab = true
-- folding by marker, do not open with horizontal movement; close automatically
opt.foldclose = 'all'
opt.foldmethod = 'marker'
opt.foldmarker = '{FOLDON,FOLDOFF}'
opt.foldopen:remove({'hor'})
-- prereq for smartcase
opt.ignorecase = true
-- always start in insert mode
opt.insertmode = true
-- no double spaces when joining
opt.joinspaces = false
-- shift keys for selecting
opt.keymodel = 'startsel,stopsel'
-- wrap lines at boundaries
opt.linebreak = true
-- show white space at end of line
opt.list = true
-- also match < >
opt.matchpairs:append({'<:>'})
-- use mouse in all modes and dialogues
opt.mouse = 'ar'
-- focus follows mouse
opt.mousefocus = true
-- right click pop up?
opt.mousemodel = 'popup'
-- use line numbers
opt.number = true
-- use ms-style selections
opt.selection = 'exclusive'
opt.selectmode = 'mouse,key'
-- lines above/below cursor
opt.scrolloff = 2
-- number of spaces when auto-indenting
opt.shiftwidth = 4
-- get rid of completion messages
opt.shortmess = opt.shortmess + 'c'
-- don't read insert at bottom
opt.showmode = false
-- insensitive search except when uppercase used
opt.smartcase = true
-- spell checking; hope I don't regret this
opt.spell = true
-- horizontal splits go on the bottom
opt.splitbelow = true
-- vertical splits go on the right
opt.splitright = true
-- tabs are 4 spaces
opt.tabstop = 4
-- use full color spectrum in terminal
opt.termguicolors = true
-- use file title as terminal title
opt.title = true
opt.titlestring = '%(%{expand(\"%:p:t\")}%) — nvim'
-- undo file: keeps undo history persistent
opt.undofile= true
opt.undodir = vim.env.HOME .. '/.local/share/nvim/undo/'
-- don't allow cursor in empty space
opt.virtualedit = ''
-- make arrow keys traverse lines
opt.whichwrap = opt.whichwrap + '<,>,[,]'
-- start in wrap mode
opt.wrap = true
-- PAQ package manager: https://github.com/savq/paq-nvim
-- if paq not installed, just return
if vim.fn.filereadable(vim.env.HOME .. '/.local/share/nvim/site/pack/paqs/start/paq-nvim/lua/paq.lua') == 0 then
return
end
-- load plugins
require "paq" {
-- this package manager
"savq/paq-nvim";
-- show color codes as actual color
"norcalli/nvim-colorizer.lua";
-- draws vertical lines for indentation levels
"lukas-reineke/indent-blankline.nvim";
-- allow copying to local clipboard over ssh with escape codes
"ojroques/vim-oscyank";
-- better syntax highlighting for markdown
"vim-pandoc/vim-pandoc-syntax";
-- use fzf as searcher/chooser inside neovim
"vijaymarupudi/nvim-fzf";
}
-- set up indentation line plugin
require("indent_blankline").setup {
space_char_blankline = " ",
char_highlight_list = {
"IndentBlanklineIndent1",
"IndentBlanklineIndent2",
"IndentBlanklineIndent3",
"IndentBlanklineIndent4",
"IndentBlanklineIndent5",
"IndentBlanklineIndent6",
}
}
-- also in options, but required for colorizer setup
vim.opt.termguicolors = true
require('colorizer').setup()
-- set variable marking plugins loaded
_G.kckpluginsloaded = true
function inserttemplate(n,delsel)
if (delsel) then
local mode = vim.fn.mode()
print("mode is " .. mode)
local vis = vim.fn.getpos("v")
sl = vis[2] - 1
sc = vis[3] - 1
local cpos = vim.api.nvim_win_get_cursor(0)
el = cpos[1] - 1
ec = cpos[2]
if ((el < sl) or ((el == sl) and (ec < sc))) then
sl, sc, el, ec = el, ec, sl, sc
end
if (mode == "V") then
vim.api.nvim_buf_set_lines(0,sl,el+1,false,{})
else
vim.api.nvim_buf_set_text(0,sl,sc,el,ec,{})
end
end
local ft = vim.opt_local.filetype:get()
local fn = vim.env.HOME .. '/.config/nvim/templates/' .. ft ..
tostring(n) .. '.template'
if (vim.fn.filereadable(fn) == 0) then
vim.api.nvim_err_writeln(ft .. tostring(n) ..
'.template not found')
return
end
local file = io.open(fn,"r")
local templatelines = {}
for line in file:lines() do
table.insert(templatelines, line);
end
file:close()
vim.api.nvim_buf_set_lines(0,0,0,false,templatelines)
vim.api.nvim_win_set_cursor(0,{1,0})
end
return inserttemplate
-- auto Fix common typos --
vim.cmd('iabbrev hte the')
vim.cmd('iabbrev teh the')
vim.cmd('iabbrev THe The')
vim.cmd('iabbrev ANd And')
-- set colorscheme
vim.g.colors_name = 'ThemerVim-transparent'
vim.o.background = vim.o.background
-- fix tab line color, because it doesn't work from
-- colorscheme for unknown reasons
vim.api.nvim_set_hl(0, 'TabLineFill', { bg='#303236' })
-- start in opaque mode
kckfns.goopaque()
-- allow ctrl-i to be mapped differently from tab
if (vim.env.TERM == 'xterm-kitty') then
vim.cmd([[autocmd UIEnter * if v:event.chan ==# 0 | call chansend(v:stderr, "\x1b[>1u") | endif]])
vim.cmd([[autocmd UILeave * if v:event.chan ==# 0 | call chansend(v:stderr, "\x1b[<1u") | endif]])
end
-- open all files in tabs
vim.cmd('tab all')
@frabjous
Copy link
Author

frabjous commented Jun 11, 2022

Note: GitHub doesn't let me put gist files in subfolders, so the '-' represents a subfolder slash, i.e., 'lua - plugins.lua' should be 'lua/plugins.lua' relative to $HOME/.config/nvim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment