diff --git a/home/nvim/default.nix b/home/nvim/default.nix index 2a368fe..043dec6 100644 --- a/home/nvim/default.nix +++ b/home/nvim/default.nix @@ -2,7 +2,7 @@ { programs.neovim = { - extraConfig = import ./config.vim; + extraConfig = builtins.readFile ./config.vim; enable = true; defaultEditor = true; plugins = with pkgs.vimPlugins; [ diff --git a/home/nvim/ftplugin/markdown.vim b/home/nvim/ftplugin/markdown.vim new file mode 100644 index 0000000..44096b3 --- /dev/null +++ b/home/nvim/ftplugin/markdown.vim @@ -0,0 +1,43 @@ +setlocal spell +setlocal textwidth=0 +setlocal syntax=rmd +setlocal breakat-=@ + +set makeprg=Rscript\ -e\ 'publishR::render(\\"%\\")' + +" nnoremap oh :! xdg-open %:r.html +nnoremap oh :! chromium-browser %:r.html +nnoremap op :! xdg-open %:r.pdf +nnoremap ow :! xdg-open %:r.docx + +nnoremap t :TOC + +xnoremap ic :call InnerChunk() +onoremap ic :call InnerChunk() +xnoremap ac :call OuterChunk() +onoremap ac :call OuterChunk() + +function OuterChunk() + let chunk = FindChunk() + execute "normal! " . chunk.start . "GV" . chunk.end . "G" +endfunction + +function InnerChunk() + let chunk = FindChunk() + execute "normal! " . chunk.start . "GjV" . chunk.end . "Gk" +endfunction + +function FindChunk() + let view = winsaveview() + normal! j + ?\v^ *```(\{.*\})=$ + let startFence = line(".") + /\v^ *``` * + let endFence = line(".") + if startFence <= view.lnum && endFence >= view.lnum + return {"start": startFence, "end": endFence} + else + echoerr "Not inside a chunk" + endif + call winrestview(view) +endfunction diff --git a/home/nvim/ftplugin/r.vim b/home/nvim/ftplugin/r.vim new file mode 100644 index 0000000..beae9bd --- /dev/null +++ b/home/nvim/ftplugin/r.vim @@ -0,0 +1,6 @@ +nnoremap i :! R CMD INSTALL `git rev-parse --show-toplevel` +nnoremap d :! R -e "devtools::document()" +nnoremap t :! R -e "devtools::test()" + +" nnoremap rl :vsplit \| :terminal R +nnoremap rl :silent exec "! tmux source-file ~/.config/tmux/rloft.conf" diff --git a/home/nvim/ftplugin/rmd.vim b/home/nvim/ftplugin/rmd.vim new file mode 100644 index 0000000..d900836 --- /dev/null +++ b/home/nvim/ftplugin/rmd.vim @@ -0,0 +1,43 @@ +runtime ftplugin/markdown.vim +runtime ftplugin/r.vim + +" let g:slime_cell_delimiter = "```" +nmap snc SlimeMotionSendic/```{:nohj + +nmap pd :execute 'SlimeSend1 datapasta::tribble_construct() \|> clipr::write_clip()':sleep500ms"*p +nmap pv :execute 'SlimeSend1 datapasta::vector_construct() \|> clipr::write_clip()':sleep500ms"*p + +nmap sc :set opfunc=SendAndPasteg@ +nmap sc ^:set opfunc=SendAndPasteg@$ +vmap sc :call SendAndPaste(visualmode(), 1) + +function! SendAndPaste(type, ...) + + let v = winsaveview() + let sel_save = &selection + let &selection = "inclusive" + let reg_save = @@ + + if a:0 " Invoked from Visual mode, use gv command. + silent exe "normal! gvy" + elseif a:type == 'line' + silent exe "normal! '[V']y" + else + silent exe "normal! `[v`]y" + endif + + call slime#send(trim(@@) . " |> capture.output() |> clipr::write_clip()\r") + + /``` + call append(line("."), ["", "```{r}", "```"]) + /```{r} + sleep 500m + let @*=substitute(@*, '\e\[[0-9;]*m', '', 'g') + :put* + call winrestview(v) + let &selection = sel_save + let @@ = reg_save +endfunction + + +:UltiSnipsAddFiletypes rmd.r.markdown diff --git a/home/nvim/syntax/rmd.vim b/home/nvim/syntax/rmd.vim new file mode 100644 index 0000000..d5bb553 --- /dev/null +++ b/home/nvim/syntax/rmd.vim @@ -0,0 +1,4 @@ +syn region math start=/\$\$/ end=/\$\$/ +syn match math_block '\$[^$].\{-}\$' +hi link math Statement +hi link math_block Statement