diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 2a530db934..7b2f77a6f9 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4931,7 +4931,8 @@ static void nv_ident(cmdarg_T *cap) snprintf(buf, buf_size, ".,.+%" PRId64, (int64_t)(cap->count0 - 1)); } - STRCAT(buf, "! "); + do_cmdline_cmd("tabnew"); + STRCAT(buf, "terminal "); if (cap->count0 == 0 && isman_s) { STRCAT(buf, "man"); } else { @@ -5028,6 +5029,17 @@ static void nv_ident(cmdarg_T *cap) g_tag_at_cursor = true; do_cmdline_cmd(buf); g_tag_at_cursor = false; + + if (cmdchar == 'K' && !kp_ex && !kp_help) { + // Start insert mode in terminal buffer + restart_edit = 'i'; + + add_map((char_u *)" call jobstop(&channel)", TERM_FOCUS, true); + do_cmdline_cmd("autocmd TermClose " + " if !v:event.status |" + " exec 'bdelete! ' .. expand('') |" + " endif"); + } } xfree(buf); diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 5c413d1e16..aff22f5d01 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -1227,7 +1227,7 @@ func Test_normal23_K() set iskeyword-=\| " Only expect "man" to work on Unix - if !has("unix") + if !has("unix") || has('nvim') " Nvim K uses :terminal. #15398 let &keywordprg = k bw! return diff --git a/test/functional/normal/K_spec.lua b/test/functional/normal/K_spec.lua index 174313d80e..40f36491e4 100644 --- a/test/functional/normal/K_spec.lua +++ b/test/functional/normal/K_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, eval, feed = - helpers.eq, helpers.clear, helpers.eval, helpers.feed +local eq, clear, eval, feed, retry = + helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.retry describe('K', function() local test_file = 'K_spec_out' @@ -31,7 +31,7 @@ describe('K', function() -- K on the text "K_spec_out" resolves to `!echo fnord >> K_spec_out`. feed('i'..test_file..'K') - feed('') -- Press ENTER + retry(nil, nil, function() eq(1, eval('filereadable("'..test_file..'")')) end) eq({'fnord'}, eval("readfile('"..test_file.."')")) end)