mirror of
https://github.com/amix/vimrc
synced 2025-06-23 06:35:01 +08:00
Updated plugins
This commit is contained in:
@ -2,144 +2,110 @@
|
||||
[](https://travis-ci.org/terryma/vim-multiple-cursors)
|
||||
[](http://issuestats.com/github/terryma/vim-multiple-cursors)
|
||||
[](http://issuestats.com/github/terryma/vim-multiple-cursors)
|
||||
|
||||
## Contents
|
||||
- [About](#about)
|
||||
- [Features](#features)
|
||||
- [Installation](#installation)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Mapping](#mapping)
|
||||
- [Settings](#settings)
|
||||
- [Interactions with other plugins](#interactions-with-other-plugins)
|
||||
- [Highlight](#highlight)
|
||||
- *[FAQ](#faq)*
|
||||
- *[Known issues](#known-issues)*
|
||||
- *[Issue creation requirements](#issue-creation-requirements)*
|
||||
- [Changelog](#changelog)
|
||||
- [FAQ](#faq)
|
||||
- [Contributing](#contributing)
|
||||
- [Credit](#credit)
|
||||
|
||||
### Contributors
|
||||
- [eapache](https://github.com/eapache)
|
||||
- [aschrab](https://github.com/aschrab)
|
||||
- [kristijanhusak](https://github.com/kristijanhusak)
|
||||
- [faceleg](https://github.com/faceleg)
|
||||
|
||||
## About
|
||||
[There](https://github.com/paradigm/vim-multicursor) [have](https://github.com/felixr/vim-multiedit) [been](https://github.com/hlissner/vim-multiedit) [many](https://github.com/adinapoli/vim-markmultiple) [attempts](https://github.com/AndrewRadev/multichange.vim) at bringing Sublime Text's awesome [multiple selection][sublime-multiple-selection] feature into Vim, but none so far have been in my opinion a faithful port that is simplistic to use, yet powerful and intuitive enough for an existing Vim user. [vim-multiple-cursors] is yet another attempt at that.
|
||||
|
||||
### It's great for quick refactoring
|
||||

|
||||
|
||||
Vim command sequence: `2Gfp<C-n><C-n><C-n>cname`
|
||||
Vim command sequence: `fp<C-n><C-n><C-n>cname`
|
||||
|
||||
### Add a cursor to each line of your visual selection
|
||||

|
||||
|
||||
Vim command sequence: `2Gvip<C-n>i"<Right><Right><Right>",<Esc>vipgJ$r]Idays = [`
|
||||
Vim command sequence: `vip<C-n>i"<Right><Right><Right>",<Esc>vipgJ$r]Idays = [`
|
||||
|
||||
### Do it backwards too! This is not just a replay of the above gif :)
|
||||
### Match characters from visual selection
|
||||

|
||||
|
||||
Vim command sequence: `2Gdf[$r,0f,v<C-n>…<C-n>c<CR><Up><Del><Right><Right><Right><Del>`
|
||||
Vim command sequence: `df[$r,0f,v<C-n>…<C-n>c<CR><Up><Del><Right><Right><Right><Del>`
|
||||
|
||||
### Add multiple cursors using regexes
|
||||
### Use the command to match regexp
|
||||

|
||||
|
||||
To see what keystrokes are used for the above examples, see [the wiki page](https://github.com/terryma/vim-multiple-cursors/wiki/Keystrokes-for-example-gifs).
|
||||
|
||||
## Features
|
||||
- Live update in Insert mode
|
||||
- One key to rule it all! See [Quick Start](#quick-start) on what the key does in different scenarios
|
||||
- Works in Normal, Insert, and Visual mode for any commands (including
|
||||
multi-key commands, assuming you set `g:multicursor_normal_maps`;
|
||||
see Settings below for details)
|
||||
|
||||
## Installation
|
||||
Install using [Pathogen], [Vundle], [Neobundle], or your favorite Vim package manager.
|
||||
|
||||
Requires vim 7.4 or later for full functionality.
|
||||
|
||||
## Quick Start
|
||||
Out of the box, all you need to know is a single key `Ctrl-n`. Pressing the key in Normal mode highlights the current word under the cursor in Visual mode and places a virtual cursor at the end of it. Pressing it again finds the next occurrence and places another virtual cursor at the end of the visual selection. If you select multiple lines in Visual mode, pressing the key puts a virtual cursor at every line and leaves you in Normal mode.
|
||||
### normal mode / visual mode
|
||||
* start: `<C-n>` start multicursor and add a _virtual cursor + selection_ on the match
|
||||
* next: `<C-n>` add a new _virtual cursor + selection_ on the next match
|
||||
* skip: `<C-x>` skip the next match
|
||||
* prev: `<C-p>` remove current _virtual cursor + selection_ and go back on previous match
|
||||
* select all: `<A-n>` start muticursor and directly select all matches
|
||||
|
||||
After you've marked all your locations with `Ctrl-n`, you can change the visual selection with normal Vim motion commands in Visual mode. You could go to Normal mode by pressing `v` and wield your motion commands there. Single key command to switch to Insert mode such as `c` or `s` from Visual mode or `i`, `a`, `I`, `A` in Normal mode should work without any issues.
|
||||
You can now change the _virtual cursors + selection_ with **visual mode** commands.
|
||||
For instance: `c`, `s`, `I`, `A` work without any issues.
|
||||
You could also go to **normal mode** by pressing `v` and use normal commands there.
|
||||
|
||||
At any time, you can press `<Esc>` to exit back to regular Vim.
|
||||
|
||||
Two additional keys are also mapped:
|
||||
- `Ctrl-p` in Visual mode will remove the current virtual cursor and go back to the previous virtual cursor location. This is useful if you are trigger happy with `Ctrl-n` and accidentally went too far.
|
||||
- `Ctrl-x` in Visual mode will remove the current virtual cursor and skip to the next virtual cursor location. This is useful if you don't want the current selection to be a candidate to operate on later.
|
||||
**NOTE**: start with `g<C-n>` to match without boundaries (behaves like `g*` instead of `*`)
|
||||
|
||||
You can also add multiple cursors using a regular expression. The command `MultipleCursorsFind` accepts a range and a pattern, and it will create a virtual cursor at the end of every match within the range. If no range is passed in, then it defaults to the entire buffer.
|
||||
### visual mode when multiple lines are selected
|
||||
* start: `<C-n>` add _virtual cursors_ on each line
|
||||
|
||||
You can now change the _virtual cursors_ with **normal mode** commands.
|
||||
For instance: `ciw`.
|
||||
|
||||
### command
|
||||
The command `MultipleCursorsFind` accepts a range and a pattern (regexp), it creates a _visual cursor_ at the end of each match.
|
||||
If no range is passed in, then it defaults to the entire buffer.
|
||||
|
||||
**NOTE:** If at any time you have lingering cursors on screen, you can press `Ctrl-n` in Normal mode and it will remove all prior cursors before starting a new one.
|
||||
|
||||
## Mapping
|
||||
Out of the box, only the single key `Ctrl-n` is mapped in regular Vim's Normal mode and Visual mode to provide the functionality mentioned above. `Ctrl-n`, `Ctrl-p`, `Ctrl-x`, and `<Esc>` are mapped in the special multicursor mode once you've added at least one virtual cursor to the buffer. If you don't like the plugin taking over your favorite key bindings, you can turn off the default with
|
||||
If you don't like the plugin taking over your key bindings, you can turn it off and reassign them the way you want:
|
||||
```viml
|
||||
let g:multi_cursor_use_default_mapping=0
|
||||
```
|
||||
|
||||
You can then map the 'next', 'previous', 'skip', and 'exit' keys like the following:
|
||||
```viml
|
||||
" Default mapping
|
||||
let g:multi_cursor_next_key='<C-n>'
|
||||
let g:multi_cursor_prev_key='<C-p>'
|
||||
let g:multi_cursor_skip_key='<C-x>'
|
||||
let g:multi_cursor_quit_key='<Esc>'
|
||||
let g:multi_cursor_start_word_key = '<C-n>'
|
||||
let g:multi_cursor_select_all_word_key = '<A-n>'
|
||||
let g:multi_cursor_start_key = 'g<C-n>'
|
||||
let g:multi_cursor_select_all_key = 'g<A-n>'
|
||||
let g:multi_cursor_next_key = '<C-n>'
|
||||
let g:multi_cursor_prev_key = '<C-p>'
|
||||
let g:multi_cursor_skip_key = '<C-x>'
|
||||
let g:multi_cursor_quit_key = '<Esc>'
|
||||
```
|
||||
|
||||
By default, the 'next' key is also used to enter multicursor mode. If you want to use a different key to start multicursor mode than for selecting the next location, do like the following:
|
||||
```viml
|
||||
" Map start key separately from next key
|
||||
let g:multi_cursor_start_key='<F6>'
|
||||
```
|
||||
|
||||
Note that when multicursor mode is started, it selects current word with boundaries, i.e. it behaves like `*`. If you want to avoid word boundaries in Normal mode (as `g*` does) but still have old behaviour up your sleeve, you can do the following:
|
||||
```viml
|
||||
let g:multi_cursor_start_key='<C-n>'
|
||||
let g:multi_cursor_start_word_key='g<C-n>'
|
||||
```
|
||||
In this configuration `<C-n>` will start multicursor mode without word boundaries (but only in Normal mode, as it does not make much sense to use it in Visual mode). Old behaviour with word boundaries is still available using `g<C-n>`.
|
||||
|
||||
**IMPORTANT:** Please note that currently only single keystrokes and special keys can be mapped. This means that a mapping like `<Leader>n` will NOT work correctly. For a list of special keys that are supported, see `help :key-notation`
|
||||
|
||||
**NOTE:** Please make sure to always map something to `g:multi_cursor_quit_key`, otherwise you'll have a tough time quitting from multicursor mode.
|
||||
|
||||
**NOTE:** Prior to version 1.3, the recommended way to map the keys is using the expression quote syntax in Vim, using something like `"\<C-n>"` or `"\<Esc>"` (see h: expr-quote). After 1.3, the recommended way is to use a raw string like above. If your key mappings don't appear to work, give the new syntax a try.
|
||||
|
||||
You can also map your own keys to quit, if ``g:multi_cursor_quit_key`` won't work:
|
||||
|
||||
```
|
||||
let g:multi_cursor_quit_key='<C-c>'
|
||||
nnoremap <C-c> :call multiple_cursors#quit()<CR>
|
||||
```
|
||||
|
||||
## Settings
|
||||
Currently there are four additional global settings one can tweak:
|
||||
|
||||
### ```g:multi_cursor_exit_from_visual_mode``` (Default: 1)
|
||||
If set to 0, then pressing `g:multi_cursor_quit_key` in _Visual_ mode will not quit and delete all existing cursors. This is useful if you want to press Escape and go back to Normal mode, and still be able to operate on all the cursors.
|
||||
If set to 0, then pressing `g:multi_cursor_quit_key` in _Visual_ mode will not quit and delete all existing cursors.
|
||||
Useful if you want to go back to Normal mode, and still be able to operate on all the cursors.
|
||||
|
||||
### ```g:multi_cursor_exit_from_insert_mode``` (Default: 1)
|
||||
If set to 0, then pressing `g:multi_cursor_quit_key` in _Insert_ mode will not quit and delete all existing cursors. This is useful if you want to press Escape and go back to Normal mode, and still be able to operate on all the cursors.
|
||||
If set to 0, then pressing `g:multi_cursor_quit_key` in _Insert_ mode will not quit and delete all existing cursors.
|
||||
Useful if you want to go back to Normal mode, and still be able to operate on all the cursors.
|
||||
|
||||
### ```g:multi_cursor_normal_maps``` (Default: see below)
|
||||
Default value: `{'!':1, '@':1, '=':1, 'q':1, 'r':1, 't':1, 'T':1, 'y':1, '[':1, ']':1, '\':1, 'd':1, 'f':1, 'F':1, 'g':1, '"':1, 'z':1, 'c':1, 'm':1, '<':1, '>':1}`
|
||||
`{'@': 1, 'F': 1, 'T': 1, '[': 1, '\': 1, ']': 1, '!': 1, '"': 1, 'c': 1, 'd': 1, 'f': 1, 'g': 1, 'm': 1, 'q': 1, 'r': 1, 't': 1, 'y': 1, 'z': 1, '<': 1, '=': 1, '>': 1}`
|
||||
|
||||
Any key in this map (values are ignored) will cause multi-cursor _Normal_ mode
|
||||
to pause for map completion just like normal vim. Otherwise keys mapped in
|
||||
normal mode will "fail to replay" when multiple cursors are active. For example,
|
||||
changing it from `{}` to `{'d':1}` makes normal-mode mappings beginning with `d`
|
||||
(such as `dw` to delete a word) work in multi-cursor mode.
|
||||
|
||||
### ```g:multi_cursor_visual_maps``` (Default: see below)
|
||||
Default value: `{'i':1, 'a':1, 'f':1, 'F':1, 't':1, 'T':1}`
|
||||
|
||||
Any key in this map (values are ignored) will cause multi-cursor _Visual_ mode
|
||||
to pause for map completion just like normal vim. Otherwise keys mapped in
|
||||
visual mode will "fail to replay" when multiple cursors are active. For example,
|
||||
changing it from `{}` to `{'i':1}` makes visual-mode mappings beginning with `i`
|
||||
(such as `it` to select an "inner tag block") work in multi-cursor mode.
|
||||
normal mode will "fail to replay" when multiple cursors are active.
|
||||
For example: `{'d':1}` makes normal-mode command `dw` work in multi-cursor mode.
|
||||
|
||||
The default list contents should work for anybody, unless they have remapped a
|
||||
key from an operator-pending command to a non-operator-pending command or
|
||||
@ -149,27 +115,28 @@ These keys must be manually listed because vim doesn't provide a way to
|
||||
automatically see which keys _start_ mappings, and trying to run motion commands
|
||||
such as `j` as if they were operator-pending commands can break things.
|
||||
|
||||
### ```g:multi_cursor_visual_maps``` (Default: see below)
|
||||
`{'T': 1, 'a': 1, 't': 1, 'F': 1, 'f': 1, 'i': 1}`
|
||||
|
||||
Same principle as `g:multi_cursor_normal_maps`
|
||||
|
||||
### Interactions with other plugins
|
||||
|
||||
### ```Multiple_cursors_before/Multiple_cursors_after``` (Default: `nothing`)
|
||||
|
||||
Other plugins may trigger on keypresses when in insert mode. These plugins
|
||||
generally provide a means to toggle their active state. These hooks allow
|
||||
the user to provide functions in their .vimrc to do this when multiple-cursor-mode
|
||||
is entered.
|
||||
Other plugins may be incompatible in insert mode.
|
||||
That is why we provide hooks to disable those plug-ins when vim-multiple-cursors is active:
|
||||
|
||||
For example, if you are using [Neocomplete](https://github.com/Shougo/neocomplete.vim),
|
||||
add this to your vimrc to prevent conflict:
|
||||
|
||||
```viml
|
||||
" Called once right before you start selecting multiple cursors
|
||||
function! Multiple_cursors_before()
|
||||
if exists(':NeoCompleteLock')==2
|
||||
exe 'NeoCompleteLock'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Called once only when the multiple selection is canceled (default <Esc>)
|
||||
function! Multiple_cursors_after()
|
||||
if exists(':NeoCompleteUnlock')==2
|
||||
exe 'NeoCompleteUnlock'
|
||||
@ -177,8 +144,6 @@ function! Multiple_cursors_after()
|
||||
endfunction
|
||||
```
|
||||
|
||||
With this locking and unlocking we prevent neocomplete to trigger it's function calls until we are finished with multiple cursors editing.
|
||||
|
||||
Plugins themselves can register `User` autocommands on `MultipleCursorsPre` and
|
||||
`MultipleCursorsPost` for automatic integration.
|
||||
|
||||
@ -193,12 +158,27 @@ highlight link multiple_cursors_visual Visual
|
||||
|
||||
## FAQ
|
||||
|
||||
#### **Q** <kbd>CTRL</kbd>+<kbd>n</kbd> doesn't seem to work in gVIM?
|
||||
#### **Q** <kbd>ALT</kbd>+<kbd>n</kbd> doesn't seem to work in VIM but works in gVIM, why?
|
||||
**A** This is a well known terminal/Vim [issue](http://vim.wikia.com/wiki/Get_Alt_key_to_work_in_terminal), different terminal have different ways to send ```Alt+key```.
|
||||
Try adding this in your `.vimrc` and **make sure to replace the string**:
|
||||
```vim
|
||||
if !has('gui_running')
|
||||
map "in Insert mode, type Ctrl+v Alt+n here" <A-n>
|
||||
endif
|
||||
```
|
||||
Or remap the following:
|
||||
```vim
|
||||
g:multi_cursor_start_key
|
||||
g:multi_cursor_select_all_key
|
||||
```
|
||||
|
||||
#### **Q** <kbd>CTRL</kbd>+<kbd>n</kbd> doesn't seem to work in gVIM?
|
||||
**A** Try setting `set selection=inclusive` in your `~/.gvimrc`
|
||||
|
||||
#### **Q** How can I select `n` keywords with several keystrokes? I have tried `200<C-n>` which does not work.
|
||||
#### **Q** is it also working on Mac?
|
||||
**A** On Mac OS, [MacVim](https://code.google.com/p/macvim/) is known to work.
|
||||
|
||||
#### **Q** How can I select `n` keywords with several keystrokes? `200<C-n>` does not work.
|
||||
**A** You can use :MultipleCursorsFind keyword. I have this binding in my vimrc:
|
||||
|
||||
```VimL
|
||||
@ -206,23 +186,24 @@ nnoremap <silent> <M-j> :MultipleCursorsFind <C-R>/<CR>
|
||||
vnoremap <silent> <M-j> :MultipleCursorsFind <C-R>/<CR>
|
||||
```
|
||||
|
||||
This allows one to a) search for the keyword using `*` b) turn search results into cursors with `Alt-j`.
|
||||
This allows one to search for the keyword using `*` and turn search results into cursors with `Alt-j`.
|
||||
|
||||
## Known Issues
|
||||
- Select mode is not implemented
|
||||
|
||||
## Issue Creation Requirements
|
||||
|
||||
This is a community supported project. Contributor's time is precious and limited. To ensure your issue is not closed out of hand, please ensure it meets the requirements outlined in [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||
|
||||
## Changelog
|
||||
See [CHANGELOG.md](CHANGELOG.md)
|
||||
|
||||
## Contributing
|
||||
As one can see, there're still many issues to be resolved, patches and suggestions are always welcome! A list of open feature requests can be found [here](../../issues?labels=enhancement&state=open).
|
||||
Patches and suggestions are always welcome! A list of open feature requests can be found [here](https://github.com/terryma/vim-multiple-cursors/labels/pull%20request%20welcome).
|
||||
|
||||
Running the test suite requires ruby and rake as well as vim of course. On Mac
|
||||
OS, [MacVim](https://code.google.com/p/macvim/) is known to work.
|
||||
### Issue Creation
|
||||
Contributor's time is precious and limited. Please ensure it meets the requirements outlined in [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||
|
||||
### Pull Requests
|
||||
Running the test suite requires ruby and rake as well as vim of course. Before submitting PR, please ensure the checks are passing:
|
||||
```bash
|
||||
cd vim-multiple-cursors/spec/
|
||||
bundle exec rake
|
||||
```
|
||||
|
||||
### Contributors
|
||||
This is a community supported project. Here is the list of all the [Contributors](https://github.com/terryma/vim-multiple-cursors/graphs/contributors)
|
||||
|
||||
## Credit
|
||||
Obviously inspired by Sublime Text's [multiple selection][sublime-multiple-selection] feature, also encouraged by Emac's [multiple cursors][emacs-multiple-cursors] implementation by Magnar Sveen
|
||||
@ -233,6 +214,3 @@ Obviously inspired by Sublime Text's [multiple selection][sublime-multiple-selec
|
||||
[Vundle]:http://github.com/gmarik/vundle
|
||||
[Neobundle]:http://github.com/Shougo/neobundle.vim
|
||||
[emacs-multiple-cursors]:https://github.com/magnars/multiple-cursors.el
|
||||
|
||||
|
||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 177 KiB |
@ -283,6 +283,22 @@ function! multiple_cursors#find(start, end, pattern)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" apply multiple_cursors#find() on the whole buffer
|
||||
function! multiple_cursors#select_all(mode, word_boundary)
|
||||
if a:mode == 'v'
|
||||
let a_save = @a
|
||||
normal! gv"ay
|
||||
let pattern = @a
|
||||
let @a = a_save
|
||||
elseif a:mode == 'n'
|
||||
let pattern = expand('<cword>')
|
||||
endif
|
||||
if a:word_boundary == 1
|
||||
let pattern = '\<'.pattern.'\>'
|
||||
endif
|
||||
call multiple_cursors#find(1, line('$'), pattern)
|
||||
endfunction
|
||||
|
||||
"===============================================================================
|
||||
" Cursor class
|
||||
"===============================================================================
|
||||
@ -1044,8 +1060,8 @@ endfunction
|
||||
|
||||
" Wrapper around getchar() that returns the string representation of the user
|
||||
" input
|
||||
function! s:get_char()
|
||||
let c = getchar()
|
||||
function! s:get_char(...)
|
||||
let c = (a:0 == 0) ? getchar() : getchar(a:1)
|
||||
" If the character is a number, then it's not a special key
|
||||
if type(c) == 0
|
||||
let c = nr2char(c)
|
||||
@ -1056,7 +1072,7 @@ endfunction
|
||||
" Quits multicursor mode and clears all cursors. Return true if exited
|
||||
" successfully.
|
||||
function! s:exit()
|
||||
if s:last_char() !=# g:multi_cursor_quit_key
|
||||
if s:char !=# g:multi_cursor_quit_key
|
||||
return 0
|
||||
endif
|
||||
let exit = 0
|
||||
@ -1179,6 +1195,10 @@ function! s:end_latency_measure()
|
||||
let s:skip_latency_measure = 0
|
||||
endfunction
|
||||
|
||||
function! s:get_time_in_ms()
|
||||
return str2nr(substitute(reltimestr(reltime()), '\.\(...\).*', '\1', ''))
|
||||
endfunction
|
||||
|
||||
function! s:last_char()
|
||||
return s:char[len(s:char)-1]
|
||||
endfunction
|
||||
@ -1215,17 +1235,9 @@ function! s:wait_for_user_input(mode)
|
||||
" imap jjj JJJ
|
||||
" will always trigger the 'jj' mapping
|
||||
if s:from_mode ==# 'i' && mapcheck(s:char, "i") != ""
|
||||
let poll_count = 0
|
||||
let map_dict = {}
|
||||
while poll_count < &timeoutlen
|
||||
let c = getchar(0)
|
||||
let char_type = type(c)
|
||||
let poll_count += 1.5
|
||||
if char_type == 0 && c != 0
|
||||
let s:char .= nr2char(c)
|
||||
elseif char_type == 1 " char with more than 8 bits (as string)
|
||||
let s:char .= c
|
||||
endif
|
||||
let s_time = s:get_time_in_ms()
|
||||
while 1
|
||||
let map_dict = maparg(s:char, "i", 0, 1)
|
||||
" break if chars exactly match mapping or if chars don't match beging of mapping anymore
|
||||
if map_dict != {} || mapcheck(s:char, "i") == ""
|
||||
@ -1233,13 +1245,20 @@ function! s:wait_for_user_input(mode)
|
||||
" handle case where {rhs} is a function
|
||||
exec 'let char_mapping = ' . map_dict['rhs']
|
||||
else
|
||||
let char_mapping = get(map_dict, 'rhs', s:char)
|
||||
let char_mapping = maparg(s:char, "i")
|
||||
endif
|
||||
" handle case where mapping is <esc>
|
||||
exec 'let s:char = "'.substitute(char_mapping, '<', '\\<', 'g').'"'
|
||||
break
|
||||
endif
|
||||
sleep 1m
|
||||
if s:get_time_in_ms() > (s_time + &timeoutlen)
|
||||
break
|
||||
endif
|
||||
let new_char = s:get_char(0)
|
||||
let s:char .= new_char
|
||||
if new_char == ''
|
||||
sleep 50m
|
||||
endif
|
||||
endwhile
|
||||
elseif s:from_mode !=# 'i' && s:char[0] ==# ":"
|
||||
call feedkeys(s:char)
|
||||
@ -1264,13 +1283,42 @@ function! s:wait_for_user_input(mode)
|
||||
" Clears any echoes we might've added
|
||||
normal! :<Esc>
|
||||
|
||||
" add chars to s:char if it start like a special/quit key
|
||||
let is_special_key = 0
|
||||
let sk_list = get(s:special_keys, s:from_mode, [])
|
||||
let is_special_key = (index(sk_list, s:char) != -1)
|
||||
let is_quit_key = 0
|
||||
let s_time = s:get_time_in_ms()
|
||||
while 1
|
||||
let start_special_key = (index(map(sk_list[:], 'v:val[0:len(s:char)-1] == s:char'), 1) > -1)
|
||||
let start_quit_key = (g:multi_cursor_quit_key[0:len(s:char)-1] == s:char)
|
||||
if start_special_key == 0 && start_quit_key == 0
|
||||
break
|
||||
else
|
||||
let is_special_key = (index(sk_list, s:char) != -1)
|
||||
let is_quit_key = (g:multi_cursor_quit_key == s:char)
|
||||
if is_special_key == 1 || is_quit_key == 1
|
||||
break
|
||||
else
|
||||
if s:get_time_in_ms() > (s_time + &timeoutlen)
|
||||
break
|
||||
endif
|
||||
let new_char = s:get_char(0)
|
||||
let s:char .= new_char
|
||||
if new_char == ''
|
||||
sleep 50m
|
||||
endif
|
||||
endif
|
||||
end
|
||||
endwhile
|
||||
|
||||
if s:exit()
|
||||
return
|
||||
endif
|
||||
|
||||
" If the key is a special key and we're in the right mode, handle it
|
||||
if index(get(s:special_keys, s:from_mode, []), s:last_char()) != -1
|
||||
call s:handle_special_key(s:last_char(), s:from_mode)
|
||||
if is_special_key == 1
|
||||
call s:handle_special_key(s:char, s:from_mode)
|
||||
call s:skip_latency_measure()
|
||||
else
|
||||
call s:cm.start_loop()
|
||||
|
@ -18,11 +18,13 @@ CONTENTS *multiple-cursors-contents*
|
||||
2.Usage...................................|multiple-cursors-usage|
|
||||
3.Mappings................................|multiple-cursors-mappings|
|
||||
4.Global Options..........................|multiple-cursors-global-options|
|
||||
5.Issues..................................|multiple-cursors-issues|
|
||||
6.Contributing............................|multiple-cursors-contributing|
|
||||
7.License.................................|multiple-cursors-license|
|
||||
8.Credit..................................|multiple-cursors-credit|
|
||||
9.References..............................|multiple-cursors-references|
|
||||
5.Interactions with other plugins.........|multiple-cursors-other-plugins|
|
||||
6.Highlight...............................|multiple-cursors-highlight|
|
||||
7.FAQ.....................................|multiple-cursors-faq|
|
||||
8.Contributing............................|multiple-cursors-contributing|
|
||||
9.License.................................|multiple-cursors-license|
|
||||
10.Credit..................................|multiple-cursors-credit|
|
||||
11.References..............................|multiple-cursors-references|
|
||||
|
||||
==============================================================================
|
||||
1. Intro *multiple-cursors-intro*
|
||||
@ -36,108 +38,57 @@ another attempt at that.
|
||||
==============================================================================
|
||||
2. Usage *multiple-cursors-usage*
|
||||
|
||||
Out of the box, all you need to know is a single key CTRL-N. Pressing the key
|
||||
in Normal mode highlights the current word under the cursor in Visual mode and
|
||||
places a virtual cursor at the end of it. Pressing it again finds the next
|
||||
ocurrence and places another virtual cursor at the end of the visual
|
||||
selection. If you select multiple lines in Visual mode, pressing the key puts
|
||||
a virtual cursor at every line and leaves you in Normal mode.
|
||||
normal mode / visual mode~
|
||||
|
||||
After you've marked all your locations with CTRL-N, you can change the visual
|
||||
selection with normal Vim motion commands in Visual mode. You could go to
|
||||
Normal mode by pressing v and wield your motion commands there. Single key
|
||||
command to switch to Insert mode such as `c` or `s` from Visual mode or `i`,
|
||||
`a`, `I`, `A` in Normal mode should work without any issues.
|
||||
- start: `<C-n>` start multicursor and add a virtual cursor + visual selection on the match
|
||||
+ next: `<C-n>` add a new virtual cursor + visual selection on the next match
|
||||
+ skip: `<C-x>` skip the next match
|
||||
+ prev: `<C-p>` remove current virtual cursor + visual selection and go back on previous match
|
||||
- select all: `<A-n>` start muticursor and directly select all matches
|
||||
|
||||
At any time, you can press <Esc> to exit back to regular Vim.
|
||||
You can now change the virtual cursors + visual selection with |visual-mode| commands.
|
||||
For instance: `c`, `s`, `I`, `A` work without any issues.
|
||||
You could also go to |normal-mode| by pressing `v` and use normal commands there.
|
||||
|
||||
Two additional keys are also mapped:
|
||||
At any time, you can press `<Esc>` to exit back to regular Vim.
|
||||
|
||||
CTRL-P in Visual mode will remove the current virtual cursor and go back to
|
||||
the previous virtual cursor location. This is useful if you are trigger happy
|
||||
with Ctrl-n and accidentally went too far.
|
||||
NOTE: start with `g<C-n>` to match without boundaries (behaves like `g*` instead of `*`, see |gstar|)
|
||||
|
||||
CTRL-X in Visual mode will remove the current virtual cursor and skip to the
|
||||
next virtual cursor location. This is useful if you don't want the current
|
||||
selection to be a candidate to operate on later.
|
||||
visual mode when multiple lines are selected~
|
||||
|
||||
You can also add multiple cursors using a regular expression. The command
|
||||
*MultipleCursorsFind* accepts a range and a pattern, and it will create a
|
||||
virtual cursor at the end of every match within the range. If no range is
|
||||
passed in, then it defaults to the entire buffer.
|
||||
- start: `<C-n>` add virtual cursors on each line
|
||||
|
||||
NOTE: If at any time you have lingering cursors on screen, you can press
|
||||
CTRL-N in Normal mode and it will remove all prior cursors before starting a
|
||||
new one.
|
||||
You can now change the virtual cursors with |normal-mode| commands.
|
||||
For instance: `ciw`.
|
||||
|
||||
command~
|
||||
|
||||
The command `MultipleCursorsFind` accepts a range and a pattern (regexp), it
|
||||
creates a visual cursor at the end of each match.
|
||||
If no range is passed in, then it defaults to the entire buffer.
|
||||
|
||||
==============================================================================
|
||||
3. Mappings *multiple-cursors-mappings*
|
||||
|
||||
*g:multi_cursor_use_default_mapping* (Default: 1)
|
||||
|
||||
Out of the box, only the single key CTRL-N is mapped in regular Vim's Normal
|
||||
mode and Visual mode to provide the functionality mentioned above. CTRL-N,
|
||||
CTRL-P, CTRL-X, and <ESC> are mapped in the special multicursor mode once
|
||||
you've added at least one virtual cursor to the buffer. If you don't like the
|
||||
plugin taking over your favorite key bindings, you can turn off the default
|
||||
with >
|
||||
If you don't like the plugin taking over your favorite key bindings, you can
|
||||
turn off the default with >
|
||||
|
||||
let g:multi_cursor_use_default_mapping=0
|
||||
<
|
||||
|
||||
*g:multi_cursor_next_key* (Default: '<C-n>')
|
||||
*g:multi_cursor_prev_key* (Default: '<C-p>')
|
||||
*g:multi_cursor_skip_key* (Default: '<C-x>')
|
||||
*g:multi_cursor_quit_key* (Default: '<Esc>')
|
||||
You can map the 'next', 'previous', 'skip', and 'exit' keys like the
|
||||
following: >
|
||||
|
||||
" Default mapping
|
||||
let g:multi_cursor_next_key='<C-n>'
|
||||
let g:multi_cursor_prev_key='<C-p>'
|
||||
let g:multi_cursor_skip_key='<C-x>'
|
||||
let g:multi_cursor_quit_key='<Esc>'
|
||||
let g:multi_cursor_start_word_key = '<C-n>'
|
||||
let g:multi_cursor_select_all_word_key = '<A-n>'
|
||||
let g:multi_cursor_start_key = 'g<C-n>'
|
||||
let g:multi_cursor_select_all_key = 'g<A-n>'
|
||||
let g:multi_cursor_next_key = '<C-n>'
|
||||
let g:multi_cursor_prev_key = '<C-p>'
|
||||
let g:multi_cursor_skip_key = '<C-x>'
|
||||
let g:multi_cursor_quit_key = '<Esc>'
|
||||
<
|
||||
|
||||
*g:multi_cursor_start_key* (Default: 'g:multi_cursor_next_key')
|
||||
By default, the same key is used to enter multicursor mode as to select the
|
||||
next cursor location. If you want to use a different key to start multicursor
|
||||
mode than for selecting the next location, do like the following: >
|
||||
|
||||
" Map start key separately from next key
|
||||
let g:multi_cursor_start_key='<F6>'
|
||||
<
|
||||
|
||||
*g:multi_cursor_start_word_key*
|
||||
When multicursor mode is started, it selects current word without
|
||||
boundaries, i.e. it behaves like `g*`. If you want to use word boundaries in
|
||||
Normal mode (as `*` does) but still have old behaviour up your sleeve, you can
|
||||
do the following: >
|
||||
|
||||
let g:multi_cursor_start_key='g<C-n>'
|
||||
let g:multi_cursor_start_word_key='<C-n>'
|
||||
<
|
||||
|
||||
In this configuration <C-n> will start multicursor mode using word boundaries
|
||||
(but only in Normal mode, as it does not make much sense to use it in Visual
|
||||
mode). Old behaviour without word boundaries is still available using
|
||||
g<C-n>.
|
||||
|
||||
IMPORTANT: Please note that currently only single keystrokes and special
|
||||
keys can be mapped. This contraint is also the reason why multikey commands
|
||||
such as `ciw` do not work and cause unexpected behavior in Normal mode. This
|
||||
means that a mapping like `<Leader>n` will NOT work correctly. For a list of
|
||||
special keys that are supported, see |key-notation|
|
||||
|
||||
NOTE: Please make sure to always map something to |g:multi_cursor_quit_key|,
|
||||
otherwise you'll have a tough time quitting from multicursor mode.
|
||||
|
||||
NOTE: Prior to version 1.3, the recommended way to map the keys is using the
|
||||
expression quote syntax in Vim, using something like `"\<C-n>"` or `"\<Esc>"`
|
||||
(see h: expr-quote). After 1.3, the recommended way is to use a raw string
|
||||
like above. If your key mappings don't appear to work, give the new syntax a
|
||||
try.
|
||||
|
||||
==============================================================================
|
||||
4. Global Options *multiple-cursors-global-options*
|
||||
|
||||
@ -145,37 +96,24 @@ Currently there are four additional global settings one can tweak:
|
||||
|
||||
*g:multi_cursor_exit_from_visual_mode* (Default: 1)
|
||||
|
||||
If set to 0, then pressing |g:multi_cursor_quit_key| in Visual mode will not
|
||||
quit and delete all existing cursors. This is useful if you want to press
|
||||
Escape and go back to Normal mode, and still be able to operate on all the
|
||||
cursors.
|
||||
If set to 0, then pressing |g:multi_cursor_quit_key| in |visual-mode| will not
|
||||
quit and delete all existing cursors. Useful if you want to go back to
|
||||
|normal-mode|, and still be able to operate on all the cursors.
|
||||
|
||||
*g:multi_cursor_exit_from_insert_mode* (Default: 1)
|
||||
|
||||
If set to 0, then pressing |g:multi_cursor_quit_key| in Insert mode will not
|
||||
quit and delete all existing cursors. This is useful if you want to press
|
||||
Escape and go back to Normal mode, and still be able to operate on all the
|
||||
cursors.
|
||||
If set to 0, then pressing |g:multi_cursor_quit_key| in |insert-mode| will not
|
||||
quit and delete all existing cursors. Useful if you want to go back to Normal
|
||||
mode, and still be able to operate on all the cursors.
|
||||
|
||||
*g:multi_cursor_normal_maps* (Default: see below)
|
||||
|
||||
Default value: `{'!':1, '@':1, '=':1, 'q':1, 'r':1, 't':1, 'T':1, 'y':1, '[':1, ']':1, '\':1, 'd':1, 'f':1, 'F':1, 'g':1, '"':1, 'z':1, 'c':1, 'm':1, '<':1, '>':1}`
|
||||
`{'@': 1, 'F': 1, 'T': 1, '[': 1, '\': 1, ']': 1, '!': 1, '"': 1, 'c': 1, 'd': 1, 'f': 1, 'g': 1, 'm': 1, 'q': 1, 'r': 1, 't': 1, 'y': 1, 'z': 1, '<': 1, '=': 1, '>': 1}`
|
||||
|
||||
Any key in this map (values are ignored) will cause multi-cursor _Normal_ mode
|
||||
to pause for map completion just like normal vim. Otherwise keys mapped in
|
||||
normal mode will "fail to replay" when multiple cursors are active. For example,
|
||||
changing it from `{}` to `{'d':1}` makes normal-mode mappings beginning with `d`
|
||||
(such as `dw` to delete a word) work in multi-cursor mode.
|
||||
|
||||
*g:multi_cursor_visual_maps* (Default: )
|
||||
|
||||
Default value: `{'i':1, 'a':1, 'f':1, 'F':1, 't':1, 'T':1}`
|
||||
|
||||
Any key in this map (values are ignored) will cause multi-cursor _Visual_ mode
|
||||
to pause for map completion just like normal vim. Otherwise keys mapped in
|
||||
visual mode will "fail to replay" when multiple cursors are active. For example,
|
||||
changing it from `{}` to `{'i':1}` makes visual-mode mappings beginning with `i`
|
||||
(such as `it` to select an "inner tag block") work in multi-cursor mode.
|
||||
normal mode will "fail to replay" when multiple cursors are active. For
|
||||
example: `{'d':1}` makes normal-mode command `dw` work in multi-cursor mode.
|
||||
|
||||
The default list contents should work for anybody, unless they have remapped a
|
||||
key from an operator-pending command to a non-operator-pending command or
|
||||
@ -185,30 +123,75 @@ These keys must be manually listed because vim doesn't provide a way to
|
||||
automatically see which keys _start_ mappings, and trying to run motion commands
|
||||
such as `j` as if they were operator-pending commands can break things.
|
||||
|
||||
*g:multi_cursor_visual_maps* (Default: )
|
||||
|
||||
`{'T': 1, 'a': 1, 't': 1, 'F': 1, 'f': 1, 'i': 1}`
|
||||
|
||||
Same principle as |g:multi_cursor_normal_maps|
|
||||
|
||||
==============================================================================
|
||||
5. Interactions with other plugins *multiple-cursors-other-plugins*
|
||||
|
||||
Other plugins may be incompatible in insert mode. That is why we provide
|
||||
hooks to disable those plug-ins when vim-multiple-cursors is active:
|
||||
|
||||
For example, if you are using `Neocomplete`, add this to your vimrc to prevent
|
||||
conflict:
|
||||
>
|
||||
function! Multiple_cursors_before()
|
||||
if exists(':NeoCompleteLock')==2
|
||||
exe 'NeoCompleteLock'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! Multiple_cursors_after()
|
||||
if exists(':NeoCompleteUnlock')==2
|
||||
exe 'NeoCompleteUnlock'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
Plugins themselves can register |User| |autocommand| on `MultipleCursorsPre` and
|
||||
`MultipleCursorsPost` for automatic integration.
|
||||
|
||||
==============================================================================
|
||||
6. Highlight *multiple-cursors-highlight*
|
||||
>
|
||||
The plugin uses the highlight group `multiple_cursors_cursor` and
|
||||
`multiple_cursors_visual` to highlight the virtual cursors and their visual
|
||||
selections respectively. You can customize them by putting something similar
|
||||
like the following in your vimrc: >
|
||||
|
||||
" Default highlighting (see help :highlight and help :highlight-link)
|
||||
highlight multiple_cursors_cursor term=reverse cterm=reverse gui=reverse
|
||||
highlight link multiple_cursors_visual Visual
|
||||
|
||||
<
|
||||
==============================================================================
|
||||
7. FAQ *multiple-cursors-faq*
|
||||
|
||||
Q: <A-n> doesn't seem to work in VIM but works in gVIM, why?
|
||||
A: This is a well known terminal/Vim [9], different terminal have different
|
||||
ways to send `Alt+key`. Try adding this in your `.vimrc` and make sure
|
||||
to replace the string: >
|
||||
if !has('gui_running')
|
||||
map "in Insert mode, type Ctrl+v Alt+n here" <A-n>
|
||||
endif
|
||||
Or remap the following: >
|
||||
g:multi_cursor_start_key
|
||||
g:multi_cursor_select_all_key
|
||||
|
||||
Q: <C-n> doesn't seem to work in gVIM?
|
||||
A: Try setting `set selection=inclusive` in your `~/.gvimrc`
|
||||
|
||||
Q: is it also working on Mac?
|
||||
A: On Mac OS, MacVim[10] is known to work.
|
||||
|
||||
Q: How can I select `n` keywords with several keystrokes? `200<C-n>` does not work.
|
||||
A: You can use :MultipleCursorsFind keyword. I have this binding in my vimrc: >
|
||||
nnoremap <silent> <M-j> :MultipleCursorsFind <C-R>/<CR>
|
||||
vnoremap <silent> <M-j> :MultipleCursorsFind <C-R>/<CR>
|
||||
This allows one to search for the keyword using `*` and turn search results into cursors with `Alt-j`.
|
||||
|
||||
==============================================================================
|
||||
5. Issues *multiple-cursors-issues*
|
||||
|
||||
- Multi key commands like ciw do not work at the moment
|
||||
- All user input typed before Vim is able to fan out the last operation to all
|
||||
cursors is lost. This is a implementation decision to keep the input
|
||||
perfectly synced in all locations, at the cost of potentially losing user
|
||||
input.
|
||||
- Select mode is not implemented
|
||||
|
||||
==============================================================================
|
||||
6. Contributing *multiple-cursors-contributing*
|
||||
8. Contributing *multiple-cursors-contributing*
|
||||
|
||||
The project is hosted on Github. Patches, feature requests and suggestions are
|
||||
always welcome!
|
||||
@ -217,19 +200,19 @@ Find the latest version of the plugin here:
|
||||
http://github.com/terryma/vim-multiple-cursors
|
||||
|
||||
==============================================================================
|
||||
7. License *multiple-cursors-license*
|
||||
9. License *multiple-cursors-license*
|
||||
|
||||
The project is licensed under the MIT license [7]. Copyrigth 2013 Terry Ma
|
||||
The project is licensed under the MIT license [7]. Copyright 2013 Terry Ma
|
||||
|
||||
==============================================================================
|
||||
8. Credit *multiple-cursors-credit*
|
||||
10. Credit *multiple-cursors-credit*
|
||||
|
||||
The plugin is obviously inspired by Sublime Text's awesome multiple selection
|
||||
[6] feature. Some inspiration was also taken from Emac's multiple cursors [8]
|
||||
implementation.
|
||||
|
||||
==============================================================================
|
||||
9. References *multiple-cursors-references*
|
||||
10. References *multiple-cursors-references*
|
||||
|
||||
[1] https://github.com/paradigm/vim-multicursor
|
||||
[2] https://github.com/felixr/vim-multiedit
|
||||
@ -239,5 +222,7 @@ implementation.
|
||||
[6] http://www.sublimetext.com/docs/2/multiple_selection_with_the_keyboard.html
|
||||
[7] http://opensource.org/licenses/MIT
|
||||
[8] https://github.com/magnars/multiple-cursors.el
|
||||
[9] http://vim.wikia.com/wiki/Get_Alt_key_to_work_in_terminal
|
||||
[10] https://code.google.com/p/macvim
|
||||
|
||||
vim:tw=78:sw=4:ft=help:norl:
|
||||
|
@ -34,10 +34,14 @@ let s:settings = {
|
||||
\ }
|
||||
|
||||
let s:settings_if_default = {
|
||||
\ 'quit_key': '<Esc>',
|
||||
\ 'next_key': '<C-n>',
|
||||
\ 'prev_key': '<C-p>',
|
||||
\ 'skip_key': '<C-x>',
|
||||
\ 'quit_key': '<Esc>',
|
||||
\ 'start_key': 'g<C-n>',
|
||||
\ 'start_word_key': '<C-n>',
|
||||
\ 'next_key': '<C-n>',
|
||||
\ 'prev_key': '<C-p>',
|
||||
\ 'skip_key': '<C-x>',
|
||||
\ 'select_all_key': 'g<A-n>',
|
||||
\ 'select_all_word_key': '<A-n>',
|
||||
\ }
|
||||
|
||||
let s:default_normal_maps = {'!':1, '@':1, '=':1, 'q':1, 'r':1, 't':1, 'T':1, 'y':1, '[':1, ']':1, '\':1, 'd':1, 'f':1, 'F':1, 'g':1, '"':1, 'z':1, 'c':1, 'm':1, '<':1, '>':1}
|
||||
@ -55,9 +59,7 @@ if g:multi_cursor_use_default_mapping
|
||||
endif
|
||||
|
||||
if !exists('g:multi_cursor_start_word_key')
|
||||
if exists('g:multi_cursor_start_key')
|
||||
let g:multi_cursor_start_word_key = g:multi_cursor_start_key
|
||||
elseif exists('g:multi_cursor_next_key')
|
||||
if exists('g:multi_cursor_next_key')
|
||||
let g:multi_cursor_start_word_key = g:multi_cursor_next_key
|
||||
endif
|
||||
endif
|
||||
@ -78,6 +80,21 @@ if exists('g:multi_cursor_start_word_key')
|
||||
\' :<C-u>call multiple_cursors#new("v", 0)<CR>'
|
||||
endif
|
||||
|
||||
if exists('g:multi_cursor_select_all_key')
|
||||
exec 'nnoremap <silent> '.g:multi_cursor_select_all_key.
|
||||
\' :call multiple_cursors#select_all("n", 0)<CR>'
|
||||
exec 'xnoremap <silent> '.g:multi_cursor_select_all_key.
|
||||
\' :<C-u>call multiple_cursors#select_all("v", 0)<CR>'
|
||||
endif
|
||||
|
||||
if exists('g:multi_cursor_select_all_word_key')
|
||||
exec 'nnoremap <silent> '.g:multi_cursor_select_all_word_key.
|
||||
\' :call multiple_cursors#select_all("n", 1)<CR>'
|
||||
" In Visual mode word boundary is not used
|
||||
exec 'xnoremap <silent> '.g:multi_cursor_select_all_word_key.
|
||||
\' :<C-u>call multiple_cursors#select_all("v", 0)<CR>'
|
||||
endif
|
||||
|
||||
" Commands
|
||||
command! -nargs=1 -range=% MultipleCursorsFind
|
||||
\ call multiple_cursors#find(<line1>, <line2>, <q-args>)
|
||||
|
@ -172,7 +172,7 @@ end
|
||||
|
||||
describe "Multiple Cursors when using insert mapings" do
|
||||
let(:filename) { 'test.txt' }
|
||||
let(:options) { ['imap jj <esc>', 'imap jojo dude'] }
|
||||
let(:options) { ['set timeoutlen=10000', 'imap jj <esc>', 'imap jojo dude'] }
|
||||
specify "#mapping doing <Esc>" do
|
||||
before <<-EOF
|
||||
hello world!
|
||||
|
Reference in New Issue
Block a user