aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYochem van Rosmalen <git@yochem.nl>2024-11-04 15:06:18 +0100
committerGitHub <noreply@github.com>2024-11-04 06:06:18 -0800
commit079e5f4f9b67a5aa2c1b481ce78711bf8c76caea (patch)
tree9553e0f74265904d0e9f1552609d39ed17ffc90e
parenta27419f3fc540f66567f4559a796cd6758f1bb1f (diff)
downloadrneovim-079e5f4f9b67a5aa2c1b481ce78711bf8c76caea.tar.gz
rneovim-079e5f4f9b67a5aa2c1b481ce78711bf8c76caea.tar.bz2
rneovim-079e5f4f9b67a5aa2c1b481ce78711bf8c76caea.zip
feat(defaults): unimpaired empty line below/above cursor #30984
-rw-r--r--runtime/doc/insert.txt10
-rw-r--r--runtime/doc/news.txt1
-rw-r--r--runtime/doc/vim_diff.txt1
-rw-r--r--runtime/lua/vim/_defaults.lua13
-rw-r--r--test/functional/editor/defaults_spec.lua48
5 files changed, 73 insertions, 0 deletions
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt
index 27b28624f8..48fd442b7e 100644
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -1907,6 +1907,16 @@ These commands are used to start inserting text. You can end insert mode with
<Esc>. See |mode-ins-repl| for the other special characters in Insert mode.
The effect of [count] takes place after Insert mode is exited.
+The following commands insert text, but stay in normal mode:
+
+ *]<Space>*
+]<Space> Insert an empty line below the cursor without leaving
+ Normal mode, repeat [count] times.
+
+ *[<Space>*
+[<Space> Insert an empty line above the cursor without leaving
+ Normal mode, repeat [count] times.
+
When 'autoindent' is on, the indent for a new line is obtained from the
previous line. When 'smartindent' or 'cindent' is on, the indent for a line
is automatically adjusted for C programs.
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 3a8277f566..df794596b8 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -178,6 +178,7 @@ DEFAULTS
• |[t|, |]t|, |[T|, |]T|, |[CTRL-T|, |]CTRL-T| navigate through the |tag-matchlist|
• |[a|, |]a|, |[A|, |]A| navigate through the |argument-list|
• |[b|, |]b|, |[B|, |]B| navigate through the |buffer-list|
+ • |[<Space>|, |]<Space>| add an empty line above and below the cursor
• Snippet:
• `<Tab>` in Insert and Select mode maps to `vim.snippet.jump({ direction = 1 })`
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 10816ec358..8fa94a2601 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -163,6 +163,7 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y".
- |[t|, |]t|, |[T|, |]T|, |[CTRL-T|, |]CTRL-T|
- |[a|, |]a|, |[A|, |]A|
- |[b|, |]b|, |[B|, |]B|
+- |[<Space>|, |]<Space>|
- Nvim LSP client defaults |lsp-defaults|
- K |K-lsp-default|
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index d3b7bda871..f399360f1e 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -363,6 +363,19 @@ do
cmd({ cmd = 'blast' })
end
end, { desc = ':blast' })
+
+ -- Add empty lines
+ vim.keymap.set('n', '[<Space>', function()
+ local repeated = vim.fn['repeat']({ '' }, vim.v.count1)
+ local linenr = vim.api.nvim_win_get_cursor(0)[1]
+ vim.api.nvim_buf_set_lines(0, linenr - 1, linenr - 1, true, repeated)
+ end, { desc = 'Add empty line above cursor' })
+
+ vim.keymap.set('n', ']<Space>', function()
+ local repeated = vim.fn['repeat']({ '' }, vim.v.count1)
+ local linenr = vim.api.nvim_win_get_cursor(0)[1]
+ vim.api.nvim_buf_set_lines(0, linenr, linenr, true, repeated)
+ end, { desc = 'Add empty line below cursor' })
end
end
diff --git a/test/functional/editor/defaults_spec.lua b/test/functional/editor/defaults_spec.lua
index 70f12ab475..9786bfeaac 100644
--- a/test/functional/editor/defaults_spec.lua
+++ b/test/functional/editor/defaults_spec.lua
@@ -152,6 +152,54 @@ describe('default', function()
]],
})
end)
+
+ describe('[<Space>', function()
+ it('adds an empty line above the current line', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed('[<Space>')
+ n.expect([[
+
+ first line]])
+ end)
+
+ it('works with a count', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed('5[<Space>')
+ n.expect([[
+
+
+
+
+
+ first line]])
+ end)
+ end)
+
+ describe(']<Space>', function()
+ it('adds an empty line below the current line', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed(']<Space>')
+ n.expect([[
+ first line
+ ]])
+ end)
+
+ it('works with a count', function()
+ n.clear({ args_rm = { '--cmd' } })
+ n.insert([[first line]])
+ n.feed('5]<Space>')
+ n.expect([[
+ first line
+
+
+
+
+ ]])
+ end)
+ end)
end)
end)
end)