From 0e07c01180b6abd84881b67e41e5f611d49e06db Mon Sep 17 00:00:00 2001 From: 0scar Date: Wed, 21 Jun 2023 12:12:45 +0200 Subject: Add neovim configuration --- .config/nvim/ftplugin/haskell.lua | 42 +++++++++++++++ .config/nvim/ftplugin/markdown.vim | 10 ++++ .config/nvim/ftplugin/tex.vim | 108 +++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 .config/nvim/ftplugin/haskell.lua create mode 100644 .config/nvim/ftplugin/markdown.vim create mode 100644 .config/nvim/ftplugin/tex.vim (limited to '.config/nvim/ftplugin') diff --git a/.config/nvim/ftplugin/haskell.lua b/.config/nvim/ftplugin/haskell.lua new file mode 100644 index 0000000..6d06780 --- /dev/null +++ b/.config/nvim/ftplugin/haskell.lua @@ -0,0 +1,42 @@ +vim.g.haskell_enable_quantification = 1 -- to enable highlighting of `forall` +vim.g.haskell_enable_recursivedo = 1 -- to enable highlighting of `mdo` and `rec` +vim.g.haskell_enable_arrowsyntax = 1 -- to enable highlighting of `proc` +vim.g.haskell_enable_pattern_synonyms = 1 -- to enable highlighting of `pattern` +vim.g.haskell_enable_typeroles = 1 -- to enable highlighting of type roles +vim.g.haskell_enable_static_pointers = 1 -- to enable highlighting of `static` +vim.g.haskell_backpack = 1 -- to enable highlighting of backpack keywords + +local ht = require('haskell-tools') +local def_opts = { noremap = true, silent = true, } +ht.start_or_attach { + hls = { + on_attach = function(client, bufnr) + local opts = vim.tbl_extend('keep', def_opts, { buffer = bufnr, }) + -- haskell-language-server relies heavily on codeLenses, + -- so auto-refresh (see advanced configuration) is enabled by default + vim.keymap.set('n', 'ca', vim.lsp.codelens.run, opts) + vim.keymap.set('n', 'hs', ht.hoogle.hoogle_signature, opts) + vim.keymap.set('n', 'ea', ht.lsp.buf_eval_all, opts) + end, + }, +} + +-- Suggested keymaps that do not depend on haskell-language-server: +local bufnr = vim.api.nvim_get_current_buf() +-- set buffer = bufnr in ftplugin/haskell.lua +local opts = { noremap = true, silent = true, buffer = bufnr } + +-- enable hovering +vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + +-- Toggle a GHCi repl for the current package +vim.keymap.set('n', 'rr', ht.repl.toggle, opts) +-- Toggle a GHCi repl for the current buffer +vim.keymap.set('n', 'rf', function() + ht.repl.toggle(vim.api.nvim_buf_get_name(0)) +end, def_opts) +vim.keymap.set('n', 'rq', ht.repl.quit, opts) + +-- Detect nvim-dap launch configurations +-- (requires nvim-dap and haskell-debug-adapter) +ht.dap.discover_configurations(bufnr) diff --git a/.config/nvim/ftplugin/markdown.vim b/.config/nvim/ftplugin/markdown.vim new file mode 100644 index 0000000..3902f56 --- /dev/null +++ b/.config/nvim/ftplugin/markdown.vim @@ -0,0 +1,10 @@ +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +let g:markdown_fenced_languages = ['c', 'css', 'sh', 'vim', 'futhark'] +let g:markdown_minlines = 64 + +setlocal spell +setlocal spelllang=en_us diff --git a/.config/nvim/ftplugin/tex.vim b/.config/nvim/ftplugin/tex.vim new file mode 100644 index 0000000..9bf703d --- /dev/null +++ b/.config/nvim/ftplugin/tex.vim @@ -0,0 +1,108 @@ +function! GetMainDoc() + let l:maindoc = search('\\begin{document}', "cnw") + if l:maindoc > 0 + return '%' + else + " Find the main document file + " Must be in the same folder of the current file + let l:maindocscmd = "grep -lrE '\\\\begin{document}' " . expand('%:h') . "/*.tex" + let l:maindocssys = system(l:maindocscmd) + let l:maindocs = split(l:maindocssys) + if len(l:maindocs) > 0 + " Use the first document containing `begin{document}` + return l:maindocs[0] + else + return "" + endif + endif +endfunction + +function! CompileMainDoc() + let l:latexcmd ='autocmd BufWritePost ! + \ latexrun --latex-args="-synctex=1 -interaction=nonstopmode" ' + + execute(l:latexcmd . GetMainDoc()) +endfunction + +"function! Synctex() +" " remove 'silent' for debugging +" let l:doc = GetMainDoc() +" execute "silent !mv -u latex.out/" . substitute(l:doc, '\.tex', '') . ".synctex.gz ." +" execute "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . bufname('%') . " " . expand('%:t:r') . ".pdf" +" redraw! +"endfunction +function! Synctex() + " remove 'silent' for debugging + execute "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . bufname('%') . " " . g:syncpdf + redraw! +endfunction +nmap :call Synctex() + +setlocal spell +setlocal spelllang=en_us + +imap FTT \texttt{}i +imap FBF \textbf{}i +imap FIT \textit{}i +imap FSC \textsc{}i +imap MTT \mathtt{}i +imap MBF \mathbf{}i +imap MIT \mathit{}i +imap MSC \mathsc{}i + +imap (( \left(\right)F\i +imap {{ \left\{\right\}F\F\i +imap [[ \left[\right]F\i + +imap ~~ \neg +imap /\ \land +imap \/ \lor +imap -> \rightarrow +imap ==> \Rightarrow +imap <== \Leftarrow +imap <=> \Leftrightarrow +imap \|- \vdash +imap \|= \vDash +imap !-- \inference[]{%}{%}kk$F[a +imap !== \begin{align*}\end{align*}O +imap !ii \begin{itemize}\end{itemize}O\item Case +imap CC \item Case +imap EIMP \expEimp{<++>}{<++>}{<++>}F\ +imap [[ [\![ +imap ]] ]\!] + +imap CI $\land\mbox{I}$ +imap CE1 $\land\mbox{E}_1$ +imap CE2 $\land\mbox{E}_2$ +imap DI1 $\lor\mbox{I}_1$ +imap DI2 $\lor\mbox{I}_2$ +imap DE $\lor\mbox{E}$ +imap II $\Rightarrow\mbox{I}$ +imap IE $\Rightarrow\mbox{E}$ +imap NE $\neg\mbox{E}$ +imap NI $\neg\mbox{I}$ + +imap MCC \mathcal{}<++>T{i + +inoremap /<++>cf> +noremap /<++>cf> + +vnoremap `it `>a}` +vnoremap `bf `>a}` +vnoremap `tt `>a}` +vnoremap `mi `>a}` +vnoremap `mb `>a}` +vnoremap `mt `>a}` + +" put \begin{} \end{} tags tags around the current word +vnoremap YpkI\begin{A}jI\end{A}kA + +syntax sync minlines=10000 +"setlocal spell spelllang=en_US + +call CompileMainDoc() + +" autocmd BufRead *.tex imap /\ \land +" autocmd BufRead *.tex imap \/ \lor +" autocmd BufRead *.tex imap -> \rightarrow +" autocmd BufRead *.tex imap ~~ \neg -- cgit v1.3