From 8dd9a875066472ab291e571206ca209bfc5de7b9 Mon Sep 17 00:00:00 2001
From: Travis Heppe <heppe@heppe-macbookpro4.roam.corp.google.com>
Date: Tue, 20 Jun 2017 20:15:09 -0700
Subject: [PATCH] [vim bindings] Rewrite queries that end in $

into a form that CodeMirror can understand.
---
 keymap/vim.js    | 4 ++++
 test/vim_test.js | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/keymap/vim.js b/keymap/vim.js
index 336f1a7cc..d8a2d60d4 100644
--- a/keymap/vim.js
+++ b/keymap/vim.js
@@ -4509,6 +4509,10 @@
         if (tokens.length) {
           regexPart = tokens[0];
           replacePart = tokens[1];
+          if (regexPart && regexPart[regexPart.length - 1] === '$') {
+            regexPart = regexPart.slice(0, regexPart.length - 1) + '\\n';
+            replacePart = replacePart ? replacePart + '\n' : '\n';
+          }
           if (replacePart !== undefined) {
             if (getOption('pcre')) {
               replacePart = unescapeRegexReplace(replacePart);
diff --git a/test/vim_test.js b/test/vim_test.js
index 86a544756..da49a24cf 100644
--- a/test/vim_test.js
+++ b/test/vim_test.js
@@ -3789,6 +3789,14 @@ testSubstitute('ex_substitute_multibackslash_replacement', {
   value: 'one,two \n three,four',
   expectedValue: 'one\\\\\\\\two \n three\\\\\\\\four', // 2*8 backslashes.
   expr: '%s/,/\\\\\\\\\\\\\\\\/g'}); // 16 backslashes.
+testSubstitute('ex_substitute_dollar_match', {
+  value: 'one,two \n three,four',
+  expectedValue: 'one,two ,\n three,four',
+  expr: '%s/$/,/g'});
+testSubstitute('ex_substitute_newline_match', {
+  value: 'one,two \n three,four',
+  expectedValue: 'one,two , three,four',
+  expr: '%s/\\n/,/g'});
 testSubstitute('ex_substitute_newline_replacement', {
   value: 'one,two \n three,four',
   expectedValue: 'one\ntwo \n three\nfour',
-- 
GitLab