From 8d8cf86821d7cc1b093d149389baf5272e8033ca Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Fri, 13 Jan 2023 01:35:12 +0100 Subject: Refactor settings and plugins --- fnl/settings/autocmds.fnl | 79 ++++++++++----------- fnl/settings/keymaps.fnl | 94 ++++++++++++------------- fnl/settings/options.fnl | 162 ++++++++++++++++++++++--------------------- fnl/settings/usercmds.fnl | 172 ++++++++++++++++++++++------------------------ 4 files changed, 248 insertions(+), 259 deletions(-) (limited to 'fnl/settings') diff --git a/fnl/settings/autocmds.fnl b/fnl/settings/autocmds.fnl index 5ae8b8c..ca361b3 100644 --- a/fnl/settings/autocmds.fnl +++ b/fnl/settings/autocmds.fnl @@ -3,46 +3,39 @@ (fn create-autocmd [event opts] (vim.api.nvim_create_autocmd event opts)) -(create-autocmd :FileType - {:pattern [:qf :help :man :lspinfo :spectre_panel] - :command "nnoremap q :close"}) - -(create-autocmd :TextYankPost - {:callback (lambda [] - (vim.highlight.on_yank {:higroup :Visual - :timeout 200}))}) - -(create-autocmd :FileType {:pattern :lir - :callback (fn [] - (tset vim.opt_local :number false) - (tset vim.opt_local :relativenumber - false))}) - -(create-autocmd :BufWinEnter {:command "setlocal formatoptions-=cro"}) - -(create-autocmd :FileType {:pattern :qf :command "set nobuflisted"}) - -(create-autocmd :FileType {:pattern [:gitcommit :markdown] - :command "setlocal wrap"}) - -(create-autocmd :FileType - {:pattern [:NeogitStatus - :NeogitCommitMessage - :NeogitNotification - :NeogitCommitView] - :command "setlocal spell!"}) - -(create-autocmd :TermOpen - {:pattern ["term://*toggleterm#*"] :command "setlocal spell!"}) - -(create-autocmd :VimResized {:command "tabdo wincmd ="}) - -(create-autocmd :FocusGained {:command :checktime}) - -(create-autocmd :TermOpen - {:pattern "term://*toggleterm#*" - :callback (fn [] - (vim.keymap.set :t : "wincmd h" {}) - (vim.keymap.set :t : "wincmd j" {}) - (vim.keymap.set :t : "wincmd k" {}) - (vim.keymap.set :t : "wincmd l" {}))}) +(local autocmds + [[:FileType + {:pattern [:qf :help :man :lspinfo :spectre_panel] + :command "nnoremap q :close"}] + [:TextYankPost + {:callback (lambda [] + (vim.highlight.on_yank {:higroup :Visual :timeout 200}))}] + [:FileType + {:pattern :lir + :callback (fn [] + (tset vim.opt_local :number false) + (tset vim.opt_local :relativenumber false))}] + [:BufWinEnter {:command "setlocal formatoptions-=cro"}] + [:FileType {:pattern :qf :command "set nobuflisted"}] + [:FileType {:pattern [:gitcommit :markdown] :command "setlocal wrap"}] + [:FileType + {:pattern [:NeogitStatus + :NeogitCommitMessage + :NeogitNotification + :NeogitCommitView] + :command "setlocal spell!"}] + [:TermOpen + {:pattern ["term://*toggleterm#*"] :command "setlocal spell!"}] + [:VimResized {:command "tabdo wincmd ="}] + [:FocusGained {:command :checktime}] + [:TermOpen + {:pattern "term://*toggleterm#*" + :callback (fn [] + (vim.keymap.set :t : "wincmd h" {}) + (vim.keymap.set :t : "wincmd j" {}) + (vim.keymap.set :t : "wincmd k" {}) + (vim.keymap.set :t : "wincmd l" {}))}]]) + +(each [_ autocmd (ipairs autocmds)] + (match autocmd + [event opts] (create-autocmd event opts))) diff --git a/fnl/settings/keymaps.fnl b/fnl/settings/keymaps.fnl index 1af9a0d..b59f68f 100644 --- a/fnl/settings/keymaps.fnl +++ b/fnl/settings/keymaps.fnl @@ -1,51 +1,51 @@ ;; Custom keymappings. -(local opts {:noremap true :silent true}) -(fn map [mode lhs rhs opt] (vim.api.nvim_set_keymap mode lhs rhs opt)) - -;;Remap space as leader key -(map "" : : opts) - -;; Normal ;; -;; Better window navigation -(map :n : :h opts) -(map :n : :j opts) -(map :n : :k opts) -(map :n : :l opts) - -;; Resize with arrows -(map :n : ":resize -2" opts) -(map :n : ":resize +2" opts) -(map :n : ":vertical resize -2" opts) -(map :n : ":vertical resize +2" opts) - -;; Visual ;; -;; Stay in indent mode -(map :v "<" :" :>gv opts) - -;; Visual Block ;; -;; Move text up and down -(map :x :J ":move '>+1gv-gv" opts) -(map :x :K ":move '<-2gv-gv" opts) +(fn map [mode lhs rhs opt] + (vim.api.nvim_set_keymap mode lhs rhs opt)) -;; Move text up and down -(map :v : ":m .+1==" opts) -(map :v : ":m .-2==" opts) -(map :v :p "\"_dP" opts) - -;; Splits -(map :n : :split opts) -(map :n : :vsplit opts) - -;; Nav -(map :n : :bprev opts) -(map :n : :bnext opts) - -(map :n : :zz opts) -(map :n : :zz opts) - -(map :n : :nohlsearch opts) +(local opts {:noremap true :silent true}) -(map :n :Q ":q" opts) -(map :n :mj ":e" opts) +(local mappings [;;Remap space as leader key + ["" : :] + ;; Normal ;; + ;; Better window navigation + [:n : :h] + [:n : :j] + [:n : :k] + [:n : :l] + ;; Resize with arrows + [:n : ":resize -2"] + [:n : ":resize +2"] + [:n : ":vertical resize -2"] + [:n : ":vertical resize +2"] + ;; Visual ;; + ;; Stay in indent mode + [:v "<" :" :>gv] + ;; Visual Block ;; + ;; Move text up and down + [:x :J ":move '>+1gv-gv"] + [:x :K ":move '<-2gv-gv"] + ;; Move text up and down + [:v : ":m .+1=="] + [:v : ":m .-2=="] + [:v :p "\"_dP"] + ;; Splits + [:n : :split] + [:n : :vsplit] + ;; Buf navigation + [:n : :bprev] + [:n : :bnext] + ;; Jump half a page and centralize the view + [:n : :zz] + [:n : :zz] + ;; Remove highlighted search + [:n : :nohlsearch] + ;; Close window + [:n :Q ":q"] + ;; Force refresh + [:n :mj ":e"]]) + +(each [_ mapping (ipairs mappings)] + (match mapping + [mode key cmd] (map mode key cmd opts))) diff --git a/fnl/settings/options.fnl b/fnl/settings/options.fnl index 303185a..cb86307 100644 --- a/fnl/settings/options.fnl +++ b/fnl/settings/options.fnl @@ -1,88 +1,92 @@ ;; Sets options in neovim -(fn apply-opts [opts] (each [k v (pairs opts)] - (tset vim.opt k v))) +(fn apply-opts [opts] + (each [k v (pairs opts)] + (tset vim.opt k v))) (local spellfile (.. (os.getenv :XDG_CONFIG_HOME) :/nvim/spell/en.utf-8.add)) (local opts {;; creates a backup file - :backup false - ;; allows neovim to access the system clipboard - :clipboard :unnamedplus - ;; more space in the neovim command line for displaying messages - :cmdheight 1 - ;; mostly just for cmp - :completeopt {:menuone :noselect} - ;; so that `` is visible in markdown files - :conceallevel 0 - ;; the encoding written to a file - :fileencoding :utf-8 - ;; highlight all matches on previous search pattern - :hlsearch true - ;; ignore case in search patterns - :ignorecase true - ;; disable the mouse to be used in neovim - :mouse "" - ;; pop up menu height - :pumheight 10 - ;; we don't need to see things like ;; INSERT ;; anymore - :showmode false - ;; never show tabs - :showtabline 0 - ;; smart case - :smartcase true - ;; make indenting smarter again - :smartindent true - ;; force all horizontal splits to go below current window - :splitbelow true - ;; force all vertical splits to go to the right of current window - :splitright true - ;; creates a swapfile - :swapfile false - ;; set term gui colors (most terminals support this) - :termguicolors true - ;; time to wait for a mapped sequence to complete (in milliseconds) - :timeoutlen 1000 - ;; enable persistent undo - :undofile true - ;; faster completion (4000ms default) - :updatetime 100 - ;; if a file is being edited by another program (or was written - ;; to file while editing with another program), it is not allowed - ;; to be edited - :writebackup false - ;; convert tabs to spaces - :expandtab true - ;; the number of spaces inserted for each indentation - :shiftwidth 2 - ;; insert 2 spaces for a tab - :tabstop 2 - ;; highlight the current line - :cursorline true - ;; set numbered lines - :number true - ;; set relative numbered lines - :relativenumber true - ;; set number column width to 2 {default 4} - :numberwidth 2 - ;; always show the sign column, otherwise it would shift the text - ;; each time - :signcolumn :yes - ;; display lines as one long line - :wrap false - :laststatus 3 - :autoread true - ;; is one of my fav - :scrolloff 8 - :sidescrolloff 8 - :colorcolumn :88 - :shortmess :filnxtToOFWIcC - :spell true - : spellfile - :spelllang [:en_us] - ;; the font used in graphical neovim applications - :guifont "monospace:h17" - :splitkeep :screen}) + :backup false + ;; allows neovim to access the system clipboard + :clipboard :unnamedplus + ;; more space in the neovim command line for displaying messages + :cmdheight 1 + ;; mostly just for cmp + :completeopt {:menuone :noselect} + ;; so that `` is visible in markdown files + :conceallevel 0 + ;; the encoding written to a file + :fileencoding :utf-8 + ;; highlight all matches on previous search pattern + :hlsearch true + ;; ignore case in search patterns + :ignorecase true + ;; disable the mouse to be used in neovim + :mouse "" + ;; pop up menu height + :pumheight 10 + ;; we don't need to see things like ;; INSERT ;; anymore + :showmode false + ;; never show tabs + :showtabline 0 + ;; smart case + :smartcase true + ;; make indenting smarter again + :smartindent true + ;; force all horizontal splits to go below current window + :splitbelow true + ;; force all vertical splits to go to the right of current window + :splitright true + ;; creates a swapfile + :swapfile false + ;; set term gui colors (most terminals support this) + :termguicolors true + ;; time to wait for a mapped sequence to complete (in milliseconds) + :timeoutlen 1000 + ;; enable persistent undo + :undofile true + ;; faster completion (4000ms default) + :updatetime 100 + ;; if a file is being edited by another program (or was written + ;; to file while editing with another program), it is not allowed + ;; to be edited + :writebackup false + ;; convert tabs to spaces + :expandtab true + ;; the number of spaces inserted for each indentation + :shiftwidth 2 + ;; insert 2 spaces for a tab + :tabstop 2 + ;; highlight the current line + :cursorline true + ;; set numbered lines + :number true + ;; set relative numbered lines + :relativenumber true + ;; set number column width to 2 {default 4} + :numberwidth 2 + ;; always show the sign column, otherwise it would shift the text + ;; each time + :signcolumn :yes + ;; display lines as one long line + :wrap false + :laststatus 3 + :autoread true + ;; is one of my fav + :scrolloff 8 + :sidescrolloff 8 + :colorcolumn :88 + :shortmess :filnxtToOFWIcC + :spell true + : spellfile + :spelllang [:en_us] + ;; the font used in graphical neovim applications + :guifont "monospace:h17" + :splitkeep :screen}) + +;; Move to new line when reaching the beginning or end. +(vim.opt.whichwrap:append "<,>,[,],h,l") (apply-opts opts) (set vim.g.mapleader " ") diff --git a/fnl/settings/usercmds.fnl b/fnl/settings/usercmds.fnl index da842cc..14020af 100644 --- a/fnl/settings/usercmds.fnl +++ b/fnl/settings/usercmds.fnl @@ -1,98 +1,90 @@ ;; Commands for plugins. -(vim.api.nvim_create_user_command :OrgAgendaPrompt - (lambda [] - (let [orgmode (require :orgmode)] - (orgmode.action :agenda.prompt))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :OrgCapturePrompt - (lambda [] - (let [orgmode (require :orgmode)] - (orgmode.action :capture.prompt))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :CommentNormal - (lambda [] - (let [comment-api (require :Comment.api)] - (comment-api.toggle.linewise.current))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :CommentVisual - (lambda [] - (let [comment-api (require :Comment.api)] - (comment-api.toggle.linewise (vim.fn.visualmode)))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :HarpoonAdd - (lambda [] - (let [harpoon (require :harpoon.mark)] - (harpoon.add_file))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :HarpoonNext - (lambda [] - (let [harpoon (require :harpoon.ui)] - (harpoon.nav_next))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :HarpoonPrev - (lambda [] - (let [harpoon (require :harpoon.ui)] - (harpoon.nav_prev))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :HarpoonUI - (lambda [] - (let [harpoon (require :harpoon.ui)] - (harpoon.toggle_quick_menu))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :Replace - (lambda [] - (let [spectre (require :spectre)] - (spectre.open))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :ReplaceWord - (lambda [] - (let [spectre (require :spectre)] - (spectre.open_visual {:select_word true}))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :ReplaceInBuf - (lambda [] - (let [spectre (require :spectre)] - (spectre.open_file_search))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :RestoreSession - (lambda [] - (let [persistence (require :persistence)] - (persistence.load))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :RestoreLastSession - (lambda [] - (let [persistence (require :persistence)] - (persistence.load {:last true}))) - {:nargs 0}) - -(vim.api.nvim_create_user_command :IgnoreSession - (lambda [] - (let [persistence (require :persistence)] - (persistence.stop))) - {:nargs 0}) - (fn telescope-builtin [builtin opts] (let [telescope (require :telescope.builtin) themes (require :telescope.themes) theme (. opts :theme)] ((. telescope builtin) ((. themes theme) opts)))) -(vim.api.nvim_create_user_command :FindFiles - (lambda [] - (telescope-builtin :find_files - {:theme :get_dropdown - :previewer false})) - {:nargs 0}) +(fn create-usercmd [event cmd opts] + (vim.api.nvim_create_user_command event cmd opts)) + +(local usercmds [[:OrgAgendaPrompt + (lambda [] + (let [orgmode (require :orgmode)] + (orgmode.action :agenda.prompt))) + {:nargs 0}] + [:OrgCapturePrompt + (lambda [] + (let [orgmode (require :orgmode)] + (orgmode.action :capture.prompt))) + {:nargs 0}] + [:CommentNormal + (lambda [] + (let [comment-api (require :Comment.api)] + (comment-api.toggle.linewise.current))) + {:nargs 0}] + [:CommentVisual + (lambda [] + (let [comment-api (require :Comment.api)] + (comment-api.toggle.linewise (vim.fn.visualmode)))) + {:nargs 0}] + [:HarpoonAdd + (lambda [] + (let [harpoon (require :harpoon.mark)] + (harpoon.add_file))) + {:nargs 0}] + [:HarpoonNext + (lambda [] + (let [harpoon (require :harpoon.ui)] + (harpoon.nav_next))) + {:nargs 0}] + [:HarpoonPrev + (lambda [] + (let [harpoon (require :harpoon.ui)] + (harpoon.nav_prev))) + {:nargs 0}] + [:HarpoonUI + (lambda [] + (let [harpoon (require :harpoon.ui)] + (harpoon.toggle_quick_menu))) + {:nargs 0}] + [:Replace + (lambda [] + (let [spectre (require :spectre)] + (spectre.open))) + {:nargs 0}] + [:ReplaceWord + (lambda [] + (let [spectre (require :spectre)] + (spectre.open_visual {:select_word true}))) + {:nargs 0}] + [:ReplaceInBuf + (lambda [] + (let [spectre (require :spectre)] + (spectre.open_file_search))) + {:nargs 0}] + [:RestoreSession + (lambda [] + (let [persistence (require :persistence)] + (persistence.load))) + {:nargs 0}] + [:RestoreLastSession + (lambda [] + (let [persistence (require :persistence)] + (persistence.load {:last true}))) + {:nargs 0}] + [:IgnoreSession + (lambda [] + (let [persistence (require :persistence)] + (persistence.stop))) + {:nargs 0}] + [:FindFiles + (lambda [] + (telescope-builtin :find_files + {:theme :get_dropdown :previewer false})) + {:nargs 0}]]) + +(each [_ usercmd (ipairs usercmds)] + (match usercmd + [event cmd opts] (create-usercmd event cmd opts))) -- cgit v1.2.3-70-g09d2