diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/auevents.lua | 1 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 24 | ||||
-rw-r--r-- | src/nvim/fileio.c | 5 | ||||
-rw-r--r-- | src/nvim/syntax.c | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_mapping.vim | 16 |
5 files changed, 43 insertions, 4 deletions
diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index d002aaae43..e6285c5c76 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -27,6 +27,7 @@ return { 'CmdWinEnter', -- after entering the cmdline window 'CmdWinLeave', -- before leaving the cmdline window 'ColorScheme', -- after loading a colorscheme + 'ColorSchemePre', -- before loading a colorscheme 'CompleteDone', -- after finishing insert complete 'CursorHold', -- cursor in same position for a while 'CursorHoldI', -- idem, in Insert mode diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 1ec00b1e25..247b9175aa 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3522,10 +3522,28 @@ void gotocmdline(int clr) */ static int ccheck_abbr(int c) { - if (p_paste || no_abbr) /* no abbreviations or in paste mode */ - return FALSE; + int spos = 0; + + if (p_paste || no_abbr) { // no abbreviations or in paste mode + return false; + } + + // Do not consider '<,'> be part of the mapping, skip leading whitespace. + // Actually accepts any mark. + while (ascii_iswhite(ccline.cmdbuff[spos]) && spos < ccline.cmdlen) { + spos++; + } + if (ccline.cmdlen - spos > 5 + && ccline.cmdbuff[spos] == '\'' + && ccline.cmdbuff[spos + 2] == ',' + && ccline.cmdbuff[spos + 3] == '\'') { + spos += 5; + } else { + // check abbreviation from the beginning of the commandline + spos = 0; + } - return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, 0); + return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); } static int sort_func_compare(const void *s1, const void *s2) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 3ab7710de5..a5ff13552b 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6779,7 +6779,9 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, * invalid. */ if (fname_io == NULL) { - if (event == EVENT_COLORSCHEME || event == EVENT_OPTIONSET) { + if (event == EVENT_COLORSCHEME + || event == EVENT_COLORSCHEMEPRE + || event == EVENT_OPTIONSET) { autocmd_fname = NULL; } else if (fname != NULL && !ends_excmd(*fname)) { autocmd_fname = fname; @@ -6830,6 +6832,7 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, sfname = vim_strsave(fname); // Don't try expanding the following events. if (event == EVENT_COLORSCHEME + || event == EVENT_COLORSCHEMEPRE || event == EVENT_DIRCHANGED || event == EVENT_FILETYPE || event == EVENT_FUNCUNDEFINED diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index e0e1897b88..5c8b5899df 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -6326,6 +6326,7 @@ int load_colors(char_u *name) recursive = true; size_t buflen = STRLEN(name) + 12; buf = xmalloc(buflen); + apply_autocmds(EVENT_COLORSCHEMEPRE, name, curbuf->b_fname, false, curbuf); snprintf((char *)buf, buflen, "colors/%s.vim", name); retval = source_runtime(buf, DIP_START + DIP_OPT); xfree(buf); diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index f4fe1c2705..071b8b369b 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -198,3 +198,19 @@ func Test_map_timeout() set timeoutlen& delfunc ExitInsert endfunc + +func Test_cabbr_visual_mode() + cabbr s su + call feedkeys(":s \<c-B>\"\<CR>", 'itx') + call assert_equal('"su ', getreg(':')) + call feedkeys(":'<,'>s \<c-B>\"\<CR>", 'itx') + let expected = '"'. "'<,'>su " + call assert_equal(expected, getreg(':')) + call feedkeys(": '<,'>s \<c-B>\"\<CR>", 'itx') + let expected = '" '. "'<,'>su " + call assert_equal(expected, getreg(':')) + call feedkeys(":'a,'bs \<c-B>\"\<CR>", 'itx') + let expected = '"'. "'a,'bsu " + call assert_equal(expected, getreg(':')) + cunabbr s +endfunc |