1
0
mirror of https://github.com/amix/vimrc synced 2025-06-23 06:35:01 +08:00

Updated vim plugins. Nerd tree is on the right by default

This commit is contained in:
amix
2015-02-13 00:19:27 +00:00
parent a4b4587019
commit 00f043f0de
25 changed files with 386 additions and 109 deletions

View File

@ -32,6 +32,7 @@ To see what keystrokes are used for the above example, see [this issue](https://
## 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 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.

View File

@ -54,6 +54,11 @@ if !hlexists(s:hi_group_visual)
exec "highlight link ".s:hi_group_visual." Visual"
endif
" Temporary buffer that is used for individual paste buffer save/restore
" operations
let s:paste_buffer_temporary_text = ''
let s:paste_buffer_temporary_type = ''
"===============================================================================
" Internal Mappings
"===============================================================================
@ -258,6 +263,9 @@ function! s:Cursor.new(position)
let obj = copy(self)
let obj.position = copy(a:position)
let obj.visual = []
" Stores text that was yanked after any commands in Normal or Visual mode
let obj.paste_buffer_text = getreg('"')
let obj.paste_buffer_type = getregtype('"')
let obj.cursor_hi_id = s:highlight_cursor(a:position)
let obj.visual_hi_id = 0
let obj.line_length = col([a:position[0], '$'])
@ -325,6 +333,17 @@ function! s:Cursor.remove_visual_selection() dict
let self.visual_hi_id = 0
endfunction
" Restore unnamed register from paste buffer
function! s:Cursor.restore_unnamed_register() dict
call setreg('"', self.paste_buffer_text, self.paste_buffer_type)
endfunction
" Save contents of the unnamed register into paste buffer
function! s:Cursor.save_unnamed_register() dict
let self.paste_buffer_text = getreg('"')
let self.paste_buffer_type = getregtype('"')
endfunction
"===============================================================================
" CursorManager class
"===============================================================================
@ -345,6 +364,7 @@ function! s:CursorManager.new()
\ 'cursorline': &cursorline,
\ 'lazyredraw': &lazyredraw,
\ 'paste': &paste,
\ 'clipboard': &clipboard,
\ }
" We save the window view when multicursor mode is entered
let obj.saved_winview = []
@ -465,9 +485,17 @@ function! s:CursorManager.update_current() dict
exec "normal! gv\<Esc>"
call cur.update_visual_selection(s:get_visual_region(s:pos('.')))
elseif s:from_mode ==# 'v' || s:from_mode ==# 'V'
" Save contents of unnamed register after each operation in Visual mode.
" This should be executed after user input is processed, when unnamed
" register already contains the text.
call cur.save_unnamed_register()
call cur.remove_visual_selection()
elseif s:from_mode ==# 'i' && s:to_mode ==# 'n' && self.current_index != self.size() - 1
normal! h
elseif s:from_mode ==# 'n'
" Save contents of unnamed register after each operation in Normal mode.
call cur.save_unnamed_register()
endif
let vdelta = line('$') - s:saved_linecount
" If the total number of lines changed in the buffer, we need to potentially
@ -551,19 +579,28 @@ endfunction
" cursors on screen
" paste mode needs to be switched off since it turns off a bunch of features
" that's critical for the plugin to function
" clipboard should not have unnamed and unnamedplus otherwise plugin cannot
" reliably use unnamed register ('"')
function! s:CursorManager.initialize() dict
let self.saved_settings['virtualedit'] = &virtualedit
let self.saved_settings['cursorline'] = &cursorline
let self.saved_settings['lazyredraw'] = &lazyredraw
let self.saved_settings['paste'] = &paste
let self.saved_settings['clipboard'] = &clipboard
let &virtualedit = "onemore"
let &cursorline = 0
let &lazyredraw = 1
let &paste = 0
set clipboard-=unnamed clipboard-=unnamedplus
" We could have already saved the view from multiple_cursors#find
if !self.start_from_find
let self.saved_winview = winsaveview()
endif
" Save contents and type of unnamed register upon entering multicursor mode
" to restore it later when leaving mode
let s:paste_buffer_temporary_text = getreg('"')
let s:paste_buffer_temporary_type = getregtype('"')
endfunction
" Restore user settings.
@ -573,7 +610,15 @@ function! s:CursorManager.restore_user_settings() dict
let &cursorline = self.saved_settings['cursorline']
let &lazyredraw = self.saved_settings['lazyredraw']
let &paste = self.saved_settings['paste']
let &clipboard = self.saved_settings['clipboard']
endif
" Restore original contents and type of unnamed register. This method is
" called from reset, which calls us only when restore_setting argument is
" true, which happens only when we leave multicursor mode. This should be
" symmetrical to saving of unnamed register upon the start of multicursor
" mode.
call setreg('"', s:paste_buffer_temporary_text, s:paste_buffer_temporary_type)
endfunction
" Reselect the current cursor's region in visual mode
@ -814,6 +859,12 @@ function! s:process_user_input()
call s:cm.get_current().update_line_length()
let s:saved_linecount = line('$')
" Restore unnamed register only in Normal mode. This should happen before user
" input is processed.
if s:from_mode ==# 'n' || s:from_mode ==# 'v' || s:from_mode ==# 'V'
call s:cm.get_current().restore_unnamed_register()
endif
" Apply the user input. Note that the above could potentially change mode, we
" use the mapping below to help us determine what the new mode is
" Note that it's possible that \<Plug>(multiple-cursors-apply) never gets called, we have a

