aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--autoload/novim_mode.vim20
-rw-r--r--doc/novim_mode.txt9
-rw-r--r--spec/novim_mode_spec.rb168
-rw-r--r--spec/spec_helper.rb23
5 files changed, 175 insertions, 54 deletions
diff --git a/README.md b/README.md
index 55ec3fd..5034923 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,7 @@ inoremap <C-P> <C-O>:CtrlP<CR>
```
Overriding or disabling shortcuts in this plugin can be done in several ways. The simplest way is to use:
-```
+```vim
let g:novim_mode_use_shortcuts = 0
inoremap ... custom mapping ...
call novim_mode#StartNoVimMode()
@@ -102,8 +102,7 @@ let g:novim_mode_use_better_wrap_navigation = 1
Lastly you can unmap a mapping using commands such as `nunmap`, `iunmap`, `sunmap`, etc.
### Known issues
- * There seems to be a bug where only `SHIFT+TAB` and not `TAB` works for indenting during selection mode. Again this may be fixed by simulating selection mode with Visual mode in the future.
- * When using `novim_mode_use_better_wrap_navigation`, then END key does not go the end of a visual line, but to the end of the physically represented line.
- * Mapping `<CTRL+m>` internally means mapping `<RETURN>`. This is a throwback to Vim's days as a pure terminal application.
- * `CTRL+BACKSPACE` internally represents <CTRL+H>, which can be annoying. Again this is a throwback to Vim's days as a pure terminal application.
+ * There seems to be a bug where only `SHIFT+TAB` and not `TAB` works for indenting during selection mode.
+ * Mapping `<CTRL+M>` internally means mapping `<RETURN>`. This is a throwback to Vim's days as a pure terminal application.
+ * `CTRL+BACKSPACE` internally represents `<CTRL+H>`, which can be annoying. Again this is a throwback to Vim's days as a pure terminal application.
diff --git a/autoload/novim_mode.vim b/autoload/novim_mode.vim
index af5c76a..549210e 100644
--- a/autoload/novim_mode.vim
+++ b/autoload/novim_mode.vim
@@ -101,8 +101,18 @@ function! g:SetNoVimModeShortcuts()
" General fixes to editor behaviour
if g:novim_mode_use_editor_fixes == 1
- " Fix HOME to go back to the first non-whitespace character of the line
- inoremap <silent> <Home> <C-O>^
+ " All thee `g`s here make these also work for wrapped lines.
+
+ " Fix HOME to go back to the first non-whitespace character of the line.
+ inoremap <silent> <Home> <C-O>g^
+ " Native End would work anyway but it needs the `g` for wrapped lines
+ inoremap <silent> <End> <C-O>g$
+
+ " For selection behaviour
+ inoremap <silent> <S-Home> <S-Left><C-G><C-O>g^
+ snoremap <silent> <S-Home> <C-O>g^
+ inoremap <silent> <S-End> <S-Right><C-G><C-O>g$
+ snoremap <silent> <S-End> <C-O>g$
" Tweaks PageUp behaviour to get cursor to first line on top page
inoremap <silent> <PageUp> <C-O>:call novim_mode#PageUp()<CR>
@@ -224,11 +234,13 @@ function! s:SetWrappedTextNavigation()
" Make arrow keys move through wrapped lines
" TODO:
- " * Make END key move to end of current wrapped piece of line.
- " * Scroll window 1 wrapped soft line at a time rather an entire block of wrapped
+ " * Scroll window 1 wrapped soft line at a time rather than entire block of wrapped
" lines.
au BufNewFile,BufRead *.txt,*.md,*.markdown inoremap <buffer> <Up> <C-O>gk
au BufNewFile,BufRead *.txt,*.md,*.markdown inoremap <buffer> <Down> <C-O>gj
+ " For selection behaviour
+ au BufNewFile,BufRead *.txt,*.md,*.markdown snoremap <buffer> <S-Up> <C-O>gk
+ au BufNewFile,BufRead *.txt,*.md,*.markdown snoremap <buffer> <S-Down> <C-O>gj
endfunction
" Try to intuitively and intelligently close things like buffers, splits,
diff --git a/doc/novim_mode.txt b/doc/novim_mode.txt
index 3758f49..f249308 100644
--- a/doc/novim_mode.txt
+++ b/doc/novim_mode.txt
@@ -107,7 +107,7 @@ Undoing
Other text manipulation tricks
* `CTRL+LEFT/RIGHT`: Move cursor per word (works in selection as well).
- * `CTRL+ALT+k`: Delete current line.
+ * `CTRL+ALT+d`: Delete current line.
* `CTRL+ALT+k`: Duplicate current line.
* `CTRL+UP/DOWN`: Move current line or selected text up/down.
@@ -155,12 +155,9 @@ following: >
* There seems to be a bug where only `SHIFT+TAB` and not `TAB` works for
indenting during selection mode. Again this may be fixed by simulating
selection mode with Visual mode in the future.
- * When using `novim_mode_use_better_wrap_navigation`, then END key does not
- go the end of a visual line, but to the end of the physically represented
- line.
- * Mapping `<CTRL+m>` internally means mapping `<RETURN>`. This is a
+ * Mapping `<CTRL+M>` internally means mapping `<RETURN>`. This is a
throwback to Vim's days as a pure terminal application.
- * `CTRL+BACKSPACE` internally represents <CTRL+H>, which can be annoying.
+ * `CTRL+BACKSPACE` internally represents `<CTRL+H>`, which can be annoying.
Again this is a throwback to Vim's days as a pure terminal application.
==============================================================================
diff --git a/spec/novim_mode_spec.rb b/spec/novim_mode_spec.rb
index 15c993f..a3d603c 100644
--- a/spec/novim_mode_spec.rb
+++ b/spec/novim_mode_spec.rb
@@ -2,78 +2,69 @@
# of testing Vim.
require 'spec_helper'
-TEST_FILE = 'test_file.txt'.freeze
-
-def write_file_content(string)
- string = normalize_string_indent(string)
- File.open(TEST_FILE, 'w') { |f| f.write(string) }
- vim.edit TEST_FILE
-end
-
-def load_file_content
- vim.write
- IO.read(TEST_FILE).strip
-end
-
-def before(string)
- options.each { |x| vim.command(x) } if options
+def initial(string)
+ @vim_options.each { |x| vim.command(x) } if @vim_options
write_file_content(string)
end
-def after(string)
+def final(string)
expect(load_file_content).to eq normalize_string_indent(string)
end
-def type(string)
- string.scan(/<.*?>|./).each do |key|
- if key =~ /<.*>/
- vim.feedkeys "\\#{key}"
- else
- vim.feedkeys key
- end
- end
-end
-
describe 'Basic editing' do
- let(:options) {}
-
specify 'writing simple text' do
- before <<-EOF
+ initial <<-EOF
EOF
type 'hello world'
- after <<-EOF
+ final <<-EOF
hello world
EOF
end
+ specify '<Home> goes to first non-whitespace char' do
+ initial <<-EOF
+ justified
+ indented
+ EOF
+
+ type '<Down><End><Home>!'
+
+ final <<-EOF
+ justified
+ !indented
+ EOF
+ end
+
specify 'copy and paste' do
- before <<-EOF
+ initial <<-EOF
copy me
EOF
- type '<S-End><C-c><Right><C-v>'
+ type '<S-End><C-c><Esc><Space><C-v>'
- after <<-EOF
+ final <<-EOF
copy me copy me
EOF
end
+end
+describe 'Selecting' do
specify 'select all and replace' do
- before <<-EOF
+ initial <<-EOF
select me
EOF
type '<C-a>gone'
- after <<-EOF
+ final <<-EOF
gone
EOF
end
specify 'paste over selection' do
- before <<-EOF
+ initial <<-EOF
cut me and paste over me
EOF
@@ -83,15 +74,114 @@ describe 'Basic editing' do
7.times { type '<S-Right>' }
type '<C-v>'
- after <<-EOF
+ final <<-EOF
and paste cut me
EOF
end
+
+ specify 'selecting from middle of line to end' do
+ initial <<-EOF
+ a line of text
+ EOF
+
+ 6.times { type '<Right>' }
+ type '<S-End>'
+ type '!'
+
+ final <<-EOF
+ a line!
+ EOF
+ end
+
+ specify 'selecting from middle of line to beginning' do
+ initial <<-EOF
+ a line of text
+ EOF
+
+ 7.times { type '<Right>' }
+ type '<S-Home>'
+ type '!'
+
+ final <<-EOF
+ !of text
+ EOF
+ end
end
-describe 'Pane control' do
- let(:options) {}
+describe 'Wrapped text' do
+ before(:each) do
+ @vim_options = [
+ # A single buffer can't be resized, so create a split of the buffer
+ 'vsplit',
+ 'vertical resize 6'
+ ]
+ end
+
+ specify 'move up/down one wrapped line' do
+ initial <<-EOF
+ line line line line
+ EOF
+
+ type '<Down><Down>down '
+ type '<Up>up '
+
+ final <<-EOF
+ line line up down line line
+ EOF
+ end
+
+ specify 'select wrapped line below' do
+ initial <<-EOF
+ line1 line2 line3 line4
+ EOF
+
+ type '<Down><S-Down><S-Down>'
+ type '!'
+ final <<-EOF
+ line1 !line3 line4
+ EOF
+ end
+
+ specify 'select wrapped line above' do
+ initial <<-EOF
+ line1 line2 line3 line4
+ EOF
+
+ type '<Down><Down><S-Up><S-Up>'
+ type '!'
+
+ final <<-EOF
+ line1 !line3 line4
+ EOF
+ end
+
+ specify '<End> goes to end of wrapped line' do
+ initial <<-EOF
+ line line line line
+ EOF
+
+ type '<End>!'
+
+ final <<-EOF
+ line! line line line
+ EOF
+ end
+
+ specify '<Home> goes to beginning of wrapped line' do
+ initial <<-EOF
+ line line line line
+ EOF
+
+ type '<Down><Home>!'
+
+ final <<-EOF
+ line !line line line
+ EOF
+ end
+end
+
+describe 'Pane control' do
specify 'moving to another pane' do
# Open Quickfix window (auto focuses to it)
type '<M-;>:copen<CR>'
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index f49f5a3..5b3e0ea 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -19,3 +19,26 @@ Vimrunner::RSpec.configure do |config|
vim
end
end
+
+TEST_FILE = 'test_file.txt'.freeze
+
+def write_file_content(string)
+ string = normalize_string_indent(string)
+ File.open(TEST_FILE, 'w') { |f| f.write(string) }
+ vim.edit TEST_FILE
+end
+
+def load_file_content
+ vim.write
+ IO.read(TEST_FILE).strip
+end
+
+def type(string)
+ string.scan(/<.*?>|./).each do |key|
+ if key =~ /<.*>/
+ vim.feedkeys "\\#{key}"
+ else
+ vim.feedkeys key
+ end
+ end
+end