@@ -1650,7 +1650,9 @@ op_delete(oap)
16501650 && oap -> line_count > 1
16511651 && oap -> op_type == OP_DELETE )
16521652 {
1653- ptr = ml_get (oap -> end .lnum ) + oap -> end .col + oap -> inclusive ;
1653+ ptr = ml_get (oap -> end .lnum ) + oap -> end .col ;
1654+ if (* ptr != NUL )
1655+ ptr += oap -> inclusive ;
16541656 ptr = skipwhite (ptr );
16551657 if (* ptr == NUL && inindent (0 ))
16561658 oap -> motion_type = MLINE ;
@@ -1920,11 +1922,20 @@ op_delete(oap)
19201922 curwin -> w_cursor .coladd = 0 ;
19211923 }
19221924#endif
1923- (void )del_bytes ((long )n , !virtual_op , oap -> op_type == OP_DELETE
1925+ if (oap -> inclusive && oap -> end .lnum == curbuf -> b_ml .ml_line_count
1926+ && n > (int )STRLEN (ml_get (oap -> end .lnum )))
1927+ {
1928+ /* Special case: gH<Del> deletes the last line. */
1929+ del_lines (1L , FALSE);
1930+ }
1931+ else
1932+ {
1933+ (void )del_bytes ((long )n , !virtual_op , oap -> op_type == OP_DELETE
19241934#ifdef FEAT_VISUAL
19251935 && !oap -> is_VIsual
19261936#endif
19271937 );
1938+ }
19281939 }
19291940 else /* delete characters between lines */
19301941 {
@@ -1941,17 +1952,29 @@ op_delete(oap)
19411952 ++ curwin -> w_cursor .lnum ;
19421953 del_lines ((long )(oap -> line_count - 2 ), FALSE);
19431954
1944- /* delete from start of line until op_end */
1945- curwin -> w_cursor .col = 0 ;
1946- (void )del_bytes ((long )(oap -> end .col + 1 - !oap -> inclusive ),
1947- !virtual_op , oap -> op_type == OP_DELETE
1955+ n = (oap -> end .col + 1 - !oap -> inclusive );
1956+ if (oap -> inclusive && oap -> end .lnum == curbuf -> b_ml .ml_line_count
1957+ && n > (int )STRLEN (ml_get (oap -> end .lnum )))
1958+ {
1959+ /* Special case: gH<Del> deletes the last line. */
1960+ del_lines (1L , FALSE);
1961+ curwin -> w_cursor = curpos ; /* restore curwin->w_cursor */
1962+ if (curwin -> w_cursor .lnum > 1 )
1963+ -- curwin -> w_cursor .lnum ;
1964+ }
1965+ else
1966+ {
1967+ /* delete from start of line until op_end */
1968+ curwin -> w_cursor .col = 0 ;
1969+ (void )del_bytes ((long )n , !virtual_op , oap -> op_type == OP_DELETE
19481970#ifdef FEAT_VISUAL
19491971 && !oap -> is_VIsual
19501972#endif
19511973 );
1952- curwin -> w_cursor = curpos ; /* restore curwin->w_cursor */
1953-
1954- (void )do_join (2 , FALSE, FALSE);
1974+ curwin -> w_cursor = curpos ; /* restore curwin->w_cursor */
1975+ }
1976+ if (curwin -> w_cursor .lnum < curbuf -> b_ml .ml_line_count )
1977+ (void )do_join (2 , FALSE, FALSE);
19551978 }
19561979 }
19571980
0 commit comments