(Change to TipImported template + severe manual clean) |
(→Comments: onoremap is for use with commands) Tag: sourceedit |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | {{review}} |
||
{{TipImported |
{{TipImported |
||
|id=1016 |
|id=1016 |
||
− | |previous= |
+ | |previous=1014 |
|next=1017 |
|next=1017 |
||
− | |created= |
+ | |created=2005 |
|complexity=basic |
|complexity=basic |
||
|author=Anthony Van Ham, Gerald Lai |
|author=Anthony Van Ham, Gerald Lai |
||
|version=6.0 |
|version=6.0 |
||
|rating=14/11 |
|rating=14/11 |
||
+ | |category1= |
||
+ | |category2= |
||
}} |
}} |
||
− | Some programs use CamelCaseWords (or camelCaseWords). The following maps allow you to move word by word, for example, from the 'C' of Camel, to the 'C' of Case, to the 'W' of Words. |
+ | Some programs use CamelCaseWords (or camelCaseWords). The following maps allow you to move word by word, for example, from the 'C' of Camel, to the 'C' of Case, to the 'W' of Words. Some alternate versions are given, starting with something simple and more easily understood. |
+ | ==Simple move== |
||
<pre> |
<pre> |
||
− | + | nnoremap <C-Left> :call search('\<\<Bar>\u', 'bW')<CR> |
|
− | + | nnoremap <C-Right> :call search('\<\<Bar>\u', 'W')<CR> |
|
− | + | inoremap <C-Left> <C-o>:call search('\<\<Bar>\u', 'bW')<CR> |
|
− | + | inoremap <C-Right> <C-o>:call search('\<\<Bar>\u', 'W')<CR> |
|
</pre> |
</pre> |
||
+ | ==Better handling of all-uppercase words== |
||
− | ==Comments== |
||
Here is a more thorough version. It does not go through a CAPITALIZED word one character at a time. |
Here is a more thorough version. It does not go through a CAPITALIZED word one character at a time. |
||
− | |||
<pre> |
<pre> |
||
− | nnoremap |
+ | nnoremap <silent><C-Left> :<C-u>call search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%^','bW')<CR> |
⚫ | |||
− | |||
− | + | inoremap <silent><C-Left> <C-o>:call search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%^','bW')<CR> |
|
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
</pre> |
</pre> |
||
− | ==Enhanced version |
+ | ==Enhanced version== |
With the following, the cursor will stop at: |
With the following, the cursor will stop at: |
||
− | + | *The beginning of a word. |
|
− | + | *The beginning of a run of camel characters. |
|
− | + | *A camel character followed by a run of non-camel characters. |
|
− | + | *The start and end of the file. |
|
− | #The end of the file. |
||
− | |||
<pre> |
<pre> |
||
− | "Use one of the following to define the camel characters. |
+ | " Use one of the following to define the camel characters. |
− | "Stop on capital letters. |
+ | " Stop on capital letters. |
− | + | let g:camelchar = "A-Z" |
|
− | "Also stop on numbers. |
+ | " Also stop on numbers. |
− | + | let g:camelchar = "A-Z0-9" |
|
− | "Include '.' for class member, ',' for separator, ';' end-statement, |
+ | " Include '.' for class member, ',' for separator, ';' end-statement, |
− | "and <[< bracket starts and "'` quotes. |
+ | " and <[< bracket starts and "'` quotes. |
− | + | let g:camelchar = "A-Z0-9.,;:{([`'\"" |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | ==Alternatives== |
||
− | nnoremap <silent><C-Left> :<C-u>cal search('\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%^','bW')<CR> |
||
+ | The {{script|id=1905|text=camelcasemotion}} script is based on this tip, but much refined and enhanced. It can move through both CamelCase and underscore_notation words. It provides configurable mappings for normal mode, operator-pending mode and visual mode, plus a corresponding "inner" text object. -- [[User:Inkarkat|Inkarkat]] 12:12, 5 April 2009 (UTC) |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | </pre> |
||
==Comments== |
==Comments== |
||
− | I believe that the pattern should start with \C, to force case sensitivity, as so: |
||
− | <pre> |
||
⚫ | |||
− | </pre> |
||
+ | This is nice but what I am looking for is motions that work with other commands like v,y,d,c etc. |
||
− | ---- |
||
− | My addition for visual mode (you need to enter visual mode first) |
||
− | <pre> |
||
⚫ | |||
⚫ | |||
− | </pre> |
||
+ | :Try adapting them to use <code>:onoremap</code> for operator-pending mode. --[[User:Fritzophrenic|Fritzophrenic]] ([[User talk:Fritzophrenic|talk]]) 21:27, April 19, 2016 (UTC) |
||
− | ---- |
Revision as of 21:27, 19 April 2016
created 2005 · complexity basic · author Anthony Van Ham, Gerald Lai · version 6.0
Some programs use CamelCaseWords (or camelCaseWords). The following maps allow you to move word by word, for example, from the 'C' of Camel, to the 'C' of Case, to the 'W' of Words. Some alternate versions are given, starting with something simple and more easily understood.
Simple move
nnoremap <C-Left> :call search('\<\<Bar>\u', 'bW')<CR> nnoremap <C-Right> :call search('\<\<Bar>\u', 'W')<CR> inoremap <C-Left> <C-o>:call search('\<\<Bar>\u', 'bW')<CR> inoremap <C-Right> <C-o>:call search('\<\<Bar>\u', 'W')<CR>
Better handling of all-uppercase words
Here is a more thorough version. It does not go through a CAPITALIZED word one character at a time.
nnoremap <silent><C-Left> :<C-u>call search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%^','bW')<CR> nnoremap <silent><C-Right> :<C-u>call search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%$','W')<CR> inoremap <silent><C-Left> <C-o>:call search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%^','bW')<CR> inoremap <silent><C-Right> <C-o>:call search('\<\<Bar>\U\@<=\u\<Bar>\u\ze\%(\U\&\>\@!\)\<Bar>\%$','W')<CR>
Enhanced version
With the following, the cursor will stop at:
- The beginning of a word.
- The beginning of a run of camel characters.
- A camel character followed by a run of non-camel characters.
- The start and end of the file.
" Use one of the following to define the camel characters. " Stop on capital letters. let g:camelchar = "A-Z" " Also stop on numbers. let g:camelchar = "A-Z0-9" " Include '.' for class member, ',' for separator, ';' end-statement, " and <[< bracket starts and "'` quotes. let g:camelchar = "A-Z0-9.,;:{([`'\"" nnoremap <silent><C-Left> :<C-u>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%^','bW')<CR> nnoremap <silent><C-Right> :<C-u>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%$','W')<CR> inoremap <silent><C-Left> <C-o>:call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%^','bW')<CR> inoremap <silent><C-Right> <C-o>:call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%$','W')<CR> vnoremap <silent><C-Left> :<C-U>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%^','bW')<CR>v`>o vnoremap <silent><C-Right> <Esc>`>:<C-U>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%$','W')<CR>v`<o
Alternatives
The camelcasemotion script is based on this tip, but much refined and enhanced. It can move through both CamelCase and underscore_notation words. It provides configurable mappings for normal mode, operator-pending mode and visual mode, plus a corresponding "inner" text object. -- Inkarkat 12:12, 5 April 2009 (UTC)
Comments
This is nice but what I am looking for is motions that work with other commands like v,y,d,c etc.
- Try adapting them to use
:onoremap
for operator-pending mode. --Fritzophrenic (talk) 21:27, April 19, 2016 (UTC)