Skip to content

Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.

License

Notifications You must be signed in to change notification settings

vypxl/nvim-spider

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-spider

Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.

Lua implementation of CamelCaseMotion. Works in normal, visual, and operator-pending mode. Works with counts.

Features

The w, e, b (and ge) motions work the same as the default ones by vim, except for two differences:

Subword Motion

The movements happen by subwords, meaning it stops at the sub-parts of a CamelCase (or SCREAMING_SNAKE_CASE or kebab-case) variable.

-- positions vim's `w` will move to
local myVariableName = FOO_BAR_BAZ
--    ^              ^ ^

-- positions spider's `w` will move to
local myVariableName = FOO_BAR_BAZ
--    ^ ^       ^    ^ ^   ^   ^

Skipping Insignificant Punctuation

A sequence of one or more punctuation characters is considered significant if it is surrounded by whitespace and does not include any non-punctuation characters.

foo == bar .. "baz"
--  ^      ^    significant punctuation

foo:find("a")
-- ^    ^  ^  insignificant punctuation

This speeds up the movement across the line by reducing the number of mostly unnecessary stops.

-- positions vim's `w` will move to
if foo:find("%d") and foo == bar then print("[foo] has" .. bar) end
-- ^  ^^   ^  ^^  ^   ^   ^  ^   ^    ^    ^  ^  ^ ^  ^ ^  ^  ^ ^  -> 21

-- positions spider's `w` will move to
if foo:find("%d") and foo == bar then print("[foo] has" .. bar) end
-- ^   ^      ^   ^   ^   ^  ^   ^    ^       ^    ^    ^  ^    ^  -> 14

If you prefer to use this plugin only for subword motion, you can disable this feature by setting skipInsignificantPunctuation = false in the .setup() call.

Note
vim's iskeyword option is ignored by this plugin.

Text Object

For an alternative iw text object that considers CamelCase word parts, check out the "subword" text object of nvim-various-textobjs.

Installation

-- packer
use { "chrisgrieser/nvim-spider" }

-- lazy.nvim
{ "chrisgrieser/nvim-spider", lazy = true },

No keybindings are created by default. Below are the mappings to replace the default w, e, and b motions with this plugin's version of them. Note that for dot-repeat to work properly, you have to use a <cmd> mapping that calls the plugin function, not a lua function calling it!

-- Keymaps
vim.keymap.set({"n", "o", "x"}, "w", "<cmd>lua require('spider').motion('w')<CR>", { desc = "Spider-w" })
vim.keymap.set({"n", "o", "x"}, "e", "<cmd>lua require('spider').motion('e')<CR>", { desc = "Spider-w" })
vim.keymap.set({"n", "o", "x"}, "b", "<cmd>lua require('spider').motion('b')<CR>", { desc = "Spider-w" })
vim.keymap.set({"n", "o", "x"}, "ge", "<cmd>lua require('spider').motion('ge')<CR>", { desc = "Spider-w" })

Configuration

The .setup() call is optional. Currently, its only option is to disable the skipping of insignificant punctuation:

-- default values
require("spider").setup({
	skipInsignificantPunctuation = true
})

Credits

About Me
In my day job, I am a sociologist studying the social mechanisms underlying the digital economy. For my PhD project, I investigate the governance of the app economy and how software ecosystems manage the tension between innovation and compatibility. If you are interested in this subject, feel free to get in touch.

Profiles

Buy Me a Coffee

Buy Me a Coffee at ko-fi.com

About

Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%