View File

@ -12,6 +12,7 @@ def get_file_content()
end
def before(string)
options.each { |x| vim.command(x) }
set_file_content(string)
end
@ -29,8 +30,198 @@ def type(string)
end
end
describe "Multiple Cursors op pending & exit from insert|visual mode" do
let(:filename) { 'test.txt' }
let(:options) { ['let g:multi_cursor_normal_maps = {"d": 1, "c": 1}',
'let g:multi_cursor_exit_from_insert_mode = 0',
'let g:multi_cursor_exit_from_visual_mode = 0'] }
specify "#paste from unnamed register to 3 cursors" do
before <<-EOF
yankme
a b c
a b c
a b c
EOF
type 'yiwj<C-n><C-n><C-n>vwwp<Esc>'
after <<-EOF
yankme
a b cyankme
a b cyankme
a b cyankme
EOF
end
specify "#paste buffer normal caw then p" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vwcaw<Esc>bP<Esc>'
after <<-EOF
jan hello world
feb hello world
mar hello world
EOF
end
specify "#paste buffer normal C then ABC then p" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vwCABC <Esc>p<Esc>'
after <<-EOF
hello ABC jan world
hello ABC feb world
hello ABC mar world
EOF
end
specify "#paste buffer normal daw then P" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vwdawbP<Esc>'
after <<-EOF
jan hello world
feb hello world
mar hello world
EOF
end
specify "#paste buffer normal D then P" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vwwhDbhP<Esc>'
after <<-EOF
hello world jan
hello world feb
hello world mar
EOF
end
specify "#paste buffer normal s then p" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vws1<Esc>p<Esc>'
after <<-EOF
hello 1jan world
hello 1feb world
hello 1mar world
EOF
end
end
describe "Multiple Cursors" do
let(:filename) { 'test.txt' }
let(:options) { [] }
specify "#paste buffer normal x then p" do
before <<-EOF
jan
feb
mar
EOF
type '<C-v>jj<C-n>xp<Esc>'
after <<-EOF
ajn
efb
amr
EOF
end
specify "#paste buffer visual y then p" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vwvelywhp<Esc>'
after <<-EOF
hello jan jan world
hello feb feb world
hello mar mar world
EOF
end
specify "#paste buffer initial visual y then P" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type 'wywb<C-n><C-n><C-n>p<Esc>'
after <<-EOF
jan jan world
jan feb world
jan mar world
EOF
end
specify "#paste buffer visual y then P" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vwvely^P<Esc>'
after <<-EOF
jan hello jan world
feb hello feb world
mar hello mar world
EOF
end
specify "#paste buffer visual Y then P" do
before <<-EOF
hello jan world
hello feb world
hello mar world
EOF
type '<C-n><C-n><C-n>vwvY^P<Esc>'
after <<-EOF
hello jan world
hello jan world
hello feb world
hello feb world
hello mar world
hello mar world
EOF
end
specify "#multiline replacement" do
before <<-EOF

View File

@ -5,7 +5,7 @@ Vimrunner::RSpec.configure do |config|
# Use a single Vim instance for the test suite. Set to false to use an
# instance per test (slower, but can be easier to manage).
config.reuse_server = true
config.reuse_server = false
# Decide how to start a Vim instance. In this block, an instance should be
# spawned and set up with anything project-specific.