Skip to content

Commit 1a02607

Browse files
committed
ref(nvim): repeat go to prev/next text object
1 parent 22b665e commit 1a02607

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ Neovim text objects + LSP whichkey + touchcursor keyboard layout + minimal zsh/y
120120
| `gr` | vscode-neovim | `n`,`x` | `.` | | +replace (with register) operator | followed by text-object/motion | | applies to selection | `griw` or `viwgr` replaces word with register (yanked text) |
121121
| `gs` | vscode-neovim | `n`,`x` | `.` | | +sort Operator | followed by text-object/motion | | uses selection | `gsip` or `vipgs` sorts a paragraph |
122122
| `gS` | vscode-neovim | `n`,`x` | `.` | | split/join arguments | toggles inside `{}`,`[]`,`()` | | followed by operator | `vipgS` joins selected lines in one line |
123+
| `gt` / `gT` | vscode-neovim | `n`,`x` | `.` | `\` / `\|` | +go to end/start of textobj | followed by text-object | | selects form cursor position | `vgtiq` selects until end of quotation (`\` to repeat) |
124+
| `qq ... q` | vscode-neovim | `n`,`x` | `.` | `\` or `@q` + `@@` | repeats ... macro | followed by text-object | | selects form cursor position | `qqviqq` selects quotation (`\` to repeat) |
125+
| `qw ... q` | vscode-neovim | `n`,`x` | `.` | `\|` or `@w` + `@@` | repeats ... macro | followed by text-object | | selects form cursor position | `qwdiqq` delete inner quotation (`\| ` to repeat) |
123126
| `gu`/`gU` | | `n`,`x` | `.` | | +to lowercase/uppercase | requires a text-object | | applies to selection | `gUiw` (neovim only) or `viwgU` lowercases a word |
124127
| `gv` | | `n`,`x` | | | last selected | finds and jumps | | reselects | `vgv` selects last selection |
125128
| `gw` | | `n`,`x` | `.` | | split/join comments/lines 80chars (keeps cursor position) | requires a text-object | | applies to selection | `gwip` or `vipgw` split/join a paragraph limited by 80 characters |

nvim/init.lua

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,14 @@ map({ "n" }, "K", "10gk")
816816
map({ "n" }, "H", "10h")
817817
map({ "n" }, "L", "10l")
818818
map({ "n" }, "Y", "yg_", { desc = "Yank forward" }) -- "Y" yank forward by default
819-
map({ "v" }, "Y", "g_y", { desc = "Yank forward" })
820-
map({ "v" }, "P", "g_P", { desc = "Paste forward" }) -- "P" doesn't change register
821-
map({ "v" }, "p", '"_c<c-r>+<esc>', { desc = "Paste (dot repeat)(register unchanged)" })
822-
map({ "n" }, "U", "@:", { desc = "repeat `:command`" }) --> :normal A,jkj --> :normal A,j --->  escape char by pression ctrl+v then escape
823-
map({ "v" }, "<", "<gv", { desc = "continious indent" })
824-
map({ "v" }, ">", ">gv", { desc = "continious indent" })
819+
map({ "x" }, "Y", "g_y", { desc = "Yank forward" })
820+
map({ "x" }, "P", "g_P", { desc = "Paste forward" }) -- "P" doesn't change register
821+
map({ "x" }, "p", '"_c<c-r>+<esc>', { desc = "Paste (dot repeat)(register unchanged)" })
822+
map({ "n", "x" }, "U", "@:", { desc = "repeat `:command`" }) --> :normal A,jkj --> :normal A,j --->  escape char by pression ctrl+v then escape
823+
map({ "n", "x" }, "\\", "@q", { desc = "repeat q register/macro" })
824+
map({ "n", "x" }, "|", "@w", { desc = "repeat w register/macro" })
825+
map({ "x" }, "<", "<gv", { desc = "continious indent" })
826+
map({ "x" }, ">", ">gv", { desc = "continious indent" })
825827
map(
826828
"n",
827829
"<esc>",
@@ -847,14 +849,14 @@ if not vim.g.vscode then
847849
map({ "n", "t" }, "<C-j>", "<C-\\><C-n><C-w>j", { desc = "down window or ]w" })
848850
map({ "n", "t" }, "<C-k>", "<C-\\><C-n><C-w>k", { desc = "up window or [w" })
849851
map({ "n", "t" }, "<C-l>", "<C-\\><C-n><C-w>l", { desc = "right window or ]w" })
850-
map({ "n", "v", "t" }, "<C-S-l>", "<cmd>vertical resize -2<cr>", { desc = "vertical shrink" })
851-
map({ "n", "v", "t" }, "<C-S-h>", "<cmd>vertical resize +2<cr>", { desc = "vertical expand" })
852-
map({ "n", "v", "t" }, "<C-S-j>", "<cmd>resize -2<cr>", { desc = "horizontal shrink" })
853-
map({ "n", "v", "t" }, "<C-S-k>", "<cmd>resize +2<cr>", { desc = "horizontal shrink" })
854-
map({ "n", "v", "t" }, "<S-right>", "<cmd>vertical resize -2<cr>", { desc = "vertical shrink" })
855-
map({ "n", "v", "t" }, "<S-left>", "<cmd>vertical resize +2<cr>", { desc = "vertical expand" })
856-
map({ "n", "v", "t" }, "<S-down>", "<cmd>resize -2<cr>", { desc = "horizontal shrink" })
857-
map({ "n", "v", "t" }, "<S-up>", "<cmd>resize +2<cr>", { desc = "horizontal shrink" })
852+
map({ "n", "x", "t" }, "<C-S-l>", "<cmd>vertical resize -2<cr>", { desc = "vertical shrink" })
853+
map({ "n", "x", "t" }, "<C-S-h>", "<cmd>vertical resize +2<cr>", { desc = "vertical expand" })
854+
map({ "n", "x", "t" }, "<C-S-j>", "<cmd>resize -2<cr>", { desc = "horizontal shrink" })
855+
map({ "n", "x", "t" }, "<C-S-k>", "<cmd>resize +2<cr>", { desc = "horizontal shrink" })
856+
map({ "n", "x", "t" }, "<S-right>", "<cmd>vertical resize -2<cr>", { desc = "vertical shrink" })
857+
map({ "n", "x", "t" }, "<S-left>", "<cmd>vertical resize +2<cr>", { desc = "vertical expand" })
858+
map({ "n", "x", "t" }, "<S-down>", "<cmd>resize -2<cr>", { desc = "horizontal shrink" })
859+
map({ "n", "x", "t" }, "<S-up>", "<cmd>resize +2<cr>", { desc = "horizontal shrink" })
858860
map({ "n" }, "<right>", "<cmd>bnext<CR>", { desc = "next buffer" })
859861
map({ "n" }, "<left>", "<cmd>bprevious<CR>", { desc = "prev buffer" })
860862
map({ "n" }, "<leader>x", "<cmd>bp | bd! #<CR>", { desc = "Close Buffer" }) -- `bd!` forces closing terminal buffer
@@ -1405,41 +1407,41 @@ map(
14051407
function()
14061408
local _, inner_outer_key = pcall(vim.fn.getcharstr)
14071409
local _, motion_key = pcall(vim.fn.getcharstr)
1410+
local cmd
14081411

14091412
if vim.fn.mode() == "n" then
1410-
vim.cmd.exec([["normal v]] .. inner_outer_key .. motion_key .. [[\<esc>`< "]]) -- empty space or `<\\ or `<` or `<`< ... escape special char since `< waits for a especial char
1413+
cmd = "v" .. inner_outer_key .. motion_key .. "`< " -- empty spaces or repeat sequence `<`< escapes special char since `< waits for a especial char
14111414
else
14121415
-- mT = Temp mark
14131416
-- mS = Start mark
1414-
-- `T = go to Temp mark
1415-
-- `S = go to Start mark
1416-
-- `< = start of recent selection
1417-
-- `> = end of recent selection
1418-
vim.cmd.exec([["normal \<esc>mT`>mS`Tv]] .. inner_outer_key .. motion_key .. [[\<esc>`<v`So"]])
1417+
cmd = "mT`>mS`Tv" .. inner_outer_key .. motion_key .. "`<v`So"
14191418
end
1419+
1420+
vim.cmd.exec([["normal ]] .. cmd .. [["]])
1421+
vim.fn.setreg('w', cmd)
14201422
end,
1421-
{ desc = "Start of TextObj" }
1423+
{ desc = "Start of TextObj (| to repeat)" }
14221424
)
14231425
map(
14241426
{ "n", "x" },
14251427
"gt",
14261428
function()
14271429
local _, inner_outer_key = pcall(vim.fn.getcharstr)
14281430
local _, motion_key = pcall(vim.fn.getcharstr)
1431+
local cmd
14291432

14301433
if vim.fn.mode() == "n" then
1431-
vim.cmd.exec([["normal v]] .. inner_outer_key .. motion_key .. [[\<esc>`>"]])
1434+
cmd = "v" .. inner_outer_key .. motion_key .. "`>"
14321435
else
14331436
-- mT = Temp mark
14341437
-- mS = Start mark
1435-
-- `T = go to Temp mark
1436-
-- `S = go to Start mark
1437-
-- `< = start of recent selection
1438-
-- `> = end of recent selection
1439-
vim.cmd.exec([["normal \<esc>mT`<mS`Tv]] .. inner_outer_key .. motion_key .. [[\<esc>`>v`So"]])
1438+
cmd = "mT`<mS`Tv" .. inner_outer_key .. motion_key .. "`>v`So"
14401439
end
1440+
1441+
vim.cmd.exec([["normal ]] .. cmd .. [["]])
1442+
vim.fn.setreg('q', cmd)
14411443
end,
1442-
{ desc = "End of TextObj" }
1444+
{ desc = "End of TextObj (\\ to repeat)" }
14431445
)
14441446

14451447
map({ "n", "x" }, "gb", '"_d', { desc = "Blackhole Motion/Selected (dot to repeat)" })

0 commit comments

Comments
 (0)