Merge pull request #1716 from ZyX-I/support-more-vim-modes

Support more vim modes
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2017-02-13 20:33:03 +03:00 committed by GitHub
commit 01d28baf72
9 changed files with 56 additions and 13 deletions

View File

@ -105,8 +105,12 @@
"S": "S-LINE",
"^S": "S-BLCK",
"i": "INSERT",
"ic": "I-COMP",
"ix": "I-C_X ",
"R": "RPLACE",
"Rv": "V-RPLC",
"Rc": "R-COMP",
"Rx": "R-C_X ",
"c": "COMMND",
"cv": "VIM-EX",
"ce": "NRM-EX",

View File

@ -103,8 +103,12 @@
"S": "S·LINE",
"^S": "S·BLCK",
"i": "INSERT",
"ic": "I·COMP",
"ix": "I·C-X ",
"R": "RPLACE",
"Rv": "V·RPLC",
"Rc": "R·COMP",
"Rx": "R·C-X ",
"c": "COMMND",
"cv": "VIM·EX",
"ce": "NRM·EX",

View File

@ -103,8 +103,12 @@
"S": "S·LINE",
"^S": "S·BLCK",
"i": "INSERT",
"ic": "I·COMP",
"ix": "I·C-X ",
"R": "RPLACE",
"Rv": "V·RPLC",
"Rc": "R·COMP",
"Rx": "R·C-X ",
"c": "COMMND",
"cv": "VIM·EX",
"ce": "NRM·EX",

View File

@ -117,8 +117,12 @@
"S": "S·LINE",
"^S": "S·BLCK",
"i": "INSERT",
"ic": "I·COMP",
"ix": "I·C-X ",
"R": "RPLACE",
"Rv": "V·RPLC",
"Rc": "R·COMP",
"Rx": "R·C-X ",
"c": "COMMND",
"cv": "VIM·EX",
"ce": "NRM·EX",

View File

@ -103,8 +103,12 @@
"S": "S·LINE",
"^S": "S·BLCK",
"i": "INSERT",
"ic": "I·COMP",
"ix": "I·C-X ",
"R": "RPLACE",
"Rv": "V·RPLC",
"Rc": "R·COMP",
"Rx": "R·C-X ",
"c": "COMMND",
"cv": "VIM·EX",
"ce": "NRM·EX",

View File

@ -103,8 +103,12 @@
"S": "S·LINE",
"^S": "S·BLCK",
"i": "INSERT",
"ic": "I·COMP",
"ix": "I·C-X ",
"R": "RPLACE",
"Rv": "V·RPLC",
"Rc": "R·COMP",
"Rx": "R·C-X ",
"c": "COMMND",
"cv": "VIM·EX",
"ce": "NRM·EX",

View File

@ -104,8 +104,12 @@
"S": "SLN",
"^S": "SBL",
"i": "INS",
"ic": "I-C",
"ix": "I^X",
"R": "REP",
"Rv": "VRP",
"Rc": "R-C",
"Rx": "R^X",
"c": "CMD",
"cv": "VEX",
"ce": " EX",

View File

@ -50,15 +50,19 @@ vim_modes = {
'S': 'S-LINE',
'^S': 'S-BLCK',
'i': 'INSERT',
'R': 'REPLACE',
'Rv': 'V-RPLCE',
'ic': 'I-COMP',
'ix': 'I-C_X ',
'R': 'RPLACE',
'Rv': 'V-RPLC',
'Rc': 'R-COMP',
'Rx': 'R-C_X ',
'c': 'COMMND',
'cv': 'VIM EX',
'ce': 'EX',
'cv': 'VIM-EX',
'ce': 'NRM-EX',
'r': 'PROMPT',
'rm': 'MORE',
'r?': 'CONFIRM',
'!': 'SHELL',
'rm': '-MORE-',
'r?': 'CNFIRM',
'!': '!SHELL',
}
@ -87,18 +91,27 @@ def window_cached(func):
def mode(pl, segment_info, override=None):
'''Return the current vim mode.
If mode (returned by ``mode()`` VimL function, see ``:h mode()`` in Vim)
consists of multiple characters and necessary mode is not known to powerline
then it will fall back to mode with last character(s) ignored.
:param dict override:
dict for overriding default mode strings, e.g. ``{ 'n': 'NORM' }``
'''
mode = segment_info['mode']
if mode == 'nc':
return None
if not override:
return vim_modes[mode]
try:
return override[mode]
except KeyError:
return vim_modes[mode]
while mode:
try:
if not override:
return vim_modes[mode]
try:
return override[mode]
except KeyError:
return vim_modes[mode]
except KeyError:
mode = mode[:-1]
return 'BUG'
@window_cached

View File

@ -1159,6 +1159,8 @@ class TestVim(TestCase):
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info, override={'n': 'NORM'}), 'NORM')
with vim_module._with('mode', 'i') as segment_info:
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'INSERT')
with vim_module._with('mode', 'i\0') as segment_info:
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'INSERT')
with vim_module._with('mode', chr(ord('V') - 0x40)) as segment_info:
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'V-BLCK')
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')