From 511f115f65b9379cff519ec2b6b37690c97d3b58 Mon Sep 17 00:00:00 2001
From: Felix Tenley <dev@felschr.com>
Date: Fri, 14 Aug 2020 23:53:15 +0200
Subject: [PATCH] feat(neovim): add fix for vim-surround

---
 home/editors/neovim.nix           |  1 +
 home/editors/vim-surround-fix.vim | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 home/editors/vim-surround-fix.vim

diff --git a/home/editors/neovim.nix b/home/editors/neovim.nix
index b9af97f..c398228 100644
--- a/home/editors/neovim.nix
+++ b/home/editors/neovim.nix
@@ -99,6 +99,7 @@ in
     ];
     extraConfig = with builtins;
       readFile ./init.vim +
+      readFile ./vim-surround-fix.vim +
       readFile ./which-key.vim +
       readFile ./coc.vim;
       # readFile ./lsp.vim;
diff --git a/home/editors/vim-surround-fix.vim b/home/editors/vim-surround-fix.vim
new file mode 100644
index 0000000..464471c
--- /dev/null
+++ b/home/editors/vim-surround-fix.vim
@@ -0,0 +1,22 @@
+" fix for vim-surround in neovim
+" https://github.com/tpope/vim-surround/issues/272
+
+let g:surround_no_mappings = 1
+
+function! SurroundOp(char)
+    if v:operator ==# 'd'
+        return "\<plug>D" . a:char . "urround"
+    elseif v:operator ==# 'c'
+        return "\<plug>C" . a:char . "urround"
+    elseif v:operator ==# 'y'
+        return "\<plug>Y" . a:char . "urround"
+    endif
+    return ''
+endfunction
+
+omap <expr> s '<esc>'.SurroundOp('s')
+omap <expr> S '<esc>'.SurroundOp('S')
+
+imap    <C-S> <Plug>Isurround
+imap      <C-G>s <Plug>Isurround
+imap <C-G>S <Plug>ISurround