aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c9
-rw-r--r--src/nvim/ex_cmds.c2
-rw-r--r--src/nvim/ex_cmds.lua2
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/indent.c1
-rw-r--r--src/nvim/testdir/test_cmdline.vim4
-rw-r--r--src/nvim/testdir/test_ex_z.vim36
-rw-r--r--src/nvim/testdir/test_modeline.vim10
-rw-r--r--src/nvim/testdir/test_textobjects.vim277
9 files changed, 239 insertions, 104 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 81f8b9073e..55db72aa16 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -5261,15 +5261,16 @@ void do_modelines(int flags)
}
entered++;
- for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count && lnum <= nmlines;
- lnum++) {
+ for (lnum = 1; curbuf->b_p_ml && lnum <= curbuf->b_ml.ml_line_count
+ && lnum <= nmlines; lnum++) {
if (chk_modeline(lnum, flags) == FAIL) {
nmlines = 0;
}
}
- for (lnum = curbuf->b_ml.ml_line_count; lnum > 0 && lnum > nmlines
- && lnum > curbuf->b_ml.ml_line_count - nmlines; lnum--) {
+ for (lnum = curbuf->b_ml.ml_line_count; curbuf->b_p_ml && lnum > 0
+ && lnum > nmlines && lnum > curbuf->b_ml.ml_line_count - nmlines;
+ lnum--) {
if (chk_modeline(lnum, flags) == FAIL) {
nmlines = 0;
}
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 5485355885..f8186c000e 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -3088,7 +3088,7 @@ void ex_z(exarg_T *eap)
// Vi compatible: ":z!" uses display height, without a count uses
// 'scroll'
if (eap->forceit) {
- bigness = curwin->w_height_inner;
+ bigness = Rows - 1;
} else if (ONE_WINDOW) {
bigness = curwin->w_p_scr * 2;
} else {
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 7b971f464f..c388373ac1 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -3271,7 +3271,7 @@ module.cmds = {
},
{
command='z',
- flags=bit.bor(RANGE, WHOLEFOLD, EXTRA, FLAGS, TRLBAR, CMDWIN),
+ flags=bit.bor(RANGE, WHOLEFOLD, BANG, EXTRA, FLAGS, TRLBAR, CMDWIN),
addr_type='ADDR_LINES',
func='ex_z',
},
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 2a0d365548..67b0c21fc5 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -3230,7 +3230,7 @@ const char * set_one_cmd_context(expand_T *xp, const char *buff)
}
}
}
- // Check for user names
+ // Check for user names.
if (*xp->xp_pattern == '~') {
for (p = (const char *)xp->xp_pattern + 1; *p != NUL && *p != '/'; p++) {
}
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index a6df0e97e6..609598b678 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -474,6 +474,7 @@ int get_breakindent_win(win_T *wp, char_u *line)
};
if (regmatch.regprog != NULL) {
+ regmatch.rm_ic = false;
if (vim_regexec(&regmatch, line, 0)) {
if (wp->w_briopt_list > 0) {
bri += wp->w_briopt_list;
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index 34126b49fa..8e2a145343 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -7,6 +7,10 @@ func Test_complete_tab()
call writefile(['testfile'], 'Xtestfile')
call feedkeys(":e Xtestf\t\r", "tx")
call assert_equal('testfile', getline(1))
+
+ " Pressing <Tab> after '%' completes the current file, also on MS-Windows
+ call feedkeys(":e %\t\r", "tx")
+ call assert_equal('e Xtestfile', @:)
call delete('Xtestfile')
endfunc
diff --git a/src/nvim/testdir/test_ex_z.vim b/src/nvim/testdir/test_ex_z.vim
index 608a36c490..481747ce84 100644
--- a/src/nvim/testdir/test_ex_z.vim
+++ b/src/nvim/testdir/test_ex_z.vim
@@ -16,8 +16,9 @@ func Test_z()
call assert_equal(23, line('.'))
let a = execute('20z+3')
- " FIXME: I would expect the same result as '20z3' but it
- " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"?
+ " FIXME: I would expect the same result as '20z3' since 'help z'
+ " says: Specifying no mark at all is the same as "+".
+ " However it " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"?
"call assert_equal("\n20\n21\n22", a)
"call assert_equal(22, line('.'))
@@ -55,19 +56,48 @@ func Test_z()
call assert_equal(100, line('.'))
let a = execute('20z-1000')
- call assert_match("^\n1\n2\n.*\n19\n20$", a)
call assert_equal(20, line('.'))
let a = execute('20z=1000')
call assert_match("^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$", a)
call assert_equal(20, line('.'))
+ " Tests with multiple windows.
+ 5split
+ call setline(1, range(1, 100))
+ " Without a count, the number line is window height - 3.
+ let a = execute('20z')
+ call assert_equal("\n20\n21", a)
+ call assert_equal(21, line('.'))
+ " If window height - 3 is less than 1, it should be clamped to 1.
+ resize 2
+ let a = execute('20z')
+ call assert_equal("\n20", a)
+ call assert_equal(20, line('.'))
+
call assert_fails('20z=a', 'E144:')
set window& scroll&
bw!
endfunc
+" :z! is the same as :z but count uses the Vim window height when not specified.
+func Test_z_bang()
+ 4split
+ call setline(1, range(1, 20))
+
+ let a = execute('10z!')
+ call assert_equal("\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20", a)
+
+ let a = execute('10z!#')
+ call assert_equal("\n 10 10\n 11 11\n 12 12\n 13 13\n 14 14\n 15 15\n 16 16\n 17 17\n 18 18\n 19 19\n 20 20", a)
+
+ let a = execute('10z!3')
+ call assert_equal("\n10\n11\n12", a)
+
+ %bwipe!
+endfunc
+
func Test_z_bug()
" This used to access invalid memory as a result of an integer overflow
" and freeze vim.
diff --git a/src/nvim/testdir/test_modeline.vim b/src/nvim/testdir/test_modeline.vim
index 9bdada616c..b3fe79f545 100644
--- a/src/nvim/testdir/test_modeline.vim
+++ b/src/nvim/testdir/test_modeline.vim
@@ -280,3 +280,13 @@ func Test_modeline_fails_modelineexpr()
call s:modeline_fails('tabline', 'tabline=Something()', 'E992:')
call s:modeline_fails('titlestring', 'titlestring=Something()', 'E992:')
endfunc
+
+func Test_modeline_disable()
+ set modeline
+ call writefile(['vim: sw=2', 'vim: nomodeline', 'vim: sw=3'], 'Xmodeline_disable')
+ edit Xmodeline_disable
+ call assert_equal(2, &sw)
+ call delete('Xmodeline_disable')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_textobjects.vim b/src/nvim/testdir/test_textobjects.vim
index 9b800d0fa9..c259453b5e 100644
--- a/src/nvim/testdir/test_textobjects.vim
+++ b/src/nvim/testdir/test_textobjects.vim
@@ -89,101 +89,109 @@ endfunc
" Tests for string and html text objects
func Test_string_html_objects()
- enew!
- let t = '"wo\"rd\\" foo'
- put =t
- normal! da"
- call assert_equal('foo', getline('.'))
-
- let t = "'foo' 'bar' 'piep'"
- put =t
- normal! 0va'a'rx
- call assert_equal("xxxxxxxxxxxx'piep'", getline('.'))
-
- let t = "bla bla `quote` blah"
- put =t
- normal! 02f`da`
- call assert_equal("bla bla blah", getline('.'))
-
- let t = 'out " in "noXno"'
- put =t
- normal! 0fXdi"
- call assert_equal('out " in ""', getline('.'))
-
- let t = "\"'\" 'blah' rep 'buh'"
- put =t
- normal! 03f'vi'ry
- call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'))
-
- set quoteescape=+*-
- let t = "bla `s*`d-`+++`l**` b`la"
- put =t
- normal! di`
- call assert_equal("bla `` b`la", getline('.'))
-
- let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
- put =t
- normal! $F"va"oha"i"rz
- call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'))
-
- let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
- put =t
- normal! fXdit
- call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'))
-
- let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
- put =t
- normal! 0fXdit
- call assert_equal('-<b></b>-', getline('.'))
-
- let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
- put =t
- normal! fXdat
- call assert_equal('-<b>asdfasdf</b>-', getline('.'))
-
- let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
- put =t
- normal! 0fXdat
- call assert_equal('--', getline('.'))
-
- let t = "-<b>\ninnertext object\n</b>"
- put =t
- normal! dit
- call assert_equal('-<b></b>', getline('.'))
-
- " copy the tag block from leading indentation before the start tag
- let t = " <b>\ntext\n</b>"
- $put =t
- normal! 2kvaty
- call assert_equal("<b>\ntext\n</b>", @")
-
- " copy the tag block from the end tag
- let t = "<title>\nwelcome\n</title>"
- $put =t
- normal! $vaty
- call assert_equal("<title>\nwelcome\n</title>", @")
-
- " copy the outer tag block from a tag without an end tag
- let t = "<html>\n<title>welcome\n</html>"
- $put =t
- normal! k$vaty
- call assert_equal("<html>\n<title>welcome\n</html>", @")
-
- " nested tag that has < in a different line from >
- let t = "<div><div\n></div></div>"
- $put =t
- normal! k0vaty
- call assert_equal("<div><div\n></div></div>", @")
-
- " nested tag with attribute that has < in a different line from >
- let t = "<div><div\nattr=\"attr\"\n></div></div>"
- $put =t
- normal! 2k0vaty
- call assert_equal("<div><div\nattr=\"attr\"\n></div></div>", @")
-
- set quoteescape&
- enew!
+ " Nvim only supports set encoding=utf-8
+ " for e in ['utf-8', 'latin1', 'cp932']
+ for e in ['utf-8']
+ enew!
+ exe 'set enc=' .. e
+
+ let t = '"wo\"rd\\" foo'
+ put =t
+ normal! da"
+ call assert_equal('foo', getline('.'), e)
+
+ let t = "'foo' 'bar' 'piep'"
+ put =t
+ normal! 0va'a'rx
+ call assert_equal("xxxxxxxxxxxx'piep'", getline('.'), e)
+
+ let t = "bla bla `quote` blah"
+ put =t
+ normal! 02f`da`
+ call assert_equal("bla bla blah", getline('.'), e)
+
+ let t = 'out " in "noXno"'
+ put =t
+ normal! 0fXdi"
+ call assert_equal('out " in ""', getline('.'), e)
+
+ let t = "\"'\" 'blah' rep 'buh'"
+ put =t
+ normal! 03f'vi'ry
+ call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'), e)
+
+ set quoteescape=+*-
+ let t = "bla `s*`d-`+++`l**` b`la"
+ put =t
+ normal! di`
+ call assert_equal("bla `` b`la", getline('.'), e)
+
+ let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
+ put =t
+ normal! $F"va"oha"i"rz
+ call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'), e)
+
+ let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
+ put =t
+ normal! fXdit
+ call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'), e)
+
+ let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
+ put =t
+ normal! 0fXdit
+ call assert_equal('-<b></b>-', getline('.'), e)
+
+ let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
+ put =t
+ normal! fXdat
+ call assert_equal('-<b>asdfasdf</b>-', getline('.'), e)
+
+ let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
+ put =t
+ normal! 0fXdat
+ call assert_equal('--', getline('.'), e)
+
+ let t = "-<b>\ninnertext object\n</b>"
+ put =t
+ normal! dit
+ call assert_equal('-<b></b>', getline('.'), e)
+
+ " copy the tag block from leading indentation before the start tag
+ let t = " <b>\ntext\n</b>"
+ $put =t
+ normal! 2kvaty
+ call assert_equal("<b>\ntext\n</b>", @", e)
+
+ " copy the tag block from the end tag
+ let t = "<title>\nwelcome\n</title>"
+ $put =t
+ normal! $vaty
+ call assert_equal("<title>\nwelcome\n</title>", @", e)
+
+ " copy the outer tag block from a tag without an end tag
+ let t = "<html>\n<title>welcome\n</html>"
+ $put =t
+ normal! k$vaty
+ call assert_equal("<html>\n<title>welcome\n</html>", @", e)
+
+ " nested tag that has < in a different line from >
+ let t = "<div><div\n></div></div>"
+ $put =t
+ normal! k0vaty
+ call assert_equal("<div><div\n></div></div>", @", e)
+
+ " nested tag with attribute that has < in a different line from >
+ let t = "<div><div\nattr=\"attr\"\n></div></div>"
+ $put =t
+ normal! 2k0vaty
+ call assert_equal("<div><div\nattr=\"attr\"\n></div></div>", @", e)
+
+ set quoteescape&
+ endfor
+
+ set enc=utf-8
+ bwipe!
endfunc
func Test_empty_html_tag()
@@ -333,3 +341,84 @@ func Test_sentence_with_cursor_on_delimiter()
%delete _
endfunc
+
+" Test for quote (', " and `) textobjects
+func Test_textobj_quote()
+ new
+
+ " Test for i" when cursor is in front of a quoted object
+ call append(0, 'foo "bar"')
+ norm! 1gg0di"
+ call assert_equal(['foo ""', ''], getline(1,'$'))
+
+ " Test for visually selecting an inner quote
+ %d
+ " extend visual selection from one quote to the next
+ call setline(1, 'color "red" color "blue"')
+ call cursor(1, 7)
+ normal v4li"y
+ call assert_equal('"red" color "blue', @")
+
+ " try to extend visual selection from one quote to a non-existing quote
+ call setline(1, 'color "red" color blue')
+ call cursor(1, 7)
+ call feedkeys('v4li"y', 'xt')
+ call assert_equal('"red"', @")
+
+ " try to extend visual selection from one quote to a next partial quote
+ call setline(1, 'color "red" color "blue')
+ call cursor(1, 7)
+ normal v4li"y
+ call assert_equal('"red" color ', @")
+
+ " select a quote backwards in visual mode
+ call cursor(1, 12)
+ normal vhi"y
+ call assert_equal('red" ', @")
+ call assert_equal(8, col('.'))
+
+ " select a quote backwards in visual mode from outside the quote
+ call cursor(1, 17)
+ normal v2hi"y
+ call assert_equal('red', @")
+ call assert_equal(8, col('.'))
+
+ " visually selecting a quote with 'selection' set to 'exclusive'
+ call setline(1, 'He said "How are you?"')
+ set selection=exclusive
+ normal 012lv2li"y
+ call assert_equal('How are you?', @")
+ set selection&
+
+ " try copy a quote object with a single quote in the line
+ call setline(1, "Smith's car")
+ call cursor(1, 6)
+ call assert_beeps("normal yi'")
+ call assert_beeps("normal 2lyi'")
+
+ " selecting space before and after a quoted string
+ call setline(1, "some 'special' string")
+ normal 0ya'
+ call assert_equal("'special' ", @")
+ call setline(1, "some 'special'string")
+ normal 0ya'
+ call assert_equal(" 'special'", @")
+
+ " quoted string with odd or even number of backslashes.
+ call setline(1, 'char *s = "foo\"bar"')
+ normal $hhyi"
+ call assert_equal('foo\"bar', @")
+ call setline(1, 'char *s = "foo\\"bar"')
+ normal $hhyi"
+ call assert_equal('bar', @")
+ call setline(1, 'char *s = "foo\\\"bar"')
+ normal $hhyi"
+ call assert_equal('foo\\\"bar', @")
+ call setline(1, 'char *s = "foo\\\\"bar"')
+ normal $hhyi"
+ call assert_equal('bar', @")
+
+ close!
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab