https://github.com/chrisgrieser/nvim-spider
Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: researchgate.net -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.3%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.
Basic Info
Statistics
- Stars: 784
- Watchers: 3
- Forks: 14
- Open Issues: 3
- Releases: 0
Topics
Metadata Files
README.md
nvim-spider 🕷️🕸️
Use the w, e, b motions like a spider. Move by subwords and skip
insignificant punctuation.
Features
The w, e, b (and ge) motions work the same as the default ones by vim,
except for two differences:
Subword motion
The motions are based on subwords, meaning they stop at the segments of a
camelCase, SNAKE_CASE, or kebab-case variable.
``lua
-- positions vim'sw` will move to
local myVariableName = FOOBARBAZ
-- ^ ^ ^
-- positions spider's w will move to
local myVariableName = FOOBARBAZ
-- ^ ^ ^ ^ ^ ^ ^
```
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.
```lua 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.
``lua
-- positions vim'sw` 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 motions, you can disable this
feature by setting skipInsignificantPunctuation = false in the .setup()
call.
[!NOTE] This plugin ignores vim's
iskeywordoption.
Installation
```lua -- packer use { "chrisgrieser/nvim-spider" }
-- lazy.nvim { "chrisgrieser/nvim-spider", lazy = true },
-- vim-plug Plug("chrisgrieser/nvim-spider") ```
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.
```lua
vim.keymap.set({ "n", "o", "x" }, "w", "
-- OR: lazy-load on keystroke (lazy.nvim)
{
"chrisgrieser/nvim-spider",
keys = {
{ "w", "
[!NOTE] For dot-repeat to work, you have to call the motions as Ex-commands. Dot-repeat will not work when using
function() require("spider").motion("w") endas third argument.
Configuration
Basic configuration
The .setup() call is optional.
lua
-- default values
require("spider").setup {
skipInsignificantPunctuation = true,
consistentOperatorPending = false, -- see the README for details
subwordMovement = true,
customPatterns = {}, -- see the README for details
}
You can also pass this configuration table to the motion function:
lua
require("spider").motion("w", { skipInsignificantPunctuation = false })
Any options passed to .motion take precedence over the options set in
.setup.
Advanced: custom movement patterns
You can use the customPatterns table to define custom movement patterns.
- These must be lua
patterns.
- If multiple patterns are given, the motion searches for all of them and stops
at the closest one. When there is no match, the search continues in the next
line.
- The customPatterns option overrides nvim-spider's default behavior,
meaning no subword movement and skipping of punctuation. Pass a pattern
table and set overrideDefault = false to extend nvim-spider's default
behavior with a new pattern.
- You can use customPatterns in the .motion call to create new motions,
while still having access nvim-spider's default behavior.
- They must be symmetrical (work the same backwards and forwards) to work for
the backwards and forwards motions. If your patterns are not symmetric, you
must define them for each direction via .motion.
A few examples:
```lua -- The motion stops only at numbers. require("spider").motion("w", { customPatterns = { "%d+" }, })
-- The motion stops at any occurrence of the ltters "A" or "C", in addition -- to spider's default behavior. require("spider").motion("w", { customPatterns = { patterns = { "A", "C" }, overrideDefault = false, }, })
-- The motion stops at the next declaration of a javascript variable.
-- (The e motion combined with the . matching any character in
-- lua patterns ensures that you stop at beginning of the variable name.)
require("spider").motion("e", {
customPatterns = { "const .", "let .", "var ." },
})
```
Special cases
UTF-8 support
For adding UTF-8 support for matching non-ASCII text, add luautf8 as rocks.
You can do so directly in packer.nvim or via dependency on nvim_rocks in
lazy.nvim.
```lua -- packer { "chrisgrieser/nvim-spider", rocks = "luautf8" }
-- lazy.nvim { "chrisgrieser/nvim-spider", lazy = true, dependencies = { "theHamsta/nvimrocks", build = "pip3 install --user hererocks && python3 -mhererocks . -j2.1.0-beta3 -r3.0.0 && cp nvimrocks.lua lua", config = function() require("nvimrocks").ensureinstalled("luautf8") end, }, }, ```
Subword text object
This plugin supports w, e, and b in operator-pending mode, but does not
include a subword variant of iw. For a version of iw that considers
camelCase, check out the subword text object of
nvim-various-textobjs.
Operator-pending mode: the case of cw
In operator pending mode, vim's web motions are actually a bit inconsistent.
For instance, cw will change to the end of a word instead of the start of
the next word, like dw does. This is probably done for convenience in vi's
early days before <!-- harper: ignore -->there were text objects. In my view,
this is quite problematic since it makes people habitualize inconsistent motion
behavior.
In this plugin, such small inconsistencies are therefore deliberately not
implemented. Apart from the inconsistency, such a behavior can create unexpected
results when used in subwords or near punctuation. If you nevertheless prefer
that behavior, you can achieve that behavior by mapping cw to ce:
```lua
vim.keymap.set("o", "w", "
-- OR in one mapping
vim.keymap.set("n", "cw", "c
Consistent operator-pending mode
Vim has more inconsistencies related to how the motion range is interpreted (see
:h exclusive). For example, if the end of the motion is at the beginning of a
line, the endpoint is moved to the last character of the previous line.
lua
foo bar
-- ^
baz
Typing dw deletes only bar. baz stays on the next line.
Similarly, if the start of the motion is before or at the first non-blank
character in a line, and the end is at the beginning of a line, the motion is
changed to linewise.
lua
foo
-- ^
bar
Typing yw yanks foo\r, that is, the indentation before the cursor is
included, and the register type is set to linewise.
Setting consistentOperatorPending = true removes these special cases. In the
first example, bar\r would be deleted charwise. In the second example, foo\r
would be yanked charwise.
Caveats
1. Last visual selection marks (`[ and `]) are updated and point to
the endpoints of the motion. This was not always the case before.
2. Forced blockwise motion may be canceled if it cannot be correctly represented
with the current selection option.
Motions in insert mode
Simple and pragmatic: Wrap the normal mode motions in <Esc>l and i. (Drop
the l on backwards motions.)
lua
vim.keymap.set("i", "<C-f>", "<Esc>l<cmd>lua require('spider').motion('w')<CR>i")
vim.keymap.set("i", "<C-b>", "<Esc><cmd>lua require('spider').motion('b')<CR>i")
Credits
Thanks
- @vypxl and @ii14 for figuring out dot-repeatability of
textobjects.
- @vanaigr for a large contribution regarding operator-pending mode.
About the developer
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.
Owner
- Name: Chris Grieser
- Login: chrisgrieser
- Kind: user
- Location: Berlin, Germany
- Company: Technical University of Berlin
- Website: https://chris-grieser.de/
- Repositories: 189
- Profile: https://github.com/chrisgrieser
Researcher in sociology & software developer
GitHub Events
Total
- Issues event: 11
- Watch event: 147
- Delete event: 4
- Issue comment event: 31
- Push event: 35
- Pull request review comment event: 6
- Pull request review event: 4
- Pull request event: 8
- Fork event: 2
- Create event: 3
Last Year
- Issues event: 11
- Watch event: 147
- Delete event: 4
- Issue comment event: 31
- Push event: 35
- Pull request review comment event: 6
- Pull request review event: 4
- Pull request event: 8
- Fork event: 2
- Create event: 3
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Chris Grieser | 7****r | 241 |
| vanaigr | v****v@g****m | 4 |
| vypxl | t****s@v****o | 3 |
| Pavel | w****a@g****m | 3 |
| dependabot[bot] | 4****] | 2 |
| Anshuman | a****i@c****k | 2 |
| smjonas | j****r@g****e | 1 |
| roycrippen4 | 5****4 | 1 |
| rami3l | r****l@o****m | 1 |
| Sangho Lee | s****5@o****m | 1 |
| John Bernard | 3****n | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 5 months ago
All Time
- Total issues: 40
- Total pull requests: 24
- Average time to close issues: 16 days
- Average time to close pull requests: 9 days
- Total issue authors: 33
- Total pull request authors: 14
- Average comments per issue: 2.18
- Average comments per pull request: 2.21
- Merged pull requests: 18
- Bot issues: 0
- Bot pull requests: 4
Past Year
- Issues: 8
- Pull requests: 8
- Average time to close issues: 25 days
- Average time to close pull requests: 18 minutes
- Issue authors: 8
- Pull request authors: 3
- Average comments per issue: 1.5
- Average comments per pull request: 1.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 4
Top Authors
Issue Authors
- Aumnescio (3)
- TheSast (2)
- jgollenz (2)
- leg7 (2)
- kevintraver (2)
- mech-a (2)
- ray-x (1)
- PrayagS (1)
- utkarshgupta137 (1)
- NormTurtle (1)
- quangd42 (1)
- Patitotective (1)
- ispringle (1)
- Mithrandir2k18 (1)
- premell (1)
Pull Request Authors
- vanaigr (4)
- dependabot[bot] (4)
- tandetat (2)
- roycrippen4 (2)
- rami3l (2)
- guru245 (2)
- IndianBoy42 (1)
- vypxl (1)
- smjonas (1)
- JarKz (1)
- nino (1)
- loqusion (1)
- ivan-volnov (1)
- filipgodlewski (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v2 composite
- kdheepak/panvimdoc main composite
- stefanzweifel/git-auto-commit-action v4 composite
- JohnnyMorganz/stylua-action v2 composite
- actions/checkout v3 composite
- actions/stale v8 composite