aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/normal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r--src/nvim/normal.c1089
1 files changed, 155 insertions, 934 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 03312e5df4..a8769c4c80 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -31,8 +31,8 @@
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
+#include "nvim/globals.h"
#include "nvim/indent.h"
-#include "nvim/indent_c.h"
#include "nvim/keymap.h"
#include "nvim/log.h"
#include "nvim/main.h"
@@ -40,7 +40,6 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/misc1.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/normal.h"
@@ -84,12 +83,6 @@ typedef struct normal_state {
pos_T old_pos;
} NormalState;
-/*
- * The Visual area is remembered for reselection.
- */
-static int resel_VIsual_mode = NUL; // 'v', 'V', or Ctrl-V
-static linenr_T resel_VIsual_line_count; // number of lines
-static colnr_T resel_VIsual_vcol; // nr of cols or end col
static int VIsual_mode_orig = NUL; // saved Visual mode
@@ -171,7 +164,7 @@ static const struct nv_cmd {
{ Ctrl_O, nv_ctrlo, 0, 0 },
{ Ctrl_P, nv_up, NV_STS, false },
{ Ctrl_Q, nv_visual, 0, false },
- { Ctrl_R, nv_redo, 0, 0 },
+ { Ctrl_R, nv_redo_or_register, 0, 0 },
{ Ctrl_S, nv_ignore, 0, 0 },
{ Ctrl_T, nv_tagpop, NV_NCW, 0 },
{ Ctrl_U, nv_halfpage, 0, 0 },
@@ -236,7 +229,7 @@ static const struct nv_cmd {
{ 'N', nv_next, 0, SEARCH_REV },
{ 'O', nv_open, 0, 0 },
{ 'P', nv_put, 0, 0 },
- { 'Q', nv_exmode, NV_NCW, 0 },
+ { 'Q', nv_regreplay, 0, 0 },
{ 'R', nv_Replace, 0, false },
{ 'S', nv_subst, NV_KEEPREG, 0 },
{ 'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD },
@@ -341,6 +334,7 @@ static const struct nv_cmd {
{ K_SELECT, nv_select, 0, 0 },
{ K_EVENT, nv_event, NV_KEEPREG, 0 },
{ K_COMMAND, nv_colon, 0, 0 },
+ { K_LUA, nv_colon, 0, 0 },
};
// Number of commands in nv_cmds[].
@@ -487,6 +481,7 @@ static void normal_prepare(NormalState *s)
if (finish_op != c) {
ui_cursor_shape(); // may show different cursor shape
}
+ may_trigger_modechanged();
// When not finishing an operator and no register name typed, reset the count.
if (!finish_op && !s->oa.regname) {
@@ -829,15 +824,12 @@ static bool normal_get_command_count(NormalState *s)
if (s->c == K_DEL || s->c == K_KDEL) {
s->ca.count0 /= 10;
del_from_showcmd(4); // delete the digit and ~@%
+ } else if (s->ca.count0 > 99999999L) {
+ s->ca.count0 = 999999999L;
} else {
s->ca.count0 = s->ca.count0 * 10 + (s->c - '0');
}
- if (s->ca.count0 < 0) {
- // overflow
- s->ca.count0 = 999999999L;
- }
-
// Set v:count here, when called from main() and not a stuffed
// command, so that v:count can be used in an expression mapping
// right after the count. Do set it for redo.
@@ -928,6 +920,7 @@ normal_end:
// Reset finish_op, in case it was set
s->c = finish_op;
finish_op = false;
+ may_trigger_modechanged();
// Redraw the cursor with another shape, if we were in Operator-pending
// mode or did a replace command.
if (s->c || s->ca.cmdchar == 'r') {
@@ -965,6 +958,8 @@ normal_end:
&& s->oa.regname == 0) {
if (restart_VIsual_select == 1) {
VIsual_select = true;
+ VIsual_select_reg = 0;
+ may_trigger_modechanged();
showmode();
restart_VIsual_select = 0;
}
@@ -1013,7 +1008,14 @@ static int normal_execute(VimState *state, int key)
// restart automatically.
// Insert the typed character in the typeahead buffer, so that it can
// be mapped in Insert mode. Required for ":lmap" to work.
- ins_char_typebuf(s->c);
+ int len = ins_char_typebuf(s->c, mod_mask);
+
+ // When recording and gotchars() was called the character will be
+ // recorded again, remove the previous recording.
+ if (KeyTyped) {
+ ungetchars(len);
+ }
+
if (restart_edit != 0) {
s->c = 'd';
} else {
@@ -1025,7 +1027,7 @@ static int normal_execute(VimState *state, int key)
s->need_flushbuf = add_to_showcmd(s->c);
- while (normal_get_command_count(s)) { continue; }
+ while (normal_get_command_count(s)) { }
if (s->c == K_EVENT) {
// Save the count values so that ca.opcount and ca.count0 are exactly
@@ -1041,14 +1043,14 @@ static int normal_execute(VimState *state, int key)
// If you give a count before AND after the operator, they are
// multiplied.
if (s->ca.count0) {
- s->ca.count0 = (long)((uint64_t)s->ca.count0 * (uint64_t)s->ca.opcount);
+ if (s->ca.opcount >= 999999999L / s->ca.count0) {
+ s->ca.count0 = 999999999L;
+ } else {
+ s->ca.count0 *= s->ca.opcount;
+ }
} else {
s->ca.count0 = s->ca.opcount;
}
- if (s->ca.count0 < 0) {
- // overflow
- s->ca.count0 = 999999999L;
- }
}
// Always remember the count. It will be set to zero (on the next call,
@@ -1221,22 +1223,18 @@ static void normal_check_interrupt(NormalState *s)
static void normal_check_window_scrolled(NormalState *s)
{
- // Trigger Scroll if the viewport changed.
- if (!finish_op && has_event(EVENT_WINSCROLLED)
- && win_did_scroll(curwin)) {
- do_autocmd_winscrolled(curwin);
+ if (!finish_op) {
+ // Trigger Scroll if the viewport changed.
+ may_trigger_winscrolled();
}
}
static void normal_check_cursor_moved(NormalState *s)
{
// Trigger CursorMoved if the cursor moved.
- if (!finish_op && (has_event(EVENT_CURSORMOVED) || curwin->w_p_cole > 0)
+ if (!finish_op && has_event(EVENT_CURSORMOVED)
&& !equalpos(curwin->w_last_cursormoved, curwin->w_cursor)) {
- if (has_event(EVENT_CURSORMOVED)) {
- apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, false, curbuf);
- }
-
+ apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, false, curbuf);
curwin->w_last_cursormoved = curwin->w_cursor;
}
}
@@ -1286,22 +1284,6 @@ static void normal_redraw(NormalState *s)
update_topline(curwin);
validate_cursor();
- // If the cursor moves horizontally when 'concealcursor' is active, then the
- // current line needs to be redrawn in order to calculate the correct
- // cursor position.
- if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) {
- redrawWinline(curwin, curwin->w_cursor.lnum);
- }
-
- // Might need to update for 'cursorline'.
- // When 'cursorlineopt' is "screenline" need to redraw always.
- if (curwin->w_p_cul
- && (curwin->w_last_cursorline != curwin->w_cursor.lnum
- || (curwin->w_p_culopt_flags & CULOPT_SCRLINE))
- && !char_avail()) {
- redraw_later(curwin, VALID);
- }
-
if (VIsual_active) {
update_curbuf(INVERTED); // update inverted part
} else if (must_redraw) {
@@ -1370,9 +1352,10 @@ static int normal_check(VimState *state)
if (skip_redraw || exmode_active) {
skip_redraw = false;
} else if (do_redraw || stuff_empty()) {
- // Need to make sure w_topline and w_leftcol are correct before
- // normal_check_window_scrolled() is called.
+ // Ensure curwin->w_topline and curwin->w_leftcol are up to date
+ // before triggering a WinScrolled autocommand.
update_topline(curwin);
+ validate_cursor();
normal_check_cursor_moved(s);
normal_check_text_changed(s);
@@ -1452,758 +1435,6 @@ static void set_vcount_ca(cmdarg_T *cap, bool *set_prevcount)
*set_prevcount = false; // only set v:prevcount once
}
-// Handle an operator after Visual mode or when the movement is finished.
-// "gui_yank" is true when yanking text for the clipboard.
-void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
-{
- oparg_T *oap = cap->oap;
- pos_T old_cursor;
- bool empty_region_error;
- int restart_edit_save;
- int lbr_saved = curwin->w_p_lbr;
-
-
- // The visual area is remembered for redo
- static int redo_VIsual_mode = NUL; // 'v', 'V', or Ctrl-V
- static linenr_T redo_VIsual_line_count; // number of lines
- static colnr_T redo_VIsual_vcol; // number of cols or end column
- static long redo_VIsual_count; // count for Visual operator
- static int redo_VIsual_arg; // extra argument
- bool include_line_break = false;
-
- old_cursor = curwin->w_cursor;
-
- /*
- * If an operation is pending, handle it...
- */
- if ((finish_op
- || VIsual_active)
- && oap->op_type != OP_NOP) {
- // Yank can be redone when 'y' is in 'cpoptions', but not when yanking
- // for the clipboard.
- const bool redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank;
-
- // Avoid a problem with unwanted linebreaks in block mode
- if (curwin->w_p_lbr) {
- curwin->w_valid &= ~VALID_VIRTCOL;
- }
- curwin->w_p_lbr = false;
- oap->is_VIsual = VIsual_active;
- if (oap->motion_force == 'V') {
- oap->motion_type = kMTLineWise;
- } else if (oap->motion_force == 'v') {
- // If the motion was linewise, "inclusive" will not have been set.
- // Use "exclusive" to be consistent. Makes "dvj" work nice.
- if (oap->motion_type == kMTLineWise) {
- oap->inclusive = false;
- } else if (oap->motion_type == kMTCharWise) {
- // If the motion already was charwise, toggle "inclusive"
- oap->inclusive = !oap->inclusive;
- }
- oap->motion_type = kMTCharWise;
- } else if (oap->motion_force == Ctrl_V) {
- // Change line- or charwise motion into Visual block mode.
- if (!VIsual_active) {
- VIsual_active = true;
- VIsual = oap->start;
- }
- VIsual_mode = Ctrl_V;
- VIsual_select = false;
- VIsual_reselect = false;
- }
-
- // Only redo yank when 'y' flag is in 'cpoptions'.
- // Never redo "zf" (define fold).
- if ((redo_yank || oap->op_type != OP_YANK)
- && ((!VIsual_active || oap->motion_force)
- // Also redo Operator-pending Visual mode mappings.
- || ((cap->cmdchar == ':' || cap->cmdchar == K_COMMAND)
- && oap->op_type != OP_COLON))
- && cap->cmdchar != 'D'
- && oap->op_type != OP_FOLD
- && oap->op_type != OP_FOLDOPEN
- && oap->op_type != OP_FOLDOPENREC
- && oap->op_type != OP_FOLDCLOSE
- && oap->op_type != OP_FOLDCLOSEREC
- && oap->op_type != OP_FOLDDEL
- && oap->op_type != OP_FOLDDELREC) {
- prep_redo(oap->regname, cap->count0,
- get_op_char(oap->op_type), get_extra_op_char(oap->op_type),
- oap->motion_force, cap->cmdchar, cap->nchar);
- if (cap->cmdchar == '/' || cap->cmdchar == '?') { // was a search
- /*
- * If 'cpoptions' does not contain 'r', insert the search
- * pattern to really repeat the same command.
- */
- if (vim_strchr(p_cpo, CPO_REDO) == NULL) {
- AppendToRedobuffLit(cap->searchbuf, -1);
- }
- AppendToRedobuff(NL_STR);
- } else if (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND) {
- // do_cmdline() has stored the first typed line in
- // "repeat_cmdline". When several lines are typed repeating
- // won't be possible.
- if (repeat_cmdline == NULL) {
- ResetRedobuff();
- } else {
- AppendToRedobuffLit(repeat_cmdline, -1);
- AppendToRedobuff(NL_STR);
- XFREE_CLEAR(repeat_cmdline);
- }
- }
- }
-
- if (redo_VIsual_busy) {
- /* Redo of an operation on a Visual area. Use the same size from
- * redo_VIsual_line_count and redo_VIsual_vcol. */
- oap->start = curwin->w_cursor;
- curwin->w_cursor.lnum += redo_VIsual_line_count - 1;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
- curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- }
- VIsual_mode = redo_VIsual_mode;
- if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') {
- if (VIsual_mode == 'v') {
- if (redo_VIsual_line_count <= 1) {
- validate_virtcol();
- curwin->w_curswant =
- curwin->w_virtcol + redo_VIsual_vcol - 1;
- } else {
- curwin->w_curswant = redo_VIsual_vcol;
- }
- } else {
- curwin->w_curswant = MAXCOL;
- }
- coladvance(curwin->w_curswant);
- }
- cap->count0 = redo_VIsual_count;
- cap->count1 = (cap->count0 == 0 ? 1 : cap->count0);
- } else if (VIsual_active) {
- if (!gui_yank) {
- // Save the current VIsual area for '< and '> marks, and "gv"
- curbuf->b_visual.vi_start = VIsual;
- curbuf->b_visual.vi_end = curwin->w_cursor;
- curbuf->b_visual.vi_mode = VIsual_mode;
- if (VIsual_mode_orig != NUL) {
- curbuf->b_visual.vi_mode = VIsual_mode_orig;
- VIsual_mode_orig = NUL;
- }
- curbuf->b_visual.vi_curswant = curwin->w_curswant;
- curbuf->b_visual_mode_eval = VIsual_mode;
- }
-
- // In Select mode, a linewise selection is operated upon like a
- // charwise selection.
- // Special case: gH<Del> deletes the last line.
- if (VIsual_select && VIsual_mode == 'V'
- && cap->oap->op_type != OP_DELETE) {
- if (lt(VIsual, curwin->w_cursor)) {
- VIsual.col = 0;
- curwin->w_cursor.col =
- (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum));
- } else {
- curwin->w_cursor.col = 0;
- VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum));
- }
- VIsual_mode = 'v';
- }
- /* If 'selection' is "exclusive", backup one character for
- * charwise selections. */
- else if (VIsual_mode == 'v') {
- include_line_break =
- unadjust_for_sel();
- }
-
- oap->start = VIsual;
- if (VIsual_mode == 'V') {
- oap->start.col = 0;
- oap->start.coladd = 0;
- }
- }
-
- /*
- * Set oap->start to the first position of the operated text, oap->end
- * to the end of the operated text. w_cursor is equal to oap->start.
- */
- if (lt(oap->start, curwin->w_cursor)) {
- // Include folded lines completely.
- if (!VIsual_active) {
- if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) {
- oap->start.col = 0;
- }
- if ((curwin->w_cursor.col > 0
- || oap->inclusive
- || oap->motion_type == kMTLineWise)
- && hasFolding(curwin->w_cursor.lnum, NULL,
- &curwin->w_cursor.lnum)) {
- curwin->w_cursor.col = (colnr_T)STRLEN(get_cursor_line_ptr());
- }
- }
- oap->end = curwin->w_cursor;
- curwin->w_cursor = oap->start;
-
- /* w_virtcol may have been updated; if the cursor goes back to its
- * previous position w_virtcol becomes invalid and isn't updated
- * automatically. */
- curwin->w_valid &= ~VALID_VIRTCOL;
- } else {
- // Include folded lines completely.
- if (!VIsual_active && oap->motion_type == kMTLineWise) {
- if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum,
- NULL)) {
- curwin->w_cursor.col = 0;
- }
- if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) {
- oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum));
- }
- }
- oap->end = oap->start;
- oap->start = curwin->w_cursor;
- }
-
- // Just in case lines were deleted that make the position invalid.
- check_pos(curwin->w_buffer, &oap->end);
- oap->line_count = oap->end.lnum - oap->start.lnum + 1;
-
- // Set "virtual_op" before resetting VIsual_active.
- virtual_op = virtual_active();
-
- if (VIsual_active || redo_VIsual_busy) {
- get_op_vcol(oap, redo_VIsual_vcol, true);
-
- if (!redo_VIsual_busy && !gui_yank) {
- /*
- * Prepare to reselect and redo Visual: this is based on the
- * size of the Visual text
- */
- resel_VIsual_mode = VIsual_mode;
- if (curwin->w_curswant == MAXCOL) {
- resel_VIsual_vcol = MAXCOL;
- } else {
- if (VIsual_mode != Ctrl_V) {
- getvvcol(curwin, &(oap->end),
- NULL, NULL, &oap->end_vcol);
- }
- if (VIsual_mode == Ctrl_V || oap->line_count <= 1) {
- if (VIsual_mode != Ctrl_V) {
- getvvcol(curwin, &(oap->start),
- &oap->start_vcol, NULL, NULL);
- }
- resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1;
- } else {
- resel_VIsual_vcol = oap->end_vcol;
- }
- }
- resel_VIsual_line_count = oap->line_count;
- }
-
- // can't redo yank (unless 'y' is in 'cpoptions') and ":"
- if ((redo_yank || oap->op_type != OP_YANK)
- && oap->op_type != OP_COLON
- && oap->op_type != OP_FOLD
- && oap->op_type != OP_FOLDOPEN
- && oap->op_type != OP_FOLDOPENREC
- && oap->op_type != OP_FOLDCLOSE
- && oap->op_type != OP_FOLDCLOSEREC
- && oap->op_type != OP_FOLDDEL
- && oap->op_type != OP_FOLDDELREC
- && oap->motion_force == NUL) {
- /* Prepare for redoing. Only use the nchar field for "r",
- * otherwise it might be the second char of the operator. */
- if (cap->cmdchar == 'g' && (cap->nchar == 'n'
- || cap->nchar == 'N')) {
- prep_redo(oap->regname, cap->count0,
- get_op_char(oap->op_type), get_extra_op_char(oap->op_type),
- oap->motion_force, cap->cmdchar, cap->nchar);
- } else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND) {
- int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;
-
- // reverse what nv_replace() did
- if (nchar == REPLACE_CR_NCHAR) {
- nchar = CAR;
- } else if (nchar == REPLACE_NL_NCHAR) {
- nchar = NL;
- }
- prep_redo(oap->regname, 0L, NUL, 'v', get_op_char(oap->op_type),
- get_extra_op_char(oap->op_type), nchar);
- }
- if (!redo_VIsual_busy) {
- redo_VIsual_mode = resel_VIsual_mode;
- redo_VIsual_vcol = resel_VIsual_vcol;
- redo_VIsual_line_count = resel_VIsual_line_count;
- redo_VIsual_count = cap->count0;
- redo_VIsual_arg = cap->arg;
- }
- }
-
- // oap->inclusive defaults to true.
- // If oap->end is on a NUL (empty line) oap->inclusive becomes
- // false. This makes "d}P" and "v}dP" work the same.
- if (oap->motion_force == NUL || oap->motion_type == kMTLineWise) {
- oap->inclusive = true;
- }
- if (VIsual_mode == 'V') {
- oap->motion_type = kMTLineWise;
- } else if (VIsual_mode == 'v') {
- oap->motion_type = kMTCharWise;
- if (*ml_get_pos(&(oap->end)) == NUL
- && (include_line_break || !virtual_op)) {
- oap->inclusive = false;
- // Try to include the newline, unless it's an operator
- // that works on lines only.
- if (*p_sel != 'o'
- && !op_on_lines(oap->op_type)
- && oap->end.lnum < curbuf->b_ml.ml_line_count) {
- oap->end.lnum++;
- oap->end.col = 0;
- oap->end.coladd = 0;
- oap->line_count++;
- }
- }
- }
-
- redo_VIsual_busy = false;
-
- /*
- * Switch Visual off now, so screen updating does
- * not show inverted text when the screen is redrawn.
- * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is
- * no screen redraw, so it is done here to remove the inverted
- * part.
- */
- if (!gui_yank) {
- VIsual_active = false;
- setmouse();
- mouse_dragging = 0;
- may_clear_cmdline();
- if ((oap->op_type == OP_YANK
- || oap->op_type == OP_COLON
- || oap->op_type == OP_FUNCTION
- || oap->op_type == OP_FILTER)
- && oap->motion_force == NUL) {
- // Make sure redrawing is correct.
- curwin->w_p_lbr = lbr_saved;
- redraw_curbuf_later(INVERTED);
- }
- }
- }
-
- // Include the trailing byte of a multi-byte char.
- if (oap->inclusive) {
- const int l = utfc_ptr2len(ml_get_pos(&oap->end));
- if (l > 1) {
- oap->end.col += l - 1;
- }
- }
- curwin->w_set_curswant = true;
-
- /*
- * oap->empty is set when start and end are the same. The inclusive
- * flag affects this too, unless yanking and the end is on a NUL.
- */
- oap->empty = (oap->motion_type != kMTLineWise
- && (!oap->inclusive
- || (oap->op_type == OP_YANK
- && gchar_pos(&oap->end) == NUL))
- && equalpos(oap->start, oap->end)
- && !(virtual_op && oap->start.coladd != oap->end.coladd)
- );
- /*
- * For delete, change and yank, it's an error to operate on an
- * empty region, when 'E' included in 'cpoptions' (Vi compatible).
- */
- empty_region_error = (oap->empty
- && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL);
-
- /* Force a redraw when operating on an empty Visual region, when
- * 'modifiable is off or creating a fold. */
- if (oap->is_VIsual && (oap->empty || !MODIFIABLE(curbuf)
- || oap->op_type == OP_FOLD
- )) {
- curwin->w_p_lbr = lbr_saved;
- redraw_curbuf_later(INVERTED);
- }
-
- /*
- * If the end of an operator is in column one while oap->motion_type
- * is kMTCharWise and oap->inclusive is false, we put op_end after the last
- * character in the previous line. If op_start is on or before the
- * first non-blank in the line, the operator becomes linewise
- * (strange, but that's the way vi does it).
- */
- if (oap->motion_type == kMTCharWise
- && oap->inclusive == false
- && !(cap->retval & CA_NO_ADJ_OP_END)
- && oap->end.col == 0
- && (!oap->is_VIsual || *p_sel == 'o')
- && oap->line_count > 1) {
- oap->end_adjusted = true; // remember that we did this
- oap->line_count--;
- oap->end.lnum--;
- if (inindent(0)) {
- oap->motion_type = kMTLineWise;
- } else {
- oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
- if (oap->end.col) {
- --oap->end.col;
- oap->inclusive = true;
- }
- }
- } else {
- oap->end_adjusted = false;
- }
-
- switch (oap->op_type) {
- case OP_LSHIFT:
- case OP_RSHIFT:
- op_shift(oap, true,
- oap->is_VIsual ? (int)cap->count1 :
- 1);
- auto_format(false, true);
- break;
-
- case OP_JOIN_NS:
- case OP_JOIN:
- if (oap->line_count < 2) {
- oap->line_count = 2;
- }
- if (curwin->w_cursor.lnum + oap->line_count - 1 >
- curbuf->b_ml.ml_line_count) {
- beep_flush();
- } else {
- do_join((size_t)oap->line_count, oap->op_type == OP_JOIN,
- true, true, true);
- auto_format(false, true);
- }
- break;
-
- case OP_DELETE:
- VIsual_reselect = false; // don't reselect now
- if (empty_region_error) {
- vim_beep(BO_OPER);
- CancelRedo();
- } else {
- (void)op_delete(oap);
- // save cursor line for undo if it wasn't saved yet
- if (oap->motion_type == kMTLineWise
- && has_format_option(FO_AUTO)
- && u_save_cursor() == OK) {
- auto_format(false, true);
- }
- }
- break;
-
- case OP_YANK:
- if (empty_region_error) {
- if (!gui_yank) {
- vim_beep(BO_OPER);
- CancelRedo();
- }
- } else {
- curwin->w_p_lbr = lbr_saved;
- oap->excl_tr_ws = cap->cmdchar == 'z';
- (void)op_yank(oap, !gui_yank, false);
- }
- check_cursor_col();
- break;
-
- case OP_CHANGE:
- VIsual_reselect = false; // don't reselect now
- if (empty_region_error) {
- vim_beep(BO_OPER);
- CancelRedo();
- } else {
- /* This is a new edit command, not a restart. Need to
- * remember it to make 'insertmode' work with mappings for
- * Visual mode. But do this only once and not when typed and
- * 'insertmode' isn't set. */
- if (p_im || !KeyTyped) {
- restart_edit_save = restart_edit;
- } else {
- restart_edit_save = 0;
- }
- restart_edit = 0;
-
- // Restore linebreak, so that when the user edits it looks as before.
- curwin->w_p_lbr = lbr_saved;
-
- // Reset finish_op now, don't want it set inside edit().
- finish_op = false;
- if (op_change(oap)) { // will call edit()
- cap->retval |= CA_COMMAND_BUSY;
- }
- if (restart_edit == 0) {
- restart_edit = restart_edit_save;
- }
- }
- break;
-
- case OP_FILTER:
- if (vim_strchr(p_cpo, CPO_FILTER) != NULL) {
- AppendToRedobuff("!\r"); // Use any last used !cmd.
- } else {
- bangredo = true; // do_bang() will put cmd in redo buffer.
- }
- FALLTHROUGH;
-
- case OP_INDENT:
- case OP_COLON:
-
- /*
- * If 'equalprg' is empty, do the indenting internally.
- */
- if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) {
- if (curbuf->b_p_lisp) {
- op_reindent(oap, get_lisp_indent);
- break;
- }
- op_reindent(oap,
- *curbuf->b_p_inde != NUL ? get_expr_indent :
- get_c_indent);
- break;
- }
-
- op_colon(oap);
- break;
-
- case OP_TILDE:
- case OP_UPPER:
- case OP_LOWER:
- case OP_ROT13:
- if (empty_region_error) {
- vim_beep(BO_OPER);
- CancelRedo();
- } else {
- op_tilde(oap);
- }
- check_cursor_col();
- break;
-
- case OP_FORMAT:
- if (*curbuf->b_p_fex != NUL) {
- op_formatexpr(oap); // use expression
- } else {
- if (*p_fp != NUL || *curbuf->b_p_fp != NUL) {
- op_colon(oap); // use external command
- } else {
- op_format(oap, false); // use internal function
- }
- }
- break;
-
- case OP_FORMAT2:
- op_format(oap, true); // use internal function
- break;
-
- case OP_FUNCTION:
- // Restore linebreak, so that when the user edits it looks as
- // before.
- curwin->w_p_lbr = lbr_saved;
- op_function(oap); // call 'operatorfunc'
- break;
-
- case OP_INSERT:
- case OP_APPEND:
- VIsual_reselect = false; // don't reselect now
- if (empty_region_error) {
- vim_beep(BO_OPER);
- CancelRedo();
- } else {
- /* This is a new edit command, not a restart. Need to
- * remember it to make 'insertmode' work with mappings for
- * Visual mode. But do this only once. */
- restart_edit_save = restart_edit;
- restart_edit = 0;
-
- // Restore linebreak, so that when the user edits it looks as before.
- curwin->w_p_lbr = lbr_saved;
-
- op_insert(oap, cap->count1);
-
- // Reset linebreak, so that formatting works correctly.
- curwin->w_p_lbr = false;
-
- /* TODO: when inserting in several lines, should format all
- * the lines. */
- auto_format(false, true);
-
- if (restart_edit == 0) {
- restart_edit = restart_edit_save;
- } else {
- cap->retval |= CA_COMMAND_BUSY;
- }
- }
- break;
-
- case OP_REPLACE:
- VIsual_reselect = false; // don't reselect now
- if (empty_region_error) {
- vim_beep(BO_OPER);
- CancelRedo();
- } else {
- // Restore linebreak, so that when the user edits it looks as before.
- curwin->w_p_lbr = lbr_saved;
-
- op_replace(oap, cap->nchar);
- }
- break;
-
- case OP_FOLD:
- VIsual_reselect = false; // don't reselect now
- foldCreate(curwin, oap->start, oap->end);
- break;
-
- case OP_FOLDOPEN:
- case OP_FOLDOPENREC:
- case OP_FOLDCLOSE:
- case OP_FOLDCLOSEREC:
- VIsual_reselect = false; // don't reselect now
- opFoldRange(oap->start, oap->end,
- oap->op_type == OP_FOLDOPEN
- || oap->op_type == OP_FOLDOPENREC,
- oap->op_type == OP_FOLDOPENREC
- || oap->op_type == OP_FOLDCLOSEREC,
- oap->is_VIsual);
- break;
-
- case OP_FOLDDEL:
- case OP_FOLDDELREC:
- VIsual_reselect = false; // don't reselect now
- deleteFold(curwin, oap->start.lnum, oap->end.lnum,
- oap->op_type == OP_FOLDDELREC, oap->is_VIsual);
- break;
-
- case OP_NR_ADD:
- case OP_NR_SUB:
- if (empty_region_error) {
- vim_beep(BO_OPER);
- CancelRedo();
- } else {
- VIsual_active = true;
- curwin->w_p_lbr = lbr_saved;
- op_addsub(oap, cap->count1, redo_VIsual_arg);
- VIsual_active = false;
- }
- check_cursor_col();
- break;
- default:
- clearopbeep(oap);
- }
- virtual_op = kNone;
- if (!gui_yank) {
- /*
- * if 'sol' not set, go back to old column for some commands
- */
- if (!p_sol && oap->motion_type == kMTLineWise && !oap->end_adjusted
- && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
- || oap->op_type == OP_DELETE)) {
- curwin->w_p_lbr = false;
- coladvance(curwin->w_curswant = old_col);
- }
- } else {
- curwin->w_cursor = old_cursor;
- }
- clearop(oap);
- motion_force = NUL;
- }
- curwin->w_p_lbr = lbr_saved;
-}
-
-/*
- * Handle indent and format operators and visual mode ":".
- */
-static void op_colon(oparg_T *oap)
-{
- stuffcharReadbuff(':');
- if (oap->is_VIsual) {
- stuffReadbuff("'<,'>");
- } else {
- // Make the range look nice, so it can be repeated.
- if (oap->start.lnum == curwin->w_cursor.lnum) {
- stuffcharReadbuff('.');
- } else {
- stuffnumReadbuff((long)oap->start.lnum);
- }
- if (oap->end.lnum != oap->start.lnum) {
- stuffcharReadbuff(',');
- if (oap->end.lnum == curwin->w_cursor.lnum) {
- stuffcharReadbuff('.');
- } else if (oap->end.lnum == curbuf->b_ml.ml_line_count) {
- stuffcharReadbuff('$');
- } else if (oap->start.lnum == curwin->w_cursor.lnum) {
- stuffReadbuff(".+");
- stuffnumReadbuff(oap->line_count - 1);
- } else {
- stuffnumReadbuff((long)oap->end.lnum);
- }
- }
- }
- if (oap->op_type != OP_COLON) {
- stuffReadbuff("!");
- }
- if (oap->op_type == OP_INDENT) {
- stuffReadbuff((const char *)get_equalprg());
- stuffReadbuff("\n");
- } else if (oap->op_type == OP_FORMAT) {
- if (*curbuf->b_p_fp != NUL) {
- stuffReadbuff((const char *)curbuf->b_p_fp);
- } else if (*p_fp != NUL) {
- stuffReadbuff((const char *)p_fp);
- } else {
- stuffReadbuff("fmt");
- }
- stuffReadbuff("\n']");
- }
-
- /*
- * do_cmdline() does the rest
- */
-}
-
-/*
- * Handle the "g@" operator: call 'operatorfunc'.
- */
-static void op_function(const oparg_T *oap)
- FUNC_ATTR_NONNULL_ALL
-{
- const TriState save_virtual_op = virtual_op;
- const bool save_finish_op = finish_op;
-
- if (*p_opfunc == NUL) {
- emsg(_("E774: 'operatorfunc' is empty"));
- } else {
- // Set '[ and '] marks to text to be operated on.
- curbuf->b_op_start = oap->start;
- curbuf->b_op_end = oap->end;
- if (oap->motion_type != kMTLineWise && !oap->inclusive) {
- // Exclude the end position.
- decl(&curbuf->b_op_end);
- }
-
- typval_T argv[2];
- argv[0].v_type = VAR_STRING;
- argv[1].v_type = VAR_UNKNOWN;
- argv[0].vval.v_string =
- (char_u *)(((const char *const[]) {
- [kMTBlockWise] = "block",
- [kMTLineWise] = "line",
- [kMTCharWise] = "char",
- })[oap->motion_type]);
-
- // Reset virtual_op so that 'virtualedit' can be changed in the
- // function.
- virtual_op = kNone;
-
- // Reset finish_op so that mode() returns the right value.
- finish_op = false;
-
- (void)call_func_retnr(p_opfunc, 1, argv);
-
- virtual_op = save_virtual_op;
- finish_op = save_finish_op;
- }
-}
-
// Move the current tab to tab in same column as mouse or to end of the
// tabline if there is no tab there.
static void move_tab_to_mouse(void)
@@ -2286,9 +1517,12 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
for (;;) {
which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag);
if (is_drag) {
- /* If the next character is the same mouse event then use that
- * one. Speeds up dragging the status line. */
- if (vpeekc() != NUL) {
+ // If the next character is the same mouse event then use that
+ // one. Speeds up dragging the status line.
+ // Note: Since characters added to the stuff buffer in the code
+ // below need to come before the next character, do not do this
+ // when the current character was stuffed.
+ if (!KeyStuffed && vpeekc() != NUL) {
int nc;
int save_mouse_grid = mouse_grid;
int save_mouse_row = mouse_row;
@@ -2855,10 +2089,9 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
} else { // MOUSE_RIGHT
stuffcharReadbuff('#');
}
- }
- // Handle double clicks, unless on status line
- else if (in_status_line) {
- } else if (in_sep_line) {
+ } else if (in_status_line || in_sep_line) {
+ // Do nothing if on status line or vertical separator
+ // Handle double clicks otherwise
} else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))) {
if (is_click || !VIsual_active) {
if (VIsual_active) {
@@ -3066,6 +2299,7 @@ void end_visual_mode(void)
may_clear_cmdline();
adjust_cursor_eol();
+ may_trigger_modechanged();
}
/*
@@ -3092,6 +2326,14 @@ void reset_VIsual(void)
}
}
+void restore_visual_mode(void)
+{
+ if (VIsual_mode_orig != NUL) {
+ curbuf->b_visual.vi_mode = VIsual_mode_orig;
+ VIsual_mode_orig = NUL;
+ }
+}
+
// Check for a balloon-eval special item to include when searching for an
// identifier. When "dir" is BACKWARD "ptr[-1]" must be valid!
// Returns true if the character at "*ptr" should be included.
@@ -3270,7 +2512,7 @@ static void prep_redo_cmd(cmdarg_T *cap)
* Prepare for redo of any command.
* Note that only the last argument can be a multi-byte char.
*/
-static void prep_redo(int regname, long num, int cmd1, int cmd2, int cmd3, int cmd4, int cmd5)
+void prep_redo(int regname, long num, int cmd1, int cmd2, int cmd3, int cmd4, int cmd5)
{
ResetRedobuff();
if (regname != 0) { // yank from specified buffer
@@ -3327,7 +2569,7 @@ static bool checkclearopq(oparg_T *oap)
return true;
}
-static void clearop(oparg_T *oap)
+void clearop(oparg_T *oap)
{
oap->op_type = OP_NOP;
oap->regname = 0;
@@ -3336,7 +2578,7 @@ static void clearop(oparg_T *oap)
motion_force = NUL;
}
-static void clearopbeep(oparg_T *oap)
+void clearopbeep(oparg_T *oap)
{
clearop(oap);
beep_flush();
@@ -3366,7 +2608,7 @@ static void unshift_special(cmdarg_T *cap)
/// If the mode is currently displayed clear the command line or update the
/// command displayed.
-static void may_clear_cmdline(void)
+void may_clear_cmdline(void)
{
if (mode_displayed) {
// unshow visual mode later
@@ -3377,7 +2619,7 @@ static void may_clear_cmdline(void)
}
// Routines for displaying a partly typed command
-#define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30
+#define SHOWCMD_BUFLEN (SHOWCMD_COLS + 1 + 30)
static char_u showcmd_buf[SHOWCMD_BUFLEN];
static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; // For push_showcmd()
static bool showcmd_is_clear = true;
@@ -3836,8 +3078,14 @@ static void nv_gd(oparg_T *oap, int nchar, int thisblock)
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0
|| !find_decl(ptr, len, nchar == 'd', thisblock, SEARCH_START)) {
clearopbeep(oap);
- } else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) {
- foldOpenCursor();
+ } else {
+ if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) {
+ foldOpenCursor();
+ }
+ // clear any search statistics
+ if (messaging() && !msg_silent && !shortmess(SHM_SEARCHCOUNT)) {
+ clear_cmdline = true;
+ }
}
}
@@ -4027,7 +3275,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
int col_off1; // margin offset for first screen line
int col_off2; // margin offset for wrapped screen line
int width1; // text width for first screen line
- int width2; // test width for wrapped screen line
+ int width2; // text width for wrapped screen line
oap->motion_type = kMTCharWise;
oap->inclusive = (curwin->w_curswant == MAXCOL);
@@ -4151,6 +3399,13 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
virtcol -= vim_strsize(get_showbreak_value(curwin));
}
+ int c = utf_ptr2char(get_cursor_pos_ptr());
+ if (dir == FORWARD && virtcol < curwin->w_curswant
+ && (curwin->w_curswant <= (colnr_T)width1)
+ && !vim_isprintc(c) && c > 255) {
+ oneright();
+ }
+
if (virtcol > curwin->w_curswant
&& (curwin->w_curswant < (colnr_T)width1
? (curwin->w_curswant > (colnr_T)width1 / 2)
@@ -4297,7 +3552,6 @@ static void nv_zet(cmdarg_T *cap)
bool undo = false;
int l_p_siso = (int)get_sidescrolloff_value(curwin);
- assert(l_p_siso <= INT_MAX);
if (ascii_isdigit(nchar)) {
/*
@@ -4775,33 +4029,37 @@ dozet:
/*
* "Q" command.
*/
-static void nv_exmode(cmdarg_T *cap)
+static void nv_regreplay(cmdarg_T *cap)
{
- /*
- * Ignore 'Q' in Visual mode, just give a beep.
- */
- if (VIsual_active) {
- vim_beep(BO_EX);
- } else if (!checkclearop(cap->oap)) {
- do_exmode();
+ if (checkclearop(cap->oap)) {
+ return;
+ }
+
+ while (cap->count1-- && !got_int) {
+ if (do_execreg(reg_recorded, false, false, false) == false) {
+ clearopbeep(cap->oap);
+ break;
+ }
+ line_breakcheck();
}
}
-/// Handle a ":" command and <Cmd>.
+/// Handle a ":" command and <Cmd> or Lua keymaps.
static void nv_colon(cmdarg_T *cap)
{
int old_p_im;
bool cmd_result;
bool is_cmdkey = cap->cmdchar == K_COMMAND;
+ bool is_lua = cap->cmdchar == K_LUA;
- if (VIsual_active && !is_cmdkey) {
+ if (VIsual_active && !is_cmdkey && !is_lua) {
nv_operator(cap);
} else {
if (cap->oap->op_type != OP_NOP) {
// Using ":" as a movement is charwise exclusive.
cap->oap->motion_type = kMTCharWise;
cap->oap->inclusive = false;
- } else if (cap->count0 && !is_cmdkey) {
+ } else if (cap->count0 && !is_cmdkey && !is_lua) {
// translate "count:" into ":.,.+(count - 1)"
stuffcharReadbuff('.');
if (cap->count0 > 1) {
@@ -4817,9 +4075,13 @@ static void nv_colon(cmdarg_T *cap)
old_p_im = p_im;
- // get a command line and execute it
- cmd_result = do_cmdline(NULL, is_cmdkey ? getcmdkeycmd : getexline, NULL,
- cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0);
+ if (is_lua) {
+ cmd_result = map_execute_lua();
+ } else {
+ // get a command line and execute it
+ cmd_result = do_cmdline(NULL, is_cmdkey ? getcmdkeycmd : getexline, NULL,
+ cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0);
+ }
// If 'insertmode' changed, enter or exit Insert mode
if (p_im != old_p_im) {
@@ -4851,6 +4113,7 @@ static void nv_ctrlg(cmdarg_T *cap)
{
if (VIsual_active) { // toggle Selection/Visual mode
VIsual_select = !VIsual_select;
+ may_trigger_modechanged();
showmode();
} else if (!checkclearop(cap->oap)) {
// print full name if count given or :cd used
@@ -4894,6 +4157,7 @@ static void nv_ctrlo(cmdarg_T *cap)
{
if (VIsual_active && VIsual_select) {
VIsual_select = false;
+ may_trigger_modechanged();
showmode();
restart_VIsual_select = 2; // restart Select mode later
} else {
@@ -5173,11 +4437,7 @@ static void nv_ident(cmdarg_T *cap)
// Start insert mode in terminal buffer
restart_edit = 'i';
- add_map((char_u *)"<buffer> <esc> <Cmd>call jobstop(&channel)<CR>", TERM_FOCUS, true);
- do_cmdline_cmd("autocmd TermClose <buffer> "
- " if !v:event.status |"
- " exec 'bdelete! ' .. expand('<abuf>') |"
- " endif");
+ add_map((char_u *)"<buffer> <esc> <Cmd>bdelete!<CR>", TERM_FOCUS, true);
}
}
@@ -5212,8 +4472,13 @@ bool get_visual_text(cmdarg_T *cap, char_u **pp, size_t *lenp)
*pp = ml_get_pos(&VIsual);
*lenp = (size_t)curwin->w_cursor.col - (size_t)VIsual.col + 1;
}
- // Correct the length to include the whole last character.
- *lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1);
+ if (**pp == NUL) {
+ *lenp = 0;
+ }
+ if (*lenp > 0) {
+ // Correct the length to include all bytes of the last character.
+ *lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1);
+ }
}
reset_VIsual_and_resel();
return true;
@@ -5747,9 +5012,7 @@ static void nv_brackets(cmdarg_T *cap)
* identifier "]i" "[i" "]I" "[I" "]^I" "[^I"
* define "]d" "[d" "]D" "[D" "]^D" "[^D"
*/
- if (vim_strchr((char_u *)
- "iI\011dD\004",
- cap->nchar) != NULL) {
+ if (vim_strchr((char_u *)"iI\011dD\004", cap->nchar) != NULL) {
char_u *ptr;
size_t len;
@@ -6590,7 +5853,7 @@ static void nv_gomark(cmdarg_T *cap)
}
}
-// Handle CTRL-O, CTRL-I, "g;", "g,", and "CTRL-Tab" commands.
+/// Handle CTRL-O, CTRL-I, "g;", "g,", and "CTRL-Tab" commands.
static void nv_pcmark(cmdarg_T *cap)
{
pos_T *pos;
@@ -6599,7 +5862,9 @@ static void nv_pcmark(cmdarg_T *cap)
if (!checkclearopq(cap->oap)) {
if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL) {
- goto_tabpage_lastused();
+ if (!goto_tabpage_lastused()) {
+ clearopbeep(cap->oap);
+ }
return;
}
if (cap->cmdchar == 'g') {
@@ -6680,6 +5945,7 @@ static void nv_visual(cmdarg_T *cap)
// or char/line mode
VIsual_mode = cap->cmdchar;
showmode();
+ may_trigger_modechanged();
}
redraw_curbuf_later(INVERTED); // update the inversion
} else { // start Visual mode
@@ -6702,11 +5968,8 @@ static void nv_visual(cmdarg_T *cap)
* was only one -- webb
*/
if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) {
- curwin->w_cursor.lnum +=
- resel_VIsual_line_count * cap->count0 - 1;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
- curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- }
+ curwin->w_cursor.lnum += resel_VIsual_line_count * cap->count0 - 1;
+ check_cursor();
}
VIsual_mode = resel_VIsual_mode;
if (VIsual_mode == 'v') {
@@ -6785,7 +6048,7 @@ static void n_start_visual_mode(int c)
// Corner case: the 0 position in a tab may change when going into
// virtualedit. Recalculate curwin->w_cursor to avoid bad highlighting.
//
- if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) {
+ if (c == Ctrl_V && (get_ve_flags() & VE_BLOCK) && gchar_cursor() == TAB) {
validate_virtcol();
coladvance(curwin->w_virtcol);
}
@@ -6793,6 +6056,7 @@ static void n_start_visual_mode(int c)
foldAdjustVisual();
+ may_trigger_modechanged();
setmouse();
// Check for redraw after changing the state.
conceal_check_cursor_line();
@@ -6924,6 +6188,7 @@ static void nv_g_cmd(cmdarg_T *cap)
// start Select mode.
if (cap->arg) {
VIsual_select = true;
+ VIsual_select_reg = 0;
} else {
may_start_select('c');
}
@@ -7050,20 +6315,17 @@ static void nv_g_cmd(cmdarg_T *cap)
curwin->w_set_curswant = true;
break;
- case 'M': {
- const char_u *const ptr = get_cursor_line_ptr();
-
+ case 'M':
oap->motion_type = kMTCharWise;
oap->inclusive = false;
- i = (int)mb_string2cells_len(ptr, STRLEN(ptr));
+ i = linetabsize(get_cursor_line_ptr());
if (cap->count0 > 0 && cap->count0 <= 100) {
coladvance((colnr_T)(i * cap->count0 / 100));
} else {
coladvance((colnr_T)(i / 2));
}
curwin->w_set_curswant = true;
- }
- break;
+ break;
case '_':
/* "g_": to the last non-blank character in the line or <count> lines
@@ -7366,9 +6628,10 @@ static void nv_g_cmd(cmdarg_T *cap)
goto_tabpage(-(int)cap->count1);
}
break;
+
case TAB:
- if (!checkclearop(oap)) {
- goto_tabpage_lastused();
+ if (!checkclearop(oap) && !goto_tabpage_lastused()) {
+ clearopbeep(oap);
}
break;
@@ -7407,9 +6670,8 @@ static void n_opencmd(cmdarg_T *cap)
(cap->cmdchar == 'o' ? 1 : 0))
)
&& open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
- has_format_option(FO_OPEN_COMS)
- ? OPENLINE_DO_COM : 0,
- 0)) {
+ has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : 0,
+ 0, NULL)) {
if (win_cursorline_standout(curwin)) {
// force redraw of cursorline
curwin->w_valid &= ~VALID_CROW;
@@ -7436,11 +6698,26 @@ static void nv_dot(cmdarg_T *cap)
}
}
-/*
- * CTRL-R: undo undo
- */
-static void nv_redo(cmdarg_T *cap)
+// CTRL-R: undo undo or specify register in select mode
+static void nv_redo_or_register(cmdarg_T *cap)
{
+ if (VIsual_select && VIsual_active) {
+ int reg;
+ // Get register name
+ no_mapping++;
+ reg = plain_vgetc();
+ LANGMAP_ADJUST(reg, true);
+ no_mapping--;
+
+ if (reg == '"') {
+ // the unnamed register is 0
+ reg = 0;
+ }
+
+ VIsual_select_reg = valid_yank_reg(reg, true) ? reg : 0;
+ return;
+ }
+
if (!checkclearopq(cap->oap)) {
u_redo((int)cap->count1);
curwin->w_set_curswant = true;
@@ -7689,7 +6966,7 @@ static void adjust_cursor(oparg_T *oap)
if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL
&& (!VIsual_active || *p_sel == 'o')
&& !virtual_active()
- && (ve_flags & VE_ONEMORE) == 0) {
+ && (get_ve_flags() & VE_ONEMORE) == 0) {
curwin->w_cursor.col--;
// prevent cursor from moving on the trail byte
mb_adjust_cursor();
@@ -7730,7 +7007,7 @@ static void adjust_for_sel(cmdarg_T *cap)
* Should check VIsual_mode before calling this.
* Returns true when backed up to the previous line.
*/
-static bool unadjust_for_sel(void)
+bool unadjust_for_sel(void)
{
pos_T *pp;
@@ -7761,6 +7038,7 @@ static void nv_select(cmdarg_T *cap)
{
if (VIsual_active) {
VIsual_select = true;
+ VIsual_select_reg = 0;
} else if (VIsual_reselect) {
cap->nchar = 'v'; // fake "gv" command
cap->arg = true;
@@ -7895,7 +7173,7 @@ static void nv_esc(cmdarg_T *cap)
void set_cursor_for_append_to_line(void)
{
curwin->w_set_curswant = true;
- if (ve_flags == VE_ALL) {
+ if (get_ve_flags() == VE_ALL) {
const int save_State = State;
// Pretend Insert mode here to allow the cursor on the
@@ -8213,9 +7491,9 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
// overwrites if the old contents is being put.
was_visual = true;
regname = cap->oap->regname;
+ bool save_unnamed = cap->cmdchar == 'P';
// '+' and '*' could be the same selection
- bool clipoverwrite = (regname == '+' || regname == '*')
- && (cb_flags & CB_UNNAMEDMASK);
+ bool clipoverwrite = (regname == '+' || regname == '*') && (cb_flags & CB_UNNAMEDMASK);
if (regname == 0 || regname == '"' || clipoverwrite
|| ascii_isdigit(regname) || regname == '-') {
// The delete might overwrite the register we want to put, save it first
@@ -8228,6 +7506,10 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
// do_put(), which requires the visual selection to still be active.
if (!VIsual_active || VIsual_mode == 'V' || regname != '.') {
// Now delete the selected text. Avoid messages here.
+ yankreg_T *old_y_previous;
+ if (save_unnamed) {
+ old_y_previous = get_y_previous();
+ }
cap->cmdchar = 'd';
cap->nchar = NUL;
cap->oap->regname = NUL;
@@ -8237,6 +7519,10 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
msg_silent--;
+ if (save_unnamed) {
+ set_y_previous(old_y_previous);
+ }
+
// delete PUT_LINE_BACKWARD;
cap->oap->regname = regname;
}
@@ -8320,71 +7606,6 @@ static void nv_open(cmdarg_T *cap)
}
}
-/// Calculate start/end virtual columns for operating in block mode.
-///
-/// @param initial when true: adjust position for 'selectmode'
-static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial)
-{
- colnr_T start;
- colnr_T end;
-
- if (VIsual_mode != Ctrl_V
- || (!initial && oap->end.col < curwin->w_width_inner)) {
- return;
- }
-
- oap->motion_type = kMTBlockWise;
-
- // prevent from moving onto a trail byte
- mark_mb_adjustpos(curwin->w_buffer, &oap->end);
-
- getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol);
- if (!redo_VIsual_busy) {
- getvvcol(curwin, &(oap->end), &start, NULL, &end);
-
- if (start < oap->start_vcol) {
- oap->start_vcol = start;
- }
- if (end > oap->end_vcol) {
- if (initial && *p_sel == 'e'
- && start >= 1
- && start - 1 >= oap->end_vcol) {
- oap->end_vcol = start - 1;
- } else {
- oap->end_vcol = end;
- }
- }
- }
-
- // if '$' was used, get oap->end_vcol from longest line
- if (curwin->w_curswant == MAXCOL) {
- curwin->w_cursor.col = MAXCOL;
- oap->end_vcol = 0;
- for (curwin->w_cursor.lnum = oap->start.lnum;
- curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) {
- getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end);
- if (end > oap->end_vcol) {
- oap->end_vcol = end;
- }
- }
- } else if (redo_VIsual_busy) {
- oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1;
- }
-
- // Correct oap->end.col and oap->start.col to be the
- // upper-left and lower-right corner of the block area.
- //
- // (Actually, this does convert column positions into character
- // positions)
- curwin->w_cursor.lnum = oap->end.lnum;
- coladvance(oap->end_vcol);
- oap->end = curwin->w_cursor;
-
- curwin->w_cursor = oap->start;
- coladvance(oap->start_vcol);
- oap->start = curwin->w_cursor;
-}
-
// Handle an arbitrary event in normal mode
static void nv_event(cmdarg_T *cap)
{