- Notifications
You must be signed in to change notification settings - Fork244
True Sublime Text style multiple selections for Vim
License
terryma/vim-multiple-cursors
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
❗ This plugin is deprecated, usevim-visual-multi instead ❗
- About
- Installation
- Quick Start
- Mapping
- Settings
- Interactions with other plugins
- Highlight
- FAQ
- Contributing
- Credit
Therehavebeenmanyattempts at bringing Sublime Text's awesomemultiple 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.
Vim command sequence:fp<C-n><C-n><C-n>cname
Vim command sequence:vip<C-n>i"<Right><Right><Right>",<Esc>vipgJ$r]Idays = [
Vim command sequence:df[$r,0f,v<C-n>…<C-n>c<CR><Up><Del><Right><Right><Right><Del>
To see what keystrokes are used for the above examples, seethe wiki page.
Install usingPathogen,Vundle,Neobundle,vim-plug, or your favorite Vim package manager.
Requires vim 7.4 or newer for full functionality.
- Paste this block into the top of
~/.vimrc
.
callplug#begin()Plug'terryma/vim-multiple-cursors'callplug#end()
- Start vim and execute
:PlugInstall
.
- start:
<C-n>
start multicursor and add avirtual cursor + selection on the match- next:
<C-n>
add a newvirtual cursor + selection on the next match - skip:
<C-x>
skip the next match - prev:
<C-p>
remove currentvirtual cursor + selection and go back on previous match
- next:
- select all:
<A-n>
start multicursor and directly select all matches
You can now change thevirtual cursors + selection withvisual mode commands.For instance:c
,s
,I
,A
work without any issues.You could also go tonormal mode by pressingv
and use normal commands there.
At any time, you can press<Esc>
to exit back to regular Vim.
NOTE: start withg<C-n>
to match without boundaries (behaves likeg*
instead of*
)
- start:
<C-n>
addvirtual cursors on each line
You can now change thevirtual cursors withnormal mode commands.For instance:ciw
.
The commandMultipleCursorsFind
accepts a range and a pattern (regexp), it creates avisual cursor at the end of each match.If no range is passed in, then it defaults to the entire buffer.
If you don't like the plugin taking over your key bindings, you can turn it off and reassign them the way you want:
letg:multi_cursor_use_default_mapping=0" Default mappingletg:multi_cursor_start_word_key='<C-n>'letg:multi_cursor_select_all_word_key='<A-n>'letg:multi_cursor_start_key='g<C-n>'letg:multi_cursor_select_all_key='g<A-n>'letg:multi_cursor_next_key='<C-n>'letg:multi_cursor_prev_key='<C-p>'letg:multi_cursor_skip_key='<C-x>'letg:multi_cursor_quit_key='<Esc>'
NOTE: Please make sure to always map something tog:multi_cursor_quit_key
, otherwise you'll have a tough time quitting from multicursor mode.
Currently there are four additional global settings one can tweak:
If set to 0, insert mappings won't be supported inInsert mode anymore.
If set to 1, then pressingg:multi_cursor_quit_key
inVisual mode will quit anddelete all existing cursors, just skipping normal mode with multiple cursors.
If set to 1, then pressingg:multi_cursor_quit_key
inInsert mode will quit anddelete all existing cursors, just skipping normal mode with multiple cursors.
{'@': 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-cursorNormal modeto pause for map completion just like normal vim. Otherwise keys mapped innormal mode will "fail to replay" when multiple cursors are active.For example:{'d':1}
makes normal-mode commanddw
work in multi-cursor mode.
The default list contents should work for anybody, unless they have remapped akey from an operator-pending command to a non-operator-pending command orvice versa.
These keys must be manually listed because vim doesn't provide a way toautomatically see which keysstart mappings, and trying to run motion commandssuch asj
as if they were operator-pending commands can break things.
{'T': 1, 'a': 1, 't': 1, 'F': 1, 'f': 1, 'i': 1}
Same principle asg:multi_cursor_normal_maps
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 usingNeocomplete,add this to your vimrc to prevent conflict:
function!Multiple_cursors_before()ifexists(':NeoCompleteLock')==2exe'NeoCompleteLock'endifendfunctionfunction!Multiple_cursors_after()ifexists(':NeoCompleteUnlock')==2exe'NeoCompleteUnlock'endifendfunction
Plugins themselves can registerUser
autocommands onMultipleCursorsPre
andMultipleCursorsPost
for automatic integration.
The plugin uses the highlight groupmultiple_cursors_cursor
andmultiple_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_cursorterm=reverse cterm=reversegui=reversehighlightlinkmultiple_cursors_visualVisual
A When selecting words withC-n, the plugin behaves like invisual mode.Once you pressedi, you can still pressI to insert text.
A This is a well known terminal/Vimissue, different terminal have different ways to sendAlt+key
.Try adding this in your.vimrc
andmake sure to replace the string:
if!has('gui_running')map"inInsert mode, type Ctrl+v Alt+n here"<A-n>endif
Or remap the following:
g:multi_cursor_start_keyg:multi_cursor_select_all_key
A Try settingset selection=inclusive
in your~/.gvimrc
A Alternatively, you can just temporarily disableexclusive selection whenever the plugin is active:
augroupMultipleCursorsSelectionFixautocmdUserMultipleCursorsPreif &selection==#'exclusive' |letg:multi_cursor_save_selection= &selection |setselection=inclusive |endifautocmdUserMultipleCursorsPostifexists('g:multi_cursor_save_selection') |let &selection=g:multi_cursor_save_selection |unletg:multi_cursor_save_selection |endifaugroupEND
A use theMultiple_cursors
functions, add this in your vimrc:
func!Multiple_cursors_before()ifdeoplete#is_enabled()calldeoplete#disable()letg:deoplete_is_enable_before_multi_cursors=1elseletg:deoplete_is_enable_before_multi_cursors=0endifendfuncfunc!Multiple_cursors_after()ifg:deoplete_is_enable_before_multi_cursorscalldeoplete#enable()endifendfunc
A On Mac OS,MacVim is known to 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 withAlt-j
.
Patches and suggestions are always welcome! A list of open feature requests can be foundhere.
Contributor's time is precious and limited. Please ensure it meets the requirements outlined inCONTRIBUTING.md.
Running the test suite requires ruby and rake as well as vim of course. Before submitting PR, please ensure the checks are passing:
cd vim-multiple-cursors/spec/bundleexec rake
This is a community supported project. Here is the list of all theContributors
Obviously inspired by Sublime Text'smultiple selection feature, also encouraged by Emac'smultiple cursors implementation by Magnar Sveen
About
True Sublime Text style multiple selections for Vim
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.