This repository has been archived on 2024-10-28. You can view files and clone it, but cannot push or open issues or pull requests.
nvim-config/init.fnl

117 lines
3.5 KiB
Fennel

;;; init.fnl - primary init file
(import-macros {: bind! : module-call!} :macros)
;; Make space leader
(set vim.g.mapleader " ")
(bind! :n :<space> :<nop>)
;; 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 <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)
;; Some filetype settings
(vim.filetype.add { :filename {
".latexmkrc" :perl
"Jenkinsfile" :groovy }
:extensions {
"nasm" :nasm
"h" :c
"ui" :xml }})
(module-call! :packer :startup (require :plugin))