Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 9376ad8

Browse files
yoongumarijnh
authored andcommitted
[vim bindings] Allow selecting text enclosed in angled brackets
1 parent 728291d commit 9376ad8

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎addon/edit/matchbrackets.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
var Pos = CodeMirror.Pos;
1616

17-
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
17+
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<", "<": ">>", ">": "<<"};
1818

1919
function findMatchingBracket(cm, where, config) {
2020
var line = cm.getLineHandle(where.line), pos = where.ch - 1;
@@ -51,7 +51,7 @@
5151
var maxScanLines = (config && config.maxScanLines) || 1000;
5252

5353
var stack = [];
54-
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
54+
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]<>]/;
5555
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
5656
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
5757
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {

‎keymap/vim.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,12 +1995,10 @@
19951995
textObjectManipulation: function(cm, head, motionArgs, vim) {
19961996
// TODO: lots of possible exceptions that can be thrown here. Try da(
19971997
// outside of a () block.
1998-
1999-
// TODO: adding <> >< to this map doesn't work, presumably because
2000-
// they're operators
20011998
var mirroredPairs = {'(': ')', ')': '(',
20021999
'{': '}', '}': '{',
2003-
'[': ']', ']': '['};
2000+
'[': ']', ']': '[',
2001+
'<': '>', '>': '<'};
20042002
var selfPaired = {'\'': true, '"': true};
20052003

20062004
var character = motionArgs.selectedCharacter;
@@ -3802,11 +3800,13 @@
38023800
var bracketRegexp = ({
38033801
'(': /[()]/, ')': /[()]/,
38043802
'[': /[[\]]/, ']': /[[\]]/,
3805-
'{': /[{}]/, '}': /[{}]/})[symb];
3803+
'{': /[{}]/, '}': /[{}]/,
3804+
'<': /[<>]/, '>': /[<>]/})[symb];
38063805
var openSym = ({
38073806
'(': '(', ')': '(',
38083807
'[': '[', ']': '[',
3809-
'{': '{', '}': '{'})[symb];
3808+
'{': '{', '}': '{',
3809+
'<': '<', '>': '<'})[symb];
38103810
var curChar = cm.getLine(cur.line).charAt(cur.ch);
38113811
// Due to the behavior of scanForBracket, we need to add an offset if the
38123812
// cursor is on a matching open bracket.

‎test/vim_test.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,12 @@ testEdit('di]_middle_spc', 'a\t[\n\tbar\n]b', /r/, 'di]', 'a\t[]b');
13271327
testEdit('da[_middle_spc', 'a\t[\n\tbar\n]b', /r/, 'da[', 'a\tb');
13281328
testEdit('da]_middle_spc', 'a\t[\n\tbar\n]b', /r/, 'da]', 'a\tb');
13291329

1330+
// open and close on diff lines, open indented more than close
1331+
testEdit('di<_middle_spc', 'a\t<\n\tbar\n>b', /r/, 'di<', 'a\t<>b');
1332+
testEdit('di>_middle_spc', 'a\t<\n\tbar\n>b', /r/, 'di>', 'a\t<>b');
1333+
testEdit('da<_middle_spc', 'a\t<\n\tbar\n>b', /r/, 'da<', 'a\tb');
1334+
testEdit('da>_middle_spc', 'a\t<\n\tbar\n>b', /r/, 'da>', 'a\tb');
1335+
13301336
function testSelection(name, before, pos, keys, sel) {
13311337
return testVim(name, function(cm, vim, helpers) {
13321338
var ch = before.search(pos)

0 commit comments

Comments
 (0)