this repo has no description
at master 10 kB view raw
1(import-macros {: use : reuse} :relude) 2 3(use nvim {: map : fun : api : opt : cmd}) 4 5(reuse plugins) 6 7(use picker) 8(import-macros {: augroup : defcommand} :nvim) 9 10(set opt.shell :fish) 11 12(do ; MatchIt must be unloaded for MatchPair to work correctly 13 (set vim.g.loaded_matchit true) 14 (set vim.g.matchup_surround_enabled true)) 15 16(do ; Colors 17 (cmd.colorscheme :blame) 18 (opt {:termguicolors true 19 :guicursor ["n-v-c-sm:block-Cursor" 20 "i-ci-ve:ver25-Cursor" 21 "r-cr-o:hor20-Cursor"]})) 22 23(do ; Indentation 24 (opt {:shiftwidth 2 25 :expandtab true 26 :textwidth 80 27 :wrap false 28 :linebreak true 29 :formatoptions :tcqjl})) 30 31(do ; UI 32 (opt {:updatetime 500 33 :title true 34 :showmode true 35 :signcolumn "yes:1"})) 36 37(do ; Display tabs and trailing spaces visually 38 (opt {:fillchars ["vert:┃" "fold:·"] 39 :list true 40 :listchars ["tab:→ " 41 "trail:·" 42 "nbsp:␣" 43 "extends:↦" 44 "precedes:↤"] 45 :conceallevel 2 46 :concealcursor :nc})) 47 48(do ; Ignore case. 49 ; If your code uses different casing to differentiate files, then you need 50 ; mental help 51 (opt {:wildignorecase true 52 :wildmode :full 53 :fileignorecase true 54 :wildignore [:*.o 55 "*~" 56 :**/.git/** 57 :**/node_modules/** 58 :**/_build/** 59 :**/deps/** 60 :**/target/** 61 :**/uploads/** 62 :*.lock]})) 63 64(opt {:diffopt+ [:indent-heuristic "algorithm:patience"] 65 :iskeyword+ ["-"]}) 66 67(do ; Autowrite file whenever possible 68 (opt {:hidden false :autowriteall true})) 69 70(do 71 (set opt.mousescroll ["ver:3" "hor:0"]) 72 ; Keep cursor in the middle 73 (let [value 9999 74 enter (fn [] 75 (set opt.window.signcolumn :no) 76 (set opt.window.scrolloff 0)) 77 leave (fn [] 78 (set opt.window.signcolumn "yes:1") 79 (set opt.window.scrolloff value))] 80 (set opt.scrolloff value) 81 (augroup terminal-scrolloff 82 (on TermOpen "*" (enter)) 83 (on BufEnter "term://*" (enter)) 84 (on BufLeave "term://*" (leave))))) 85 86(do ; XXI century - we have cursors now 87 (set opt.mouse :a)) 88 89(do 90 (set opt.title true) 91 (augroup window-title 92 (on BufEnter "*" 93 (let [cwd (fun.getcwd) 94 project (fun.fnamemodify cwd ":p:~:h")] 95 (set opt.titlestring (.. "nvim " project)))))) 96 97(do ; Split in CORRECT places 98 (opt {:splitright true :splitbelow true})) 99 100(do ; Searching 101 (opt {:ignorecase true :smartcase true :inccommand :nosplit})) 102 103(do ; Permanent undo 104 (set opt.undofile true)) 105 106(do ; Save only meaningful data to sessions 107 (set opt.sessionoptions [:blank 108 :buffers 109 :curdir 110 :folds 111 :tabpages 112 :winsize 113 :terminal])) 114 115(do ; Folding 116 (opt {:foldmethod :expr 117 :foldexpr "nvim_treesitter#foldexpr()" 118 :foldlevel 999}) 119 (map :n :<CR> "foldlevel(\".\") ? \"za\" : \"\\<CR>\"" {:expr true})) 120 121(do ; Completion 122 (opt {:complete ["." :w :b :t :k :kspell] 123 :completeopt [:menuone :noselect :noinsert]})) 124 125(do ; Clap 126 (map :n :<Space><Space> #(picker.find-files))) 127 128(do ; Additional "Close" commands 129 (map :n :ZS ":wa") 130 (map :n :ZA ":qa") 131 (map :n :ZX ":cq")) 132 133(do ; Swap ; and : for easier command line mode 134 (let [swap (fn [a b] 135 (map :nx a b) 136 (map :nx b a))] 137 (swap ";" ":") 138 (map :n "q;" "q:"))) 139 140(do ; Expand abbreviation when hit <CR> 141 (map :i :<CR> "<C-]><CR>")) 142 143(do ; Make Vim behaviour consistent 144 (map :n :Y :y$)) 145 146(do ; Code formatting 147 (map :n :g= "=aGg``") 148 (map :nx :Q :gq) 149 (map :n :gQ "gqaG``")) 150 151(do ; Smart `0` 152 ; Goes to the beginning of the text at first and later goes to the beginning of 153 ; the line, alternates afterwards 154 (map :n :0 "virtcol('.') - 1 <= indent('.') && col('.') > 1 ? '0' : '_'" 155 {:expr true})) 156 157(do ; Help viewing and opening URLs 158 (defcommand Dash {:nargs "?"} (fun.dash#open (tostring args))) 159 (map :n :gK ":Dash") 160 (map :n :gq #(let [name (fun.expand :<cfile>)] 161 (fun.jobstart [:open name] {:detach true}) 162 (print :Open name)))) 163 164(do ; Text object for whole file 165 (map :o :aG ":normal! ggVG")) 166 167(do ; Quickly disable highlight 168 (map :n "<Space>," ":nohlsearch")) 169 170(do ; Frequently used unimpaired mappings 171 (let [unimpaired (fn [char left right] 172 (map :n (.. "[" char) left) 173 (map :n (.. "]" char) right))] 174 (unimpaired :w :gT :gt))) 175 176(do ; Terminal mappings 177 ; (map :n :<C-q>c ":term") 178 (map :n :<C-q>s ":Start") 179 (map :n :<C-q>v ":vert Start") 180 (map :n :<C-q>t ":tab Start") 181 (map :t :<C-q> "<C-\\><C-n>") 182 (map :n :<C-q> :<ESC>) 183 (map :n :<C-q>q :<ESC>) 184 (map :n :<C-q><C-q> :<ESC>) 185 (map :i :<C-q><C-q> :<ESC>)) 186 ; (when (fun.executable :nvr) 187 ; (set vim.env.EDITOR "nvr -cc split -c 'set bufhidden=delete' --remote-wait"))) 188 189(do ; Git mappings 190 (let [leader :U 191 git-map (fn [lhs cmd] 192 (map :n (.. leader lhs) (.. ":Git " cmd)))] 193 (map :n leader :<nop>) 194 (map :n (.. leader leader) (.. leader :u) {:noremap false}) 195 (git-map :p :push) 196 (git-map :s "") 197 (git-map :d :diff) 198 (git-map :B :blame) 199 (git-map :c :commit) 200 (git-map :u :pull) 201 (git-map :g :log))) 202 203; (do ; Split management 204; (set vim.g.choosewin_label :QWERTASDF) 205; (map :n :<C-w><C-w> "<plug>(choosewin)") 206; (map :n :<C-_> "<plug>(choosewin)")) 207 208(do ; Search 209 (when (fun.executable :rg) 210 (opt {:grepprg "rg --vimgrep --no-heading --smart-case" 211 :grepformat "%f:%l:%c:%m,%f:%l%m,%f %l%m"}))) 212 213(do ; Matchparen 214 (set vim.g.matchup_matchparen_offscreen {:method :popup}) 215 (augroup matchparen-term 216 (let [term "term://*"] 217 (on BufEnter term (cmd.NoMatchParen)) 218 (on BufLeave term (cmd.DoMatchParen))))) 219 220(do ; Autoreload Direnv after writing the .envrc 221 (when (fun.executable :direnv) 222 (augroup autoreload-envrc 223 (on BufWritePost :.envrc 224 (fun.system ["direnv" "allow" (fun.expand "%")]) 225 (cmd.DirenvExport))))) 226 227(do ; Setup Lua extensions 228 (let [setup (fn [package config] 229 (let [lib (require package) 230 f (. lib :setup) 231 opts (match (type config) 232 :nil {} 233 :function (config lib) 234 :table config)] 235 (f opts) 236 lib))] 237 (setup :mini.ai) 238 (setup :mini.align 239 {:mappings {:start :gl 240 :start_with_preview :gL}}) 241 ;(setup :mini.bracketed) 242 (setup :mini.bufremove 243 (fn [bufremove] 244 (defcommand Bd (bufremove.delete)) 245 (defcommand BClean 246 (->> (fun.getbufinfo {:buflisted true}) 247 (vim.tbl_filter #(= (next $1.windows) nil)) 248 (#(each [_ v (ipairs $1)] 249 (bufremove.delete v.bufnr))))) 250 {:set_vim_settings false})) 251 (setup :mini.jump {:mappings {:repeat_jump ":"}}) 252 (setup :mini.operators { 253 :multiply {:prefix ""} 254 :replace {:prefix ""} 255 :sort {:prefix ""}}) 256 (setup :mini.sessions 257 (fn [sessions] 258 (let [complete (fn [with-current?] 259 #(icollect [_ spec (pairs sessions.detected)] 260 (when (not (and with-current? 261 (= spec.path vim.v.this_session))) 262 spec.name)))] 263 (defcommand SSave {:nargs "?" :bang true} 264 (print (sessions.write args {:force bang}))) 265 (defcommand SDelete {:nargs "?" :bang true :complete (complete true)} 266 (print (sessions.delete args {:force bang}))) 267 (defcommand SRead {:nargs 1 :bang true :complete (complete false)} 268 (print (sessions.read (tostring args) {:force bang})))) 269 {:directory (.. (fun.stdpath :data) "/site/sessions/")})) 270 (setup :mini.starter 271 (fn [starter] 272 {:items [(starter.sections.sessions 10 true) 273 (starter.sections.builtin_actions)]})) 274 (setup :mini.surround 275 {:mappings {:add :gsa 276 :delete :gsd 277 :find :gsf 278 :find_left :gsF 279 :highlight "" 280 :replace :gss 281 :update_n_lines ""}}) 282 (setup :nvim-treesitter.configs 283 {:highlight {:enable true 284 ; Currently disable as it do not work as expected 285 :disable [:erlang :make :diff]} 286 :matchup {:enable true} 287 :indent {:enable true} 288 :incremental_selection {:enable true}}) 289 (setup :neorg 290 {:load {:core.defaults {} 291 :core.concealer {}}}) 292 )) 293 294(defcommand Clean "keeppatterns %s/\\s\\+$//e | set nohlsearch") 295 296(do ; Async Make and Grep 297 (let [run (fn [args f-args] 298 (api.call-function "asyncdo#run" (vim.list_extend args f-args)))] 299 (defcommand Make {:bang true :nargs "*" :complete :file} 300 (run [bang opt.makeprg] args)) 301 (defcommand Grep {:bang true :nargs "+" :complete :dir} 302 (run [bang {:job opt.grepprg :errorformat opt.grepformat}] 303 args)))) 304 305(defcommand Ctags (cmd.AsyncDo "ctags -R .")) 306 307(defcommand Start {:nargs "*"} 308 (let [args (if (= (length args) 0) (fun.split opt.shell) args) 309 command (icollect [_ v (pairs args)] (fun.expand v))] 310 (cmd.new {:mods mods}) 311 (fun.termopen command) 312 (cmd.startinsert))) 313 314(do ; TreeSJ 315 (map :n :gS #(let [lib (require "treesj") 316 toggle (. lib :toggle)] 317 (toggle)))) 318 319(require :langclient)