aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/novim_mode.vim78
-rw-r--r--spec/novim_mode_spec.rb82
-rw-r--r--spec/spec_helper.rb31
3 files changed, 150 insertions, 41 deletions
diff --git a/autoload/novim_mode.vim b/autoload/novim_mode.vim
index 90aecc5..f992b3f 100644
--- a/autoload/novim_mode.vim
+++ b/autoload/novim_mode.vim
@@ -109,18 +109,11 @@ function! g:SetNoVimModeShortcuts()
" General fixes to editor behaviour
if g:novim_mode_use_editor_fixes == 1
- " 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$
+ inoremap <silent> <Home> <C-O>^
+ " The same but for selection behaviour
+ inoremap <silent> <S-Home> <S-Left><C-G><C-O>^
+ snoremap <silent> <S-Home> <C-O>^
" Tweaks PageUp behaviour to get cursor to first line on top page
inoremap <silent> <PageUp> <C-O>:call novim_mode#PageUp()<CR>
@@ -155,14 +148,14 @@ function! g:SetNoVimModeShortcuts()
" One of those curious features of Vim: without `onemore` when pasting
" at the end of a line, pasted text gets put *before* the cursor.
set virtualedit=onemore
- " NB. All these use the named 'p' register.
- inoremap <C-V> <C-O>"pP
- snoremap <C-V> <C-O>"pP
- cnoremap <C-V> <C-R>"p
- snoremap <C-C> <C-O>"pygv
- inoremap <C-C> <C-O>"pY
- snoremap <C-X> <C-O>"pxi
- inoremap <C-X> <C-O>"pdd
+ " NB. All these use the system clipboard.
+ inoremap <C-V> <C-O>"+P
+ snoremap <C-V> <C-O>"+P
+ cnoremap <C-V> <C-R>"+
+ snoremap <C-C> <C-O>"+ygv
+ inoremap <C-C> <C-O>"+Y
+ snoremap <C-X> <C-O>"+xi
+ inoremap <C-X> <C-O>"+dd
" Select word under cursor
inoremap <C-D> <C-O>viw<C-G>
" Select current line
@@ -239,26 +232,57 @@ endfunction
" By default Vim treats wrapped text as a single line even though it may
" appear as many lines on screen. So here we try to make wrapped text behave
-" more conventionally.
+" more conventionally. Please add any new types you might come across.
function! s:SetWrappedTextNavigation()
+ autocmd BufNewFile,BufRead *.{
+ \md,
+ \mdown,
+ \markdown,
+ \txt,
+ \textile,
+ \rdoc,
+ \org,
+ \creole,
+ \mediawiki
+ \} setlocal filetype=txt
+ autocmd FileType \
+ \rst,
+ \asciidoc,
+ \pod,
+ \txt
+ \ call s:WrappedTextBehaviour()
+endfunction
+
+function! s:WrappedTextBehaviour()
" Allow text to wrap in text files
- au BufNewFile,BufRead *.txt,*.md,*.markdown setlocal linebreak spell wrap
+ setlocal linebreak wrap
" Make arrow keys move through wrapped lines
" TODO:
- " * 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
+ " * Scroll window 1 wrapped soft line at a time rather than entire block
+ " of wrapped lines -- I'm as good as certain this will need a patch to
+ " (n)vim's internals.
+ inoremap <buffer> <Up> <C-O>gk
+ inoremap <buffer> <Down> <C-O>gj
+ " For selection behaviour
+ snoremap <buffer> <S-Up> <C-O>gk
+ snoremap <buffer> <S-Down> <C-O>gj
+ " HOME/END for *visible* lines, not literal lines
+ inoremap <buffer> <silent> <Home> <C-O>g^
+ inoremap <buffer> <silent> <End> <C-O>g$
" 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
+ inoremap <buffer> <silent> <S-Home> <S-Left><C-G><C-O>g^
+ snoremap <buffer> <silent> <S-Home> <C-O>g^
+ inoremap <buffer> <silent> <S-End> <S-Right><C-G><C-O>g$
+ snoremap <buffer> <silent> <S-End> <C-O>g$
endfunction
" Try to intuitively and intelligently close things like buffers, splits,
" panes, quicklist, etc, basically anything that looks like a pane.
function! novim_mode#ClosePane()
if s:IsEditableBuffer() == 1
+ " TODO: These aren't actually formally associated with a buffer, although
+ " conceptually they often are (eg; linting errors, file search).
" Close any location lists on screen.
exe "lclose"
" Close any quickfix lists on screen.
diff --git a/spec/novim_mode_spec.rb b/spec/novim_mode_spec.rb
index a3d603c..965fbb0 100644
--- a/spec/novim_mode_spec.rb
+++ b/spec/novim_mode_spec.rb
@@ -2,15 +2,6 @@
# of testing Vim.
require 'spec_helper'
-def initial(string)
- @vim_options.each { |x| vim.command(x) } if @vim_options
- write_file_content(string)
-end
-
-def final(string)
- expect(load_file_content).to eq normalize_string_indent(string)
-end
-
describe 'Basic editing' do
specify 'writing simple text' do
initial <<-EOF
@@ -48,6 +39,18 @@ describe 'Basic editing' do
copy me copy me
EOF
end
+
+ specify 'CTRL+ARROW jumps by word' do
+ initial <<-EOF
+ one two three four
+ EOF
+
+ type '<C-Right>X<C-Right>Y<C-Left>Z'
+
+ final <<-EOF
+ one Xtwo ZYthree four
+ EOF
+ end
end
describe 'Selecting' do
@@ -106,6 +109,66 @@ describe 'Selecting' do
!of text
EOF
end
+
+ specify 'CTRL+D selects the word under the cursor' do
+ initial <<-EOF
+ a line of text
+ EOF
+
+ 4.times { type '<Right>' }
+ type '<C-D>X'
+
+ final <<-EOF
+ a X of text
+ EOF
+ end
+end
+
+describe 'Home/End behaviour for long, non-wrapped code lines' do
+ before(:each) do
+ # We need a small screen so that lines go off the edge of it.
+ @vim_options = [
+ # A single buffer can't be resized, so create a split of the buffer
+ 'vsplit',
+ 'vertical resize 6'
+ ]
+ end
+
+ specify 'HOME/END move to start/end of line off-screen' do
+ initial <<-EOF
+ line line line line
+ EOF
+
+ type '<End>X<Home>Y'
+
+ final <<-EOF
+ Yline line line lineX
+ EOF
+ end
+
+ specify 'SHIFT+END selects line, even if off-screen' do
+ initial <<-EOF
+ line line line line!
+ EOF
+
+ type '<S-End><S-Left>x'
+
+ final <<-EOF
+ x!
+ EOF
+ end
+
+ specify 'SHIFT+HOME selects line, even if off-screen' do
+ initial <<-EOF
+ !line line line line
+ EOF
+
+ type '<End><S-Home><S-Right>x'
+
+ final <<-EOF
+ !x
+ EOF
+ end
end
describe 'Wrapped text' do
@@ -115,6 +178,7 @@ describe 'Wrapped text' do
'vsplit',
'vertical resize 6'
]
+ use_extension 'txt'
end
specify 'move up/down one wrapped line' do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5b3e0ea..cfe5a51 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -20,17 +20,24 @@ Vimrunner::RSpec.configure do |config|
end
end
-TEST_FILE = 'test_file.txt'.freeze
+RSpec.configure do |config|
+ config.before :each do
+ # Default to setting the filetype to shell to enable
+ # code-like behaviour.
+ @ext = 'sh'
+ end
+end
-def write_file_content(string)
+def write_file_content(string, ext = 'sh')
+ @file = "file.#{ext}"
string = normalize_string_indent(string)
- File.open(TEST_FILE, 'w') { |f| f.write(string) }
- vim.edit TEST_FILE
+ File.open(@file, 'w') { |f| f.write(string) }
+ vim.edit @file
end
def load_file_content
vim.write
- IO.read(TEST_FILE).strip
+ IO.read(@file).strip
end
def type(string)
@@ -42,3 +49,17 @@ def type(string)
end
end
end
+
+def initial(string)
+ @vim_options.each { |x| vim.command(x) } if @vim_options
+ write_file_content(string, @ext)
+end
+
+def final(string)
+ expected = normalize_string_indent(string)
+ expect(load_file_content).to eq expected
+end
+
+def use_extension(ext)
+ @ext = ext
+end