2022-11-29 05:22:32 -08:00
|
|
|
;;; init.fnl - primary init file
|
|
|
|
|
2022-12-31 18:18:49 -08:00
|
|
|
(import-macros {: bind! : module-call! : hook!
|
|
|
|
: save-excursion! } :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)
|
2023-02-06 12:23:45 -08:00
|
|
|
; Spell optionis
|
2023-01-26 17:01:22 -08:00
|
|
|
(set vim.opt.spelllang "en_us,cjk")
|
2022-11-29 05:22:32 -08:00
|
|
|
(set vim.opt.spelloptions :camel)
|
|
|
|
; Allow more freedom with the cursor
|
|
|
|
(set vim.opt.virtualedit :block)
|
2023-05-03 15:20:37 -07:00
|
|
|
; Enable modelines with modelineexpr off
|
|
|
|
(set vim.opt.modeline true)
|
|
|
|
(set vim.opt.modelineexpr false)
|
2022-12-10 04:59:31 -08:00
|
|
|
; Auto chdir into files' dirs
|
2022-12-10 06:44:36 -08:00
|
|
|
;(set vim.opt.autochdir true)
|
2023-02-06 12:23:45 -08:00
|
|
|
; Enable substitute 'g' flag by default
|
|
|
|
(set vim.opt.gdefault true)
|
2023-04-14 14:42:38 -07:00
|
|
|
(let [ver (vim.version)]
|
|
|
|
(set vim.opt.exrc (or (> ver.major 0) (>= ver.minor 9))))
|
2022-11-29 05:22:32 -08:00
|
|
|
|
|
|
|
;; Remove trailing whitespace
|
2022-12-02 16:38:31 -08:00
|
|
|
(fn remove-trailing-whitespace []
|
2022-11-29 05:22:32 -08:00
|
|
|
"Remove trailing whitespace from the whole file."
|
2022-12-31 18:18:49 -08:00
|
|
|
(save-excursion!
|
|
|
|
(vim.api.nvim_exec "keepjumps keeppatterns silent! %s/ \\+$//" false)
|
|
|
|
(vim.api.nvim_exec "keepjumps keeppatterns silent! 0;/^\\%(\\n*.\\)\\@!/,$d_" false)))
|
2022-11-29 05:22:32 -08:00
|
|
|
(vim.api.nvim_create_user_command :RemoveTrailingWhitespace
|
2022-12-02 16:38:31 -08:00
|
|
|
remove-trailing-whitespace {})
|
2022-12-09 00:23:02 -08:00
|
|
|
(hook! [ :BufWritePre ] "*" remove-trailing-whitespace)
|
2022-11-29 05:22:32 -08:00
|
|
|
|
|
|
|
;; Spell keybindings
|
|
|
|
(bind! :n :<leader>l (fn []
|
2022-12-10 04:59:31 -08:00
|
|
|
(let [new-spell (not (vim.opt_local.spell:get))]
|
|
|
|
(set vim.opt_local.spell new-spell)
|
|
|
|
(print (if new-spell
|
|
|
|
"Enabled Spellcheck"
|
|
|
|
"Disabled Spellcheck")))))
|
2022-11-29 05:22:32 -08:00
|
|
|
|
2023-05-03 23:04:38 -07:00
|
|
|
;; Enable spell in certain buffers
|
2022-12-10 06:44:36 -08:00
|
|
|
(hook! :FileType [ :text :markdown :tex :bib ]
|
2022-12-02 19:22:59 -08:00
|
|
|
#(if (= (vim.fn.buflisted (vim.api.nvim_get_current_buf)) 1)
|
|
|
|
(set vim.opt_local.spell true)))
|
|
|
|
|
2022-11-29 05:22:32 -08:00
|
|
|
;; 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 }
|
2022-12-06 10:58:47 -08:00
|
|
|
:extension {
|
2022-11-29 23:55:20 -08:00
|
|
|
"nasm" :nasm
|
|
|
|
"h" :c
|
2023-03-03 21:04:33 -08:00
|
|
|
"ui" :xml
|
2023-09-13 03:30:31 -07:00
|
|
|
"tpp" :cpp
|
|
|
|
"m" :objc }})
|
2022-11-29 23:55:20 -08:00
|
|
|
|
2023-05-26 14:50:58 -07:00
|
|
|
;; Fix filetype of terminal buffers
|
|
|
|
(hook! :BufEnter "term:/*" #(set vim.bo.filetype ""))
|
|
|
|
|
2022-11-30 23:34:15 -08:00
|
|
|
(module-call! :packer :startup (require :plugin))
|