~charles/dotfiles

39cbce2f4cdb15642f4d8937742ec693816e38e3 — Charles Daniels 2 months ago 011fb3c
switch to using lua-based neovim configuration
M install-full.sh => install-full.sh +6 -0
@@ 50,6 50,12 @@ curl -SsfLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
curl -SsfLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

# packer.nvim
if [ ! -e  ~/.local/share/nvim/site/pack/packer/start/packer.nvim ] ; then
	git clone https://github.com/wbthomason/packer.nvim \
	    ~/.local/share/nvim/site/pack/packer/start/packer.nvim
fi


# Eisvogel
if [ ! -e "$HOME/.pandoc/templates/eisvogel.tex" ] ; then

A overlay.full/.config/nvim/ginit.vim => overlay.full/.config/nvim/ginit.vim +21 -0
@@ 0,0 1,21 @@
" Set Editor Font
if exists(':GuiFont')
    GuiFont! Spleen:h14
endif

if exists(':GuiTabline')
    GuiTabline 1
endif

if exists(':GuiPopupmenu')
    GuiPopupmenu 1
endif

if exists(':GuiScrollBar')
    GuiScrollBar 0
endif

" Right Click Context Menu (Copy-Cut-Paste)
nnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>
inoremap <silent><RightMouse> <Esc>:call GuiShowContextMenu()<CR>
vnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>gv

A overlay.full/.config/nvim/init.lua => overlay.full/.config/nvim/init.lua +248 -0
@@ 0,0 1,248 @@
local o = vim.o  -- global options
local w = vim.wo -- window local options
local b = vim.bo -- buffer local options
local g = vim.g  -- editor global options
local t = vim.t  -- tapage-scoped options

local utils = require('utils')

-- set , to be the leader key
vim.g.mapleader = ','

-- automatically gues filetype and indent based on file contents
vim.api.nvim_command("filetype plugin indent on")

-- fix dumb default backspace behavior
o.backspace = [[indent,eol,start]]

-- enable syntax highlighting
o.syntax = 'on'

-- underline the current line
o.cursorline = true
vim.api.nvim_command("hi clear CursorLine")
vim.api.nvim_command("hi CursorLine gui=underline cterm=underline")

-- enable line numbering
o.number = true

-- always show the statusline
o.laststatus=2

-- use case insensitive searches by default, unless capital letters are used
o.ignorecase=true
o.smartcase=true

-- show column and line number in statusline
o.ruler = true

-- disable line wrapping (dosen't work with vim.o for some reason?)
g.nowrap=true

-- enable content continuation on enter
o.formatoptions = o.formatoptions .. 'cro'

-- use a light background
o.bg = "light"

-- explcitly use the defualt colorscheme (we'll override this for the GUI later)
g.colors_name = "default"

-- don't show the welcome message on blank files
o.shortmess = o.shortmess .. "I"

-- allow visual block past EOL
o.virtualedit = "block"

-- set backup directories
o.directory = os.getenv("HOME") .. "/.nvimbak"
o.backupdir = os.getenv("HOME") .. "/.nvimbak"
o.undodir = os.getenv("HOME") .. "/.nvimbak"

-- interactive menu for tab-completing buffers and such
o.wildmenu = true
o.wildmode = [[longest:full]]

-- show visual rulers every 80 columns
o.colorcolumn=[[80,160,240,320,400,480,660,740,820]]
vim.api.nvim_command("hi ColorColumn ctermbg=red guibg=red")

-- enable relative numbering
o.relativenumber = true

-- enable mouse support
o.mouse = "a"

-- copy to system clipboard with ,yc
utils.map("n", "<Leader>yc", [["+yy]], {noremap=true})
utils.map("v", "<Leader>yc", [["+yy]], {noremap=true})

-- navigate windows using C-{h,j,k,l}
vim.api.nvim_command("nnoremap <C-h> <C-w>h")
vim.api.nvim_command("nnoremap <BS> <C-w>h")  -- workaround for nvim handling of C-h
vim.api.nvim_command("nnoremap <C-j> <C-w>j")
vim.api.nvim_command("nnoremap <C-k> <C-w>k")
vim.api.nvim_command("nnoremap <C-l> <C-w>l")


-- use ,fl to fill line with character
utils.map("n", "<Leader>fl", [[y1l$80p079ld$]], {noremap=true})

-- only use manual code folding by default
o.foldmethod = "manual"

-- automatucally unfold on new files
vim.api.nvim_command([[autocmd BufWinEnter * silent! :%foldopen!]])

-- bind C-n to :noh
utils.map("n", "<C-n>", ":noh<CR>", {noremap=true})

-- open new tab with C-t
utils.map("n", "<C-t>", ":tabnew<CR>", {noremap=true})

-- don't open help with F1
utils.map("n", "<F1>", "<nop>", {noremap=true})

-- listchars setup, shows certain non-printing characters
o.list = true
o.listchars = [[trail:¬,precedes:«,extends:»,tab:→⋅]]

-- indentation settings
function TwoSpacesSoftTabs()
	vim.o.tabstop = 2
	vim.o.shiftwidth = 2
	vim.o.softtabstop = 2
	vim.o.expandtab = true
end

function FourSpacesSoftTabs()
	vim.o.tabstop = 4
	vim.o.shiftwidth = 4
	vim.o.softtabstop = 4
	vim.o.expandtab = true
end

function FourSpacesHardTabs()
	vim.o.tabstop = 4
	vim.o.shiftwidth = 4
	vim.o.softtabstop = 4
	vim.o.expandtab = false
end

function EightSpacesHardTabs()
	vim.o.tabstop = 8
	vim.o.shiftwidth = 8
	vim.o.softtabstop = 8
	vim.o.expandtab = false
end

EightSpacesHardTabs()

-- override filetype setting based on extension
function extensionOverride(extensions, filetype)
	vim.api.nvim_command("autocmd BufNewFile,BufRead " .. extensions .. " set filetype=" .. filetype)
end
extensionOverride("*.h,*.c", "c")
extensionOverride("*.v", "verilog")
extensionOverride("*.tv", "text")
extensionOverride("*.tex,*.sty", "tex")
extensionOverride("*.yml,*.yaml,Sakefile", "yaml")
extensionOverride("*.pmg", "markdown")

-- override tab and space behavior per file
function ftIndent(filetype, behavior)
	vim.api.nvim_command("autocmd FileType " .. filetype .. " lua " .. behavior)
end
ftIndent("c", "EightSpacesHardTabs()")
ftIndent("sql", "EightSpacesHardTabs()")
ftIndent("go", "EightSpacesHardTabs()")
ftIndent("html", "FourSpacesSoftTabs()")
ftIndent("java", "FourSpacesSoftTabs()")
ftIndent("javascript", "FourSpacesSoftTabs()")
ftIndent("json", "FourSpacesSoftTabs()")
ftIndent("matlab", "FourSpacesSoftTabs()")
ftIndent("perl", "EightSpacesHardTabs()")
ftIndent("python", "FourSpacesSoftTabs()")
ftIndent("rst", "FourSpacesSoftTabs()")
ftIndent("sh", "EightSpacesHardTabs()")
ftIndent("tcl", "EightSpacesHardTabs()")
ftIndent("tex", "EightSpacesHardTabs()")
ftIndent("verilog", "EightSpacesHardTabs()")
ftIndent("yaml", "TwoSpacesSoftTabs()")
ftIndent("toml", "FourSpacesSoftTabs()")
ftIndent("xml", "FourSpacesSoftTabs()")

-- text wrapping (gq) behavior
o.showbreak = [[\_]]
o.breakindent = true
o.formatoptions = o.formatoptions .. "q" -- allow gqq to wrap comments
o.wrap = true
o.linebreak = true
o.textwidth = 0
o.wrapmargin = 0

-- spell checking
o.spell = true
o.spelllang = "en_us"
o.complete = o.complete .. ",kspell"
vim.api.nvim_command("highlight clear SpellBad")
vim.api.nvim_command("highlight clear SpellCap")
vim.api.nvim_command("highlight clear SpellRare")
vim.api.nvim_command("highlight clear SpellLocal")
vim.api.nvim_command("highlight SpellBad cterm=underline gui=underline")
vim.api.nvim_command("highlight SpellLocal cterm=underline gui=underline")

-- load plugins
require("plugins")

-- NERDTree setup
utils.map("n", "<C-e>", [[:silent! lua NERDTreeToggleInCurDir()<CR>]])
function NERDTreeToggleInCurDir()
	if (t.NERDTreeBufName ~= nil) and (vim.fn.bufwinnr(t.NERDTreeBufName) ~= -1)  then
		vim.api.nvim_command([[exe ":NERDTreeClose"]])
	else
		vim.api.nvim_command([[exe ":NERDTreeFind"]])
		vim.api.nvim_command("g:NERDTree.ForCurrentTab().getRoot().refresh() | g:NERDTree.ForCurrentTab().getRoot().render() | wincmd w")
	end
end

-- NERDCommenter setup
g.NERDSpaceDelims = 0 -- extra spaces after comment char
g.NERDDefaultAlign = 'left' --  align comments to left edge of fiel
g.NERDCommentEmptyLines = 1 -- allow empty lines to be commented

-- tagbar setup
utils.map("n", "<F8>", ":TagbarToggle<CR>")
utils.map("v", "<F8>", ":TagbarToggle<CR>")

-- auto docsting generation
vim.api.nvim_command([[autocmd FileType java nmap <silent> <C-g> :call JCommentWriter()<CR>]])  -- for jcommenter
vim.api.nvim_command([[autocmd FileType java let b:jcommenter_class_author=system('git config user.name')]])
vim.api.nvim_command([[autocmd FileType java let b:jcommenter_file_author=system('git config user.email')]])

vim.api.nvim_command([[autocmd FileType python nmap <silent> <C-g> <Plug>(pydocstring)]]) -- for pydocstring
g.pydocstring_doq_path = "~/.local/bin/doq" -- fix doq search path

-- trailer trash setup
vim.api.nvim_command([[autocmd BufEnter * TrailerHide]])
vim.api.nvim_command([[autocmd InsertLeave * TrailerHide]])
utils.map("n", "<Leader>tt", ":TrailerTrim<CR>", {noremap = true})

-- ctrlp configuration
g.ctrlp_show_hidden = 1
g.ctrlp_dotfiles = 1
g.ctrlp_working_path_mode = 'a'
g.ctrlp_switch_buffer = 0
g.ctrlp_max_depth = 100
g.ctrlp_max_files = 500000

-- fugative.vim
o.statusline=[[%<%f %h%m%r%=%-14.(%l,%c%V%) %{FugitiveStatusline()} %P]]

-- vim-go
g.go_def_mapping_enabled = 0 -- don't override C-t

-- gruvbox
g.gruvbox_contrast_light = 'hard'
vim.api.nvim_command([[colorscheme gruvbox]])


D overlay.full/.config/nvim/init.vim => overlay.full/.config/nvim/init.vim +0 -13
@@ 1,13 0,0 @@
source ~/.vimrc

""""""""10""""""""20"" vim-tmux-navigator configuration ""60""""""""70""""""""80

function TerminalMapTmuxNavigator ()
	tnoremap<silent> <C-h> <C-\><C-N>:TmuxNavigateLeft<cr>
	tnoremap<silent> <C-j> <C-\><C-N>:TmuxNavigateDown<cr>
	tnoremap<silent> <C-k> <C-\><C-N>:TmuxNavigateUp<cr>
	tnoremap<silent> <C-l> <C-\><C-N>:TmuxNavigateRight<cr>
endfunction

" other plugins insist on overriding vim-tmux-navigator's bindings
autocmd BufEnter,BufWritePost * call TerminalMapTmuxNavigator()

A overlay.full/.config/nvim/lua/plugins.lua => overlay.full/.config/nvim/lua/plugins.lua +65 -0
@@ 0,0 1,65 @@
-- Only required if you have packer configured as `opt`
vim.cmd [[packadd packer.nvim]]

return require("packer").startup(function()
	use 'wbthomason/packer.nvim'
 	use 'coyotebush/vim-pweave'
	use 'PProvost/vim-ps1'
	use 'gi1242/vim-tex-syntax'
	use 'tpope/vim-fugitive'
	use 'https://tildegit.org/sloum/gemini-vim-syntax'
	use 'lazywei/vim-matlab'
	use 'morhetz/gruvbox'
	use 'airblade/vim-gitgutter'
	use 'cappyzawa/starlark.vim'

	use {
		"scrooloose/nerdtree",
		cmd = {"NERDTreeClose", "NERDTreeFind"}
	}

	use {
		"preservim/tagbar",
		cmd = {"TagbarToggle"}
	}

	use {
		'heavenshell/vim-pydocstring',
		ft = {"python"}
	}

	use {
		'twmht/jcommenter.vim',
		ft = {"java"}
	}

	use {
		'csexton/trailertrash.vim',
		cmd = {"TrailerTrim", "TrailerHide"}
	}

	use {
		'ctrlpvim/ctrlp.vim',
		keys = {"<C-p>"}
	}

	use {
		"scrooloose/nerdcommenter",
		keys = {"<Leader>cc"}
	}

	use {
		'vim-scripts/DoxygenToolkit.vim',
		cmd = {"Dox"},
	}


	use {
		'fatih/vim-go',
		run = ':GoUpdateBinaries'
	}



end)


A overlay.full/.config/nvim/lua/utils.lua => overlay.full/.config/nvim/lua/utils.lua +61 -0
@@ 0,0 1,61 @@
--
-- This file was source dfrom: https://emilienl.medium.com/a-quick-guide-to-configure-neovim-in-lua-7c58a28e624c
--

local M = {} -- The module to export
local cmd = vim.cmd

-- We will create a few autogroup, this function will help to avoid
-- always writing cmd('augroup' .. group) etc..
function M.create_augroup(autocmds, name)
  cmd ('augroup ' .. name)
  cmd('autocmd!')
  for _, autocmd in ipairs(autocmds) do
    cmd('autocmd ' .. table.concat(autocmd, ' '))
  end
  cmd('augroup END')
end

-- Add a apth to the rtp
function M.add_rtp(path)
  local rtp = vim.o.rtp
  rtp = rtp .. ',' .. path
end

-- Map a key with optional options
function M.map(mode, keys, action, options)
  if options == nil then
    options = {}
  end
  vim.api.nvim_set_keymap(mode, keys, action, options)
end

-- Map a key to a lua callback
function M.map_lua(mode, keys, action, options)
  if options == nil then
    options = {}
  end
  vim.api.nvim_set_keymap(mode, keys, "<cmd>lua " .. action .. "<cr>", options)
end

-- Buffer local mappings
function M.map_buf(mode, keys, action, options, buf_nr)
  if options == nil then
    options = {}
  end
  local buf = buf_nr or 0
  vim.api.nvim_buf_set_keymap(buf, mode, keys, action, options)
end

function M.map_lua_buf(mode, keys, action, options, buf_nr)
  if options == nil then
    options = {}
  end
  local buf = buf_nr or 0
  vim.api.nvim_buf_set_keymap(buf, mode, keys, "<cmd>lua " .. action .. "<cr>", options)
end

-- We want to be able to access utils in all our configuration files
-- so we add the module to the _G global variable.
_G.utils = M
return M -- Export the module