init.fnl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ;;; init.fnl - primary init file
  2. (import-macros {: bind! : module-call! : hook!
  3. : save-excursion! } :macros)
  4. ;; Make space leader
  5. (set vim.g.mapleader " ")
  6. (bind! :n :<space> :<nop>)
  7. ;; Make comma localleader
  8. (set vim.g.maplocalleader ",")
  9. ;; Enable lua filetype
  10. (set vim.g.do_filetype_lua true)
  11. ;; Some options
  12. ; Make the mouse work
  13. (set vim.opt.mouse :a)
  14. (set vim.opt.mousemodel :extend)
  15. ; Ignore case when a query is all lower case
  16. (set vim.opt.ignorecase true)
  17. (set vim.opt.smartcase true)
  18. ; Enable line numbering
  19. (set vim.opt.number true)
  20. ; Make <tab> insert 4 spaces
  21. (set vim.opt.expandtab true)
  22. (set vim.opt.tabstop 4)
  23. (set vim.opt.shiftwidth 4)
  24. (set vim.opt.shiftround true)
  25. ; Auto-indent
  26. (set vim.opt.autoindent true)
  27. (set vim.opt.smartindent true)
  28. ; Give context while scrolling
  29. (set vim.opt.scrolloff 4)
  30. (set vim.opt.sidescrolloff 8)
  31. ; Make splitting better
  32. (set vim.opt.splitbelow true)
  33. (set vim.opt.splitright true)
  34. ; 24 bit color support
  35. (set vim.opt.termguicolors true)
  36. ; Shell like completions
  37. (set vim.opt.wildmode [ :list :longest ])
  38. ; Set completion options
  39. (set vim.opt.completeopt [ :menu :menuone :noselect ])
  40. ; Make buffers hide when abandoned
  41. (set vim.opt.hidden true)
  42. ; Save undo data
  43. (set vim.opt.undofile true)
  44. ; Text width
  45. (set vim.opt.textwidth 80)
  46. ; Spell optionis
  47. (set vim.opt.spelllang "en_us,cjk")
  48. (set vim.opt.spelloptions :camel)
  49. ; Allow more freedom with the cursor
  50. (set vim.opt.virtualedit :block)
  51. ; Enable modelines with modelineexpr off
  52. (set vim.opt.modeline true)
  53. (set vim.opt.modelineexpr false)
  54. ; Auto chdir into files' dirs
  55. ;(set vim.opt.autochdir true)
  56. ; Enable substitute 'g' flag by default
  57. (set vim.opt.gdefault true)
  58. (let [ver (vim.version)]
  59. (set vim.opt.exrc (or (> ver.major 0) (>= ver.minor 9))))
  60. ;; Remove trailing whitespace
  61. (fn remove-trailing-whitespace []
  62. "Remove trailing whitespace from the whole file."
  63. (save-excursion!
  64. (vim.api.nvim_exec "keepjumps keeppatterns silent! %s/ \\+$//" false)
  65. (vim.api.nvim_exec "keepjumps keeppatterns silent! 0;/^\\%(\\n*.\\)\\@!/,$d_" false)))
  66. (vim.api.nvim_create_user_command :RemoveTrailingWhitespace
  67. remove-trailing-whitespace {})
  68. (hook! [ :BufWritePre ] "*" remove-trailing-whitespace)
  69. ;; Spell keybindings
  70. (bind! :n :<leader>l (fn []
  71. (let [new-spell (not (vim.opt_local.spell:get))]
  72. (set vim.opt_local.spell new-spell)
  73. (print (if new-spell
  74. "Enabled Spellcheck"
  75. "Disabled Spellcheck")))))
  76. ;; Enable spell in certain buffers
  77. (hook! :FileType [ :text :markdown :tex :bib ]
  78. #(if (= (vim.fn.buflisted (vim.api.nvim_get_current_buf)) 1)
  79. (set vim.opt_local.spell true)))
  80. ;; Some keybindings for diagnostics
  81. (bind! :n :<leader>e vim.diagnostic.open_float)
  82. (bind! :n "[d" vim.diagnostic.goto_prev)
  83. (bind! :n "]d" vim.diagnostic.goto_next)
  84. (bind! :n :<leader>q vim.diagnostic.setloclist)
  85. ;; Some filetype settings
  86. (vim.filetype.add { :filename {
  87. ".latexmkrc" :perl
  88. "Jenkinsfile" :groovy }
  89. :extension {
  90. "nasm" :nasm
  91. "h" :c
  92. "ui" :xml
  93. "tpp" :cpp
  94. "m" :objc }})
  95. ;; Fix filetype of terminal buffers
  96. (hook! :BufEnter "term:/*" #(set vim.bo.filetype ""))
  97. (module-call! :packer :startup (require :plugin))