Skip to content

Commit a49771b

Browse files
committed
Make own subsection and expand
1 parent e4c7d60 commit a49771b

File tree

1 file changed

+61
-39
lines changed

1 file changed

+61
-39
lines changed

docs/usage/line_movement.md

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,6 @@ If you want to figure out how a key sequence should be represented you can try `
3535
The key letter you press is not case sensitive.
3636
So `^a` is the same as `^A`.
3737

38-
If you are coming from bash and want your emacs jump/delete word functions to stop at `/` and `-` you can add this in
39-
your .zshrc:
40-
```
41-
autoload -U select-word-style
42-
select-word-style bash
43-
```
44-
Without it `[^D` will delete a full directory path. For example:
45-
```
46-
## Without
47-
$ cd /project/example/delete
48-
## Press [^D from front beginning of line
49-
$ /project/example/delete
50-
## Press [^D again
51-
$
52-
53-
## With select-word-style bash
54-
$ cd /project/example/delete
55-
## Press [^D from front beginning of line
56-
$ /project/example/delete
57-
## Press [^D again
58-
$ /example/delete
59-
```
60-
You can learn about the available word styles and their behavior [here](https://linux.die.net/man/1/zshcontrib) (search for `select-word-syle`). If you want even more flexiblity you can do the following in your .zshrc:
61-
```
62-
export WORDCHAR=''
63-
```
64-
When in `normal` select-word-style all alpha-numeric characters plus anything in `WORDCHARS` is used by ZSH to determine
65-
when to stop its action. What the `select-style` above does is essentially set it to `''`, if you want even more control
66-
to know when to stop feel free to set the var directly. This can then be used to make your backwards jump different than
67-
your forwards jump. For example if I want my backward delete to delete a whole directory path I can set this:
68-
```
69-
default-backward-delete-word () {
70-
local WORDCHARS="*?_[]~=/&;!#$%^(){}<>"
71-
zle backward-delete-word
72-
}
73-
zle -N default-backward-delete-word
74-
bindkey '^W' default-backward-delete-word
75-
```
76-
7738
## Basic movement
7839

7940
I may like vi mode for my keymap but I'm not a monster.
@@ -119,6 +80,67 @@ There are many `*-kill-*` widgets available that will let you kill words, lines,
11980

12081
If you don't want to feel like a murderer you can also try the `*-yank-*` and `*-push-*` widgets too.
12182

83+
### Advance Word Movements and Modifications
84+
When jumping between words (for example `[^f` and `[^b` for forward and backwards in emacs mode). The shell uses a few different
85+
things to define what a "word" is. By default you can `echo $WORDCHARS` to see all the special characters the shell will include
86+
in continous wors. For example the default is:
87+
```
88+
$ echo $WORDCHARS
89+
*?_-.[]~=/&;!#$%^(){}<>
90+
```
91+
This means that any alphanumeric character plus any of the above will be combined to be a single word. Notice how `/` is
92+
included in the above. This means `foo/bar/bazz` will be one word to be acted upon.
93+
94+
If you are coming from bash and want your jump/delete word functions to stop at `/` and `-` you can add this in
95+
your .zshrc:
96+
```
97+
autoload -U select-word-style
98+
select-word-style bash
99+
```
100+
Without it `[^D` will delete a full directory path. For example:
101+
```
102+
## Without
103+
$ cd /project/example/delete
104+
## Press [^D from front beginning of line
105+
$ /project/example/delete
106+
## Press [^D again
107+
$
108+
109+
## With select-word-style bash
110+
$ cd /project/example/delete
111+
## Press [^D from front beginning of line
112+
$ /project/example/delete
113+
## Press [^D again
114+
$ /example/delete
115+
```
116+
You can learn about the available word styles and their behavior [here](https://linux.die.net/man/1/zshcontrib) (search for `select-word-syle`).
117+
But here is a quick explanation:
118+
```
119+
$ select-word-style
120+
Usage: select-word-style word-style
121+
where word-style is one of the characters in parentheses:
122+
(b)ash: Word characters are alphanumerics only
123+
(n)ormal: Word characters are alphanumerics plus $WORDCHARS
124+
(s)hell: Words are command arguments using shell syntax
125+
(w)hitespace: Words are whitespace-delimited
126+
(d)efault: Use default, no special handling (usually same as `n')
127+
(q)uit: Quit without setting a new style
128+
```
129+
One important thing to note is that any `select-word-style` that is not `normal` will may not respect `$WORDCHARS`.
130+
When in `normal` select-word-style all alphanumeric characters plus anything in `$WORDCHARS` is used by zsh to determine
131+
when to stop its action. If you want even more control feel free to set the var directly. This can then be used to make your
132+
backwards jump different than your forwards jump.
133+
For example if I want my backward delete to delete a whole directory path I can set this:
134+
```
135+
## with word-style set to `normal` but $WORDCHARS=''
136+
default-backward-delete-word () {
137+
local WORDCHARS="*?_[]~=/&;!#$%^(){}<>"
138+
zle backward-delete-word
139+
}
140+
zle -N default-backward-delete-word
141+
bindkey '^W' default-backward-delete-word
142+
```
143+
122144
### Yank current command and paste
123145

124146
For example, let's say you have a long command line typed up but you forgot you needed to run a command first or look up some information.

0 commit comments

Comments
 (0)