2022-11-29 05:22:32 -08:00
|
|
|
;;; init.fnl - primary init file
|
|
|
|
|
2022-11-30 23:34:15 -08:00
|
|
|
(import-macros {: bind! : module-call!} :macros)
|
2022-11-29 05:22:32 -08:00
|
|
|
|
|
|
|
;; Make space leader
|
|
|
|
(set vim.g.mapleader " ")
|
|
|
|
(bind! :n :<space> :<nop>)
|
|
|
|
|
2022-11-30 00:47:55 -08:00
|
|
|
;; Make comma localleader
|
|
|
|
(set vim.g.maplocalleader ",")
|
|
|
|
|
2022-11-29 05:22:32 -08:00
|
|
|
;; Enable lua filetype
|
|
|
|
(set vim.g.do_filetype_lua true)
|
|
|
|
|
|
|
|
;; Some options
|
|
|
|
; Make the mouse work
|
|
|
|
(set vim.opt.mouse :a)
|
|
|
|
(set vim.opt.mousemodel :extend)
|
|
|
|
; Ignore case when a query is all lower case
|
|
|
|
(set vim.opt.ignorecase true)
|
|
|
|
(set vim.opt.smartcase true)
|
|
|
|
; Enable line numbering
|
|
|
|
(set vim.opt.number true)
|
|
|
|
; Make <tab> insert 4 spaces
|
|
|
|
(set vim.opt.expandtab true)
|
|
|
|
(set vim.opt.tabstop 4)
|
|
|
|
(set vim.opt.shiftwidth 4)
|
|
|
|
(set vim.opt.shiftround true)
|
|
|
|
; Auto-indent
|
|
|
|
(set vim.opt.autoindent true)
|
|
|
|
(set vim.opt.smartindent true)
|
|
|
|
; Give context while scrolling
|
|
|
|
(set vim.opt.scrolloff 4)
|
|
|
|
(set vim.opt.sidescrolloff 8)
|
|
|
|
; Make splitting better
|
|
|
|
(set vim.opt.splitbelow true)
|
|
|
|
(set vim.opt.splitright true)
|
|
|
|
; 24 bit color support
|
|
|
|
(set vim.opt.termguicolors true)
|
|
|
|
; Shell like completions
|
|
|
|
(set vim.opt.wildmode [ :list :longest ])
|
|
|
|
; Set completion options
|
|
|
|
(set vim.opt.completeopt [ :menu :menuone :noselect ])
|
|
|
|
; Make buffers hide when abandoned
|
|
|
|
(set vim.opt.hidden true)
|
|
|
|
; Save undo data
|
|
|
|
(set vim.opt.undofile true)
|
|
|
|
; Text width
|
|
|
|
(set vim.opt.textwidth 80)
|
|
|
|
; Spell options
|
|
|
|
(set vim.opt.spelllang :en_us)
|
|
|
|
(set vim.opt.spelloptions :camel)
|
|
|
|
; Allow more freedom with the cursor
|
|
|
|
(set vim.opt.virtualedit :block)
|
|
|
|
|
|
|
|
;; Disable netrw
|
|
|
|
(set vim.g.loaded_netrw 1)
|
|
|
|
(set vim.g.loaded_netrwPlugin 1)
|
|
|
|
|
|
|
|
;; Remove trailing whitespace
|
|
|
|
(fn remove_trailing_whitespace []
|
|
|
|
"Remove trailing whitespace from the whole file."
|
|
|
|
(let [res (pcall vim.cmd "%s/ \\+$//gc")]
|
|
|
|
(vim.cmd.nohlsearch)
|
|
|
|
(when (not res)
|
|
|
|
(print "File is clean"))))
|
|
|
|
(vim.api.nvim_create_user_command :RemoveTrailingWhitespace
|
|
|
|
remove_trailing_whitespace {})
|
|
|
|
(bind! :n :<leader>ws remove_trailing_whitespace)
|
|
|
|
|
|
|
|
;; Spell keybindings
|
|
|
|
(bind! :n :<leader>l (fn []
|
|
|
|
(let [new_spell (not (vim.opt_local.spell:get))]
|
|
|
|
(set vim.opt_local.spell new_spell)
|
|
|
|
(print (if new_spell
|
|
|
|
"Enabled Spellcheck"
|
|
|
|
"Disabled Spellcheck")))))
|
|
|
|
|
|
|
|
(fn jump_or_open_terminal []
|
|
|
|
"If no terminal buffer exists, create one. Otherwise, open new one."
|
|
|
|
(var term_count 0)
|
|
|
|
(var last_id 0)
|
|
|
|
(var terms [ ])
|
|
|
|
(each [_ id (pairs (vim.api.nvim_list_bufs))]
|
|
|
|
(let [name (vim.api.nvim_buf_get_name id)]
|
|
|
|
(when (vim.startswith name "term://")
|
|
|
|
(table.insert terms name)
|
|
|
|
(set term_count (+ term_count 1))
|
|
|
|
(set last_id id))))
|
|
|
|
(if (= term_count 0)
|
|
|
|
(vim.cmd.terminal)
|
|
|
|
(= term_count 1)
|
|
|
|
(vim.cmd.buffer last_id)
|
|
|
|
(vim.ui.select terms
|
|
|
|
{ :prompt "Terminal Buffers" }
|
|
|
|
(fn [choice]
|
|
|
|
(when choice
|
|
|
|
(vim.cmd.buffer choice))))))
|
|
|
|
(bind! :n :<leader>t jump_or_open_terminal)
|
|
|
|
|
|
|
|
;; Some keybindings for diagnostics
|
|
|
|
(bind! :n :<leader>e vim.diagnostic.open_float)
|
|
|
|
(bind! :n "[d" vim.diagnostic.goto_prev)
|
|
|
|
(bind! :n "]d" vim.diagnostic.goto_next)
|
|
|
|
(bind! :n :<leader>q vim.diagnostic.setloclist)
|
|
|
|
|
2022-11-29 23:55:20 -08:00
|
|
|
;; Some filetype settings
|
|
|
|
(vim.filetype.add { :filename {
|
|
|
|
".latexmkrc" :perl
|
|
|
|
"Jenkinsfile" :groovy }
|
|
|
|
:extensions {
|
|
|
|
"nasm" :nasm
|
|
|
|
"h" :c
|
|
|
|
"ui" :xml }})
|
|
|
|
|
2022-11-30 23:34:15 -08:00
|
|
|
(module-call! :packer :startup (require :plugin))
|