;;; init.fnl - primary init file (import-macros {: bind! : module-call! : hook! : save-excursion! } :macros) ;; Make space leader (set vim.g.mapleader " ") (bind! :n : :) ;; Make comma localleader (set vim.g.maplocalleader ",") ;; 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 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 optionis (set vim.opt.spelllang "en_us,cjk") (set vim.opt.spelloptions :camel) ; Allow more freedom with the cursor (set vim.opt.virtualedit :block) ; Enable modelines with modelineexpr off (set vim.opt.modeline true) (set vim.opt.modelineexpr false) ; Auto chdir into files' dirs ;(set vim.opt.autochdir true) ; Enable substitute 'g' flag by default (set vim.opt.gdefault true) (let [ver (vim.version)] (set vim.opt.exrc (or (> ver.major 0) (>= ver.minor 9)))) ;; Remove trailing whitespace (fn remove-trailing-whitespace [] "Remove trailing whitespace from the whole file." (save-excursion! (vim.api.nvim_exec "keepjumps keeppatterns silent! %s/ \\+$//" false) (vim.api.nvim_exec "keepjumps keeppatterns silent! 0;/^\\%(\\n*.\\)\\@!/,$d_" false))) (vim.api.nvim_create_user_command :RemoveTrailingWhitespace remove-trailing-whitespace {}) (hook! [ :BufWritePre ] "*" remove-trailing-whitespace) ;; Spell keybindings (bind! :n :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"))))) ;; Enable spell in certain buffers (hook! :FileType [ :text :markdown :tex :bib ] #(if (= (vim.fn.buflisted (vim.api.nvim_get_current_buf)) 1) (set vim.opt_local.spell true))) ;; Some keybindings for diagnostics (bind! :n :e vim.diagnostic.open_float) (bind! :n "[d" vim.diagnostic.goto_prev) (bind! :n "]d" vim.diagnostic.goto_next) (bind! :n :q vim.diagnostic.setloclist) ;; Some filetype settings (vim.filetype.add { :filename { ".latexmkrc" :perl "Jenkinsfile" :groovy } :extension { "nasm" :nasm "h" :c "ui" :xml "tpp" :cpp "m" :objc }}) ;; Fix filetype of terminal buffers (hook! :BufEnter "term:/*" #(set vim.bo.filetype "")) (module-call! :packer :startup (require :plugin))