Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

True Sublime Text style multiple selections for Vim

License

NotificationsYou must be signed in to change notification settings

terryma/vim-multiple-cursors

Repository files navigation

vim-multiple-cursors

Build Status

Contents

About

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.

It's great for quick refactoring

Example1

Vim command sequence:fp<C-n><C-n><C-n>cname

Add a cursor to each line of your visual selection

Example2

Vim command sequence:vip<C-n>i"<Right><Right><Right>",<Esc>vipgJ$r]Idays = [

Match characters from visual selection

Example3

Vim command sequence:df[$r,0f,v<C-n>…<C-n>c<CR><Up><Del><Right><Right><Right><Del>

Use the command to match regexp

Example4

To see what keystrokes are used for the above examples, seethe wiki page.

Installation

Install usingPathogen,Vundle,Neobundle,vim-plug, or your favorite Vim package manager.

Requires vim 7.4 or newer for full functionality.

vim-plug instructions

  1. Paste this block into the top of~/.vimrc.
callplug#begin()Plug'terryma/vim-multiple-cursors'callplug#end()
  1. Start vim and execute:PlugInstall.

Quick Start

normal mode / visual mode

  • 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
  • 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*)

visual mode when multiple lines are selected

  • start:<C-n> addvirtual cursors on each line

You can now change thevirtual cursors withnormal mode commands.For instance:ciw.

command

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.

Mapping

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.

Settings

Currently there are four additional global settings one can tweak:

g:multi_cursor_support_imap (Default: 1)

If set to 0, insert mappings won't be supported inInsert mode anymore.

g:multi_cursor_exit_from_visual_mode (Default: 0)

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.

g:multi_cursor_exit_from_insert_mode (Default: 0)

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.

g:multi_cursor_normal_maps (Default: see below)

{'@': 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.

g:multi_cursor_visual_maps (Default: see below)

{'T': 1, 'a': 1, 't': 1, 'F': 1, 'f': 1, 'i': 1}

Same principle asg:multi_cursor_normal_maps

Interactions with other plugins

Multiple_cursors_before/Multiple_cursors_after (Default:nothing)

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.

Highlight

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

FAQ

Q Pressingi after selecting words withC-n makes the plugin hang, why?

A When selecting words withC-n, the plugin behaves like invisual mode.Once you pressedi, you can still pressI to insert text.

QALT+n doesn't seem to work in VIM but works in gVIM, why?

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

QCTRL+n doesn't seem to work in gVIM?

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

Q deoplete insert giberrish, how to fix this?

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

Q is it also working on Mac?

A On Mac OS,MacVim is known to work.

Q How can I selectn 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 withAlt-j.

Contributing

Patches and suggestions are always welcome! A list of open feature requests can be foundhere.

Issue Creation

Contributor's time is precious and limited. Please ensure it meets the requirements outlined inCONTRIBUTING.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:

cd vim-multiple-cursors/spec/bundleexec rake

Contributors

This is a community supported project. Here is the list of all theContributors

Credit

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

Stars

Watchers

Forks

Packages

No packages published

Contributors36


[8]ページ先頭

©2009-2025 Movatter.jp