chaoren / vim-wordmotion Goto Github PK
View Code? Open in Web Editor NEWMore useful word motions for Vim
More useful word motions for Vim
I've recently migrated to Lazy from Packer and it seems this has broken support to wordmotion_prefix.
You can reproduce this with the following minimal configuration:
-- bootstrap lazy
--
local lazy_path = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazy_path) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazy_path,
})
end
vim.opt.rtp:prepend(lazy_path)
-- plugins
--
require("lazy").setup({
{ "chaoren/vim-wordmotion" }, -- more precise word motion
})
vim.g.wordmotion_prefix = ","
Running :map w
outputs:
o w <Plug>WordMotion_w
x w <Plug>WordMotion_w
n w <Plug>WordMotion_w
Hi, I'm sorry but I didn't quite follow how to setup my own keys.
Let's say I want to preserve the default behavior of 'w', 'W', 'b', 'B', 'e', 'E', 'ge' and 'gE'. And I want to set up new motions <M-w>
, <M-e>
, <M-b>
to perform camel-case etc. traversal. What do I need to do?
As the subject says. It looks like this should be possible with a big ilst in g:wordmotion_uppercase_spaces but it might be nice to have some easy way to do this (maybe just a var lying around that could be advertised in the docs). People who don't like lots of white space just never use W so it's likely a common want.
Hi! This is a great plugin, and has made vim word motions work way better for me. So, thank you!
The one problem I'm having is that I work with hex color codes a lot (#0f0f0f
, #ebebeb
, etc). Since numbers are considered the start of a new word, codes like #0f0f0f
quickly get in the way. I understand that numbers should be separate words in some languages, but these hex codes are where I most often encounter them.
I would like to request an option to change whether numbers are considered words.
Or maybe include these codes along with the other hex literals (0x00ffFF
), since they are essentially the same thing.
Trying to use <S-Left>
and <S-Right>
, <C-Left>
and <C-Right>
to navigate word boundaries while in insert mode and i'm back in the dark ages again!
I can't seem to find any easy example of how to map a keybinding to call the wordmotion navigation either.
redacted
ok so there are two things i have noticed.
thing 1:
asdf_
^ cursor
cw
here will change up to the underscore. default vim cw
will change up to the a (it goes up to the word, not to the end of the word)
thing 2:
vims special case for cw (see https://old.reddit.com/r/vim/comments/26nut8/why_does_cw_work_like_ce/)
it would be nice if there was an option for the more canonical version of cw
eg:
asdf (
^ cursor
dw
here would delete to the (
cw
deletes up to (not including) the space, so it's like ce
Hi,
Let's say we have
foo bar
and then with cursor on first "o" of "foo" I press cw
. After doing that, I'm getting
fbar
Without the plugin I was getting
f bar
Is that normal behavior?
THX, Alejandro
It's stated in README that the hex color codes are single words but e.g. #B2B2B2 is 6 words for me, same with lowercase. edit: That only happens when the color code is surrounded with quotes
consider the scenario:
return true;
your cursor is somewhere on true
and you use vaw
.
default vim selects true
and the prior space, this plugin just selects true
.
it seems like you get this right in some scenarios, eg:
return true
here the space will be selected.
it happens with other delimiters than spaces too:
return my_var;
if your cursor is on var
, it won't select the underscore.
return my_var
but do the same on this line, and the underscore is selected.
The behavior of the vim-wordmotion plugin doesn't correspond to the default vim w
, b
, e
, ge
motions interaction with folds.
Instead of opening fold (if foldopen
option contains hor
value, which is by default) vim-wordmotion moves cursor between words inside a closed fold without opening it.
It's nice to be able to configure plugin-provided mappings using <Plug>
, as opposed to config dictionaries. This way you can keep them in the same format as native mappings. If you're willing to incorporate <Plug>
mappings, I can provide a PR that implements them. Shouldn't be too much code. There would also be an option g:wordmotion_disable_default_mappings
that would disable the default logic for those who would rather set their own mappings with <Plug>
.
Hi there. Thanks for the useful plugin.
Though I noticed it doesn't work as I expect in the visual mode. If I press ve
it still selects word as usual. This is my config
let g:wordmotion_nomap = 1
nmap w <Plug>WordMotion_w
nmap b <Plug>WordMotion_b
nmap gE <Plug>WordMotion_gE
omap aW <Plug>WordMotion_aW
cmap <C-R><C-W> <Plug>WordMotion_<C-R><C-W>
Could you guide me on how to resolve that? Thanks!
The first line is a sample line, I expect to reach the g
with 3w
(see the first line) but I actually have to use 5w
since the accented character isn't taken into account as alphanumeric character.
abc déf ghi
^ ^ ^
^ ^^^ ^
For example I'd like to have vim-wordmotion
motion mapped to W
, B
, E
, gE
, aW
, iW
but I currently don't have any clean way to do so beside using a bogus custom prefix and then remapping the keys by hand.
I'd suggest to provide a way for the user to provide some custom mappings, maybe via a list/dictionary
It seems that the count work as expected only when the cursor is placed at the end of the word:
I suspect that here
vim-wordmotion/autoload/wordmotion.vim
Lines 118 to 124 in 0edeebd
if l:count == 1 && l:cw
let l:flags .= 'c'
endif
while l:count > 0
call search('\m'.l:pattern, l:flags.'W')
let l:count -= 1
endwhile
And I've tested it and it works as expected after the modification, but I'm not sure whether it will break other stuff.
I've just tried vim-wordmotion
. What an awesome plugin!
But I was wondering about the strange stop points in this line:
#define SCANCODE_TAB_KEY 15
^ ^ ^ ^ ^ ^
The reason might be that #def
could be a short hex color code. Is this the intended behavior? I suppose there are more #define
s in the world than mixed words starting with a short hex color code and going on with some unrelated letters :-)
Can I somehow define not to consider #define
as two words? Kind of a blacklist?
I recently wrote a macro like this:
ct(getFilter^[
to fix a piece of code like this:
let f = getConversion(...);
I'd expect it to give me:
let f = getFilter(...);
When I run this macro from the g
, I instead get:
const f = call <SNR>71_WordMotion(v:count1, 'o', 'be', [])
tFilter(...)
When I run the macro commands manually in normal mode, the desired behavior occurs.
When coupeling with iw
, vim will treat visual block select like the normal visual select.
[cursor]
Camel[C]ase --> <C-v>iw
--> Camel[Case]
CamelCas[e] --> <C-v>iw
--> Camel[Case]
Vim merely jumps to the end of the word without selecting
Camel[C]ase --> <C-v>iw
-> CamelCas[e]
CamelCas[e] --> <C-v>iw
-> CamelCas[e]
The motion to step backwards over/through words is no longer working after I recently updated the plugin. Previously it had stepped over camelCased words perfectly fine, but now the functionality (even default of stepping over entire words) is broken.
Now, When I press b
the cursor moves backwards as if I were pressing the h
key to step backwards letter by letter.
I haven't looked at the code to try and figure out a possible PR, but I did verify that it's this plugin by removing the plugin, which returned the b
key back to the standard behavior.
This is a very useful plugin, especially when I have long_variable_name and need to change part of it. However, when working with surround, it is not very handy.
E.g.
[l]ong_variable_name1, long_variable_name2, ...
do ysw" and I got:
"long_"variable_name1, long_variable_name2, ...;
do ysW" and I got:
"long_variable_name1," long_variable_name2, ...
But most of the time, people want "long_variable_name1", and I cannot achieve this.
I'm wondering is there any workaround for this?
I configured let g:wordmotion_prefix = ","
in my vimrc and expected text object bindings to change from iw
and aw
to i,w
and a,w
. Because I see i
and a
as the verbs and w
or ,w
as the nouns that the verbs operate on. Instead, the bindings were changed to ,iw
and ,aw
.
I'm using the following as a workaround:
let g:wordmotion_mappings = {
\ 'w' : ',w',
\ 'e' : ',e',
\ 'b' : ',b',
\ 'ge' : ',ge',
\ 'iw' : 'i,w',
\ 'aw' : 'a,w'
\ }
Along with binary and hexadecimal: 0o0644
Hi there!
I just noticed that the plugin doesn't interact quite well with nvim's lsp lua vim.lsp.buf.rename()
.
Say for example I'm renaming nice_variable
to cool_variable
with the cursor over the word varible
by launching the above mentioned command.
The prompt will ask what to replace variable
with, instead of `nice_variable''.
Is this the expected behavior?
Hello,
In the command line area I am seeing spurious output from this wordmotion plugin when set noshowmode
is set.
Steps to produce the issue:
set noshowmode
Edit a file such as the following with the cursor positioned on the 1st line inside Bar:
FooBarFoo
BarFooBar
Do ciw
to anything (e.g Car)
Move cursor to 2nd line inside Foo and hit dot .
to repeat the change
Look in the command line area, spurious output will be emitted, in my case :call <SNR>10_AOrInnerWordMotion(v:count1, 'o', 1)
. Note, the actual change word operation is being performed correctly.
When showmode
is set (aka the Vim default) there is no spurious output.
Maybe a <silent>
directive is needed somewhere?
Thanks for a great plugin.
hey, thanks for the plugin. was looking for something like it and works like a charm. After using it for a while, I would prefer to use the default word definition for WORD
. Is that config possible? I could not find it in the docs.
thanks!
Pretty much title, it would be nice to use wordmotions in the command line insertion.
Hi Chaoren - Thanks for this plugin!
When I cw
on the word at the end of the line, vim-wordmotion includes the EOL, so I effectively join lines.
I think this is addressed in your README, where you say:
If you want to restore Vim's special case behavior with dw and cw, you can do this:
map dw de
map cw ce
Problem is, when I do that, dd
takes a second before acting. Which is weird, because those mappings aren't for dd
.
It's map dw de
that's doing it. Without that, dd
is instantaneous, like it's supposed to be.
Come to think of it, this doesn't have anything to do with vim-wordmotion, since I can replicate it without the plugin even loading. Perhaps you have some insight anyway?
This is with vim 7.4.1689.
I have upgraded to version 5ba8453 (from some old one) in neovim 0.4.4 and on every launch I get:
Error detected while processing function wordmotion#init:
line 40:
E699: Too many arguments
sometimes I also get:
Error detected while processing function wordmotion#motion:
line 33:
E866: (NFA regexp) Misplaced *
Any ideas?
Hello, it is a really great plugin, thanks for your work.
I want to extend the pattern so it can handle some cases like:
Currently, it works like this:
|if ||name| |== |"|main|":
|pass|
I want it to work like this:
|if ||name| |== |"|main|":|
|pass|
Is it possible?
Thank you!
Is it intentional to consume the whitespace between words? I'm getting myself frequently making mistakes because of this change, for example in |foo bar
(cursor is |
), I see that for dw
it's indeed useful to delete whitespace, maybe, but for cw
it doesn't make much sense, even more because it's inconsistent with ciw
that whose purpose is to change word from inside the word, but it differs from behavior given that it doesn't consume whitespace, as in usual Vim.
The four word (not WORD) motions are w
, e
, b
, and ge
. This plugin only works for the first three. It'd be great to have all four. Seems really simple to add. Thanks for the awesome plugin!
Hi there and thanks for this super useful plugin! I'm fairly certain that the issue I'm having is specific to something in my setup, but I'm not sure what exactly is causing it. The issue is that w
works as expected (as described in the README of this repo), but cw
, ce
, dw
and de
all revert to the default vim behavior. You can see my vimrc here. I'd love to hear confirmation that this is in fact not expected and any tips on how I could troubleshoot. Thank you!
First of all, awesome plugin, thank you.
Consider providing a :ToggleWordMotion
command.
Rationale: prefixing wordmotion bindings commands with <leader>
is not ideal. I more often need wordmotions defaults than not.
Temporarily disabling wordmotion would be faster if, for example, want to refactor var a=[a][b][a_really_huge_variable_using_the_normal_w_vim_motion];
.
I'm leaving wordmotion with the default bindings and using :norm! ciw
when I want to operate as described above. But that feels clunky.
ciw
seems to leave behind the last letter of the word.
Hi,
After the implementation of #24 (which I'm still really grateful for!), I'm facing one issue when I use the 'w' motion in a snake_case_word
.
I have set the wordmotion_spaces
variable like this: let g:wordmotion_spaces = '-.<>()\[\]{}&*=!+"'''
When I'm at the beginning of the word and I press 'dw', I'd expect it to delete snake_
so only case_word
would remain. But instead, it results with _case_word
(notice the leading underscore).
If I also include an underscore symbol in the wordmotion_spaces
variable, it works as expected, but it also defeats the purpose of #24. It also works if I don't set the wordmotion_spaces
variable at all, because then it'll get set to _
by default.
Is this also one of the plugin's limitations or can this be fixed?
like [b]ar)
, dW will remove all bar)
.
[]
indicate the cursor position.
Does it by design which is different with Vim origin dw
.
Curious why ci<M-w>
etc work as I'd expect, change default Vim word, but c<M-w>
doesn't, the change is cancelled and cursor moves by default Vim word instead?
The behaviour that you mentioned in caveats section often becomes inconsistent because default dW
still behaves like dE
. So, it would be awesome if you can rebind W
to work like w
.
On files with a shebang and no extension, dw
seems to only delete a single character, rather than until the beginning of the next word.
Create four files (only the first one demonstrates the unintended behaviour, but the other three show (what I believe) the intended behaviour should be).
$ cat test1
#!/usr/bin/env python3
print('test')
$ cat test2
print('test')
$ cat test3.py
print('test')
$ cat test4.py
#!/usr/bin/env python3
print('test')
Reopen each file individually (opening all at the same time does not seem to invoke the unintended behaviour), and with cursor over the p
in print
, press dw
. For test1
, a single character is deleted, resulting in rint('test')
. For all of test2
, test3.py
, and test4.py
, the result is ('test')
.
From my understanding, in all four cases, the result should be ('test')
. Please correct me if I'm misunderstanding something.
Currently with the way the plugin is built, there is no way to disable it. For example, I created a function:
nnoremap <silent> <C-e> :call WordMotionToggle()<cr>
let s:wordmotion_enabled = 1
function! WordMotionToggle()
if s:wordmotion_enabled
let s:wordmotion_enabled = 0
let g:wordmotion_prefix = 'invalid'
else
let s:wordmotion_enabled = 1
let g:wordmotion_prefix = ''
endif
endfunction
However this doesn't work because when WordMotion
loads, it gets the global properties and sets them as local properties to the plugin before doing the motion mappings.
Can this plugin add some functionality that will allow you to disable it on the fly?
When I do ce
for ab.
I get .
, which is correct. If I do it for a.
I get
, which is incorrect, the .
gets consumed.
Is there a good reason for that? Because for me it seems like a waste of my time.
And thank you for working on ci<leader>w
, because in the original plugin it doesn't work.
I'd like to see toggling option in this plugin. For example, let user define a normal mapping to toggle on and off. It is more robust than having g:wordmotion_prefix
, and adheres to vim's modal philosophy. Like, when I press predefined toggle map, I'm in wordmotion mode, press again, I exit wordmotion mode.
In readme you provides two example:
Vim:
^foo [b]ar$ -> dw -> ^foo[ ]$
^ baz$ ^ baz$
^[f]oo bar$ -> cw -> ^[ ]bar$
This plugin:
^foo [b]ar$ -> dw -> ^foo [b]az$
^ baz$
^[f]oo bar$ -> cw -> ^[b]ar$
and recommend to use nmap dw de
to restore Vim's special case behavior.
But when cursor located in the last word of one line, the Vim origin dw
behavior like d$
. Neither dw
nor de
provide by this plugin has same effect.
So am I misunderstand what you post? And expected dw
of this plugin have same effect, i.e. d$
, when delete the last consecutive characters.
Thanks in advance.
First of all, massive thanks for this plugin. I have been using this plugin for years and I've always taken it for granted, being very surprised when I suddenly had to work in Vim without this plugin.
I've always wished for one more feature of this plugin and that would be the possibility to also override the default Vim's W
, B
, E
, and possibly other commands.
The default behaviour is that Vim stops on the space character on these W
, B
, E
commands. It would be great, in my opinion, if we could also override this behaviour so that Vim would stop on characters like -.,>
but not on CamelCase
snake_case
and so on.
To give an example:
|CamelCaseWord->followed_by_snake_case
With the current behaviour, when I press W
, the cursor moves the the end of the line.
What I would like is the cursor stopping on the dash character:
CamelCaseWord|->followed_by_snake_case
This would allow me to delete the first CamelCaseWord
, for example, without deleting the rest. Now I have to press 3dw
or 3 times dw
.
Hopefully it makes sense what I mean.
I had been yearning for this. Thanks for developing. Just close this issue 😆
Actual (w motion):
[f]oo-bar
foo[-]bar
Expected:
[f]oo-bar
foo-[bar]
Can this be easily done? Maybe by extension.
For private
fields in a C++ class, I'm using the convention of a leading underscore, like _length
or _id
. With the default wordmotion settings, w
moves to the first letter and will never stop on the underscore. In any other case, with the underscore in the middle or at the end of a word, that works fine. But it becomes very awkward for example to copy these private field identifiers because I can't w
to the start of the word. Is there a way to configure wordmotion so that a leading underscore is a totally different character than an internal underscore? Or if not, can the position of the underscore be taken into account, so that the leading underscore becomes equivalent to a letter? Thanks for any suggestions.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.