Skip to content

Commit cc1f111

Browse files
committed
fixes #3, #4 - camelcase optimized and count added
1 parent ff75175 commit cc1f111

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Smarter, horizontal navigation in vim.
44

5-
[![asciicast](https://asciinema.org/a/8dtiq6m4fzoh7fgz872g5oi0s.png)](https://asciinema.org/a/8dtiq6m4fzoh7fgz872g5oi0s)
5+
6+
[![asciicast](https://asciinema.org/a/7ewafmt0dx3ruwjphpwew1c8g.png)](https://asciinema.org/a/7ewafmt0dx3ruwjphpwew1c8g?autoplay=1)
67

78
`vim-nav` is a simple plugin that hijacks `b` and `e` for smarter navigation between characters. **vim-nav** allows you to navigate through snake case, camel case and normal word breaks. Break characters are also configurable for custom navigation.
89

lib/nav.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def move(direction, count=1):
7777
# if we hit a white space on the first element, then we want to keep
7878
# going to find the next non-whitespace element
7979
if re.match(r'\s', char) or re.match(r'\n', char):
80-
if moved > 0:
80+
if moved > 1:
8181
col -= direction
8282
# if col is less than zero, it means we are moving forward and
8383
# the last position was the last character of the previous
@@ -94,7 +94,10 @@ def move(direction, count=1):
9494
col = 0
9595
break
9696
else:
97+
moved += 1
98+
col += direction
9799
is_empty = True
100+
continue
98101

99102
# if we've move more than one character, are going backwards and are on
100103
# the first element in a list then we can break
@@ -106,7 +109,9 @@ def move(direction, count=1):
106109
break
107110

108111
# the current character has a different case than the start char
109-
if (char.lower() == char) != (start_char == start_char.lower()):
112+
if start_char == start_char.lower() and char == char.upper():
113+
break
114+
if start_char == start_char.upper() and char == char.upper() and moved > 0:
110115
break
111116

112117
# if the current character is one of our delimiter characters break,
@@ -129,6 +134,7 @@ def move(direction, count=1):
129134

130135
# move to the correct character
131136
vim.current.window.cursor = (row+1, col)
137+
return move(direction, count-1)
132138

133139

134140
def forwards(count=1):

plugin/vim-nav.vim

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import nav
2323
EOF
2424

2525
" map b in normal mode to nav.backwards()
26-
nmap b :python nav.backwards()<CR>
27-
"nmap b :normal n.:python nav.backwards()<CR>
26+
"nmap b :python nav.backwards()<CR>
27+
"nmap b @dd
2828

29-
" map e in normal mode to nav.forwards()
30-
nmap e :python nav.forwards()<CR>
31-
"nmap e :normal n.:python nav.backwards()<CR>
29+
:nnoremap b :<C-U>exe ":python nav.backwards(count=".v:count1.")"<CR>
30+
:nnoremap e :<C-U>exe ":python nav.forwards(count=".v:count1.")"<CR>

0 commit comments

Comments
 (0)