From d6b8c141238a5b01531454814c8604ee941259b4 Mon Sep 17 00:00:00 2001 From: j-james Date: Sat, 14 Nov 2020 23:22:29 -0800 Subject: Rename and refactor novim-mode to vim-heresy --- README.md | 33 +++-- autoload/heresy.vim | 349 ++++++++++++++++++++++++++++++++++++++++++++++++ autoload/novim_mode.vim | 349 ------------------------------------------------ doc/heresy.txt | 175 ++++++++++++++++++++++++ doc/novim_mode.txt | 175 ------------------------ plugin/heresy.vim | 50 +++++++ plugin/novim_mode.vim | 50 ------- spec/heresy_spec.rb | 273 +++++++++++++++++++++++++++++++++++++ spec/novim_mode_spec.rb | 273 ------------------------------------- spec/spec_helper.rb | 2 +- 10 files changed, 863 insertions(+), 866 deletions(-) create mode 100644 autoload/heresy.vim delete mode 100644 autoload/novim_mode.vim create mode 100644 doc/heresy.txt delete mode 100644 doc/novim_mode.txt create mode 100644 plugin/heresy.vim delete mode 100644 plugin/novim_mode.vim create mode 100644 spec/heresy_spec.rb delete mode 100644 spec/novim_mode_spec.rb diff --git a/README.md b/README.md index 0c99738..07ba6ca 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# No Vim Keybindings Mode [![Build Status](https://travis-ci.org/tombh/novim-mode.svg?branch=master)](https://travis-ci.org/tombh/novim-mode) +# heresy.vim Some, indeed many, may say this is counter-productive or even sacrilegious. But Vim is a lot more than just a keybinding paradigm; firstly it has one of the richest plugin ecosystems of any editor, but also it is a -if not *the* most- ubiquitous text editor that's been battle tested for over 25 years. There are more reasons to use it than merely its famous shortcut vocabulary. @@ -6,13 +6,11 @@ This plugin is an attempt to expose everything else about Vim without the overhe Vim itself already has support for something similar in its optional [`mswin.vim`](https://github.com/vim/vim/blob/master/runtime/mswin.vim) config file. However it still assumes the necessity of Normal Mode and such heritage as `SHIFT+INSERT`-style combinations. This plugin however, attempts to avoid Normal Mode unless absolutely necessary, say for interacting with the NERDTree buffer, wherein Insert Mode has no purpose. -The name `novim-mode` is a nod to the prevalence of 'vim-mode' plugins and extensions available in environments outside the editor, such as web browsers. In the same way that the love of Vim has led to efforts to export it elsewhere, 'novim-mode' is the love of 'conventional' editing imported into Vim. - ## Installation Use your favourite plugin manager, eg, for vim-plug; -`Plug 'tombh/novim-mode'` +`Plug 'j-james/vim-heresy'` Note that Vim before v7.5 and Neovim before v0.1.5 have a bug where Insert Mode is inappropriately set for some panes. @@ -25,9 +23,9 @@ If you are new to Vim, then perhaps the only remaining confusion after installin ### Keybindings #### Vim in the terminal -Both Vim and Neovim can be used both as GUI apps and in the terminal. However, original Vim in the terminal has problems with many key combinations - essentially most combinations that are not a plain `CTRL+KEY`. To get around this you can use the [vim-fixkey](https://github.com/drmikehenry/vim-fixkey) plugin. It does have some caveats, which you can read about in its docs, but basically it just makes recording macros a little bit more tricky because of the timing between `Esc` combinations. `vim-fixkey` also doesn't enable `ALT+non-alphanumeric` combinations, but `novim-mode` usually has alphanumeric siblings which you can still use. However, if you are not particularly tied to Vim, you can use Neovim in the terminal which has much better support for key combinations and will work without the need for `vim-fixkey`. Note that the GUI versions of both Vim and Neovim also don't have these key combination problems. +Both Vim and Neovim can be used both as GUI apps and in the terminal. However, original Vim in the terminal has problems with many key combinations - essentially most combinations that are not a plain `CTRL+KEY`. To get around this you can use the [vim-fixkey](https://github.com/drmikehenry/vim-fixkey) plugin. It does have some caveats, which you can read about in its docs, but basically it just makes recording macros a little bit more tricky because of the timing between `Esc` combinations. `vim-fixkey` also doesn't enable `ALT+non-alphanumeric` combinations, but `vim-heresy` usually has alphanumeric siblings which you can still use. However, if you are not particularly tied to Vim, you can use Neovim in the terminal which has much better support for key combinations and will work without the need for `vim-fixkey`. Note that the GUI versions of both Vim and Neovim also don't have these key combination problems. -Most terminal emulators (ie. `xterm`, `rxvt`, `PuTTY`, etc) default to intercepting `CTRL+S` to suspend output (`CTRL+Q` unsuspends if you're wondering), if so you will need to disable this behaviour to use `novim-mode`'s shortcuts for saving and quitting. Most often you simply need to add the following to your `~/.bashrc`, `~/.zshrc` or similar: +Most terminal emulators (ie. `xterm`, `rxvt`, `PuTTY`, etc) default to intercepting `CTRL+S` to suspend output (`CTRL+Q` unsuspends if you're wondering), if so you will need to disable this behaviour to use `vim-heresy`'s shortcuts for saving and quitting. Most often you simply need to add the following to your `~/.bashrc`, `~/.zshrc` or similar: ```sh stty -ixon @@ -91,25 +89,25 @@ inoremap :CtrlP 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 +let g:heresy_use_shortcuts = 0 inoremap ... custom mapping ... -call novim_mode#StartNoVimMode() +call heresy#StartHeresy() ``` Shortcuts are also grouped roughly under the headings described above, so you may be able to disable one of the following: ```vim -let g:novim_mode_use_general_app_shortcuts = 1 -let g:novim_mode_use_pane_controls = 1 -let g:novim_mode_use_copypasting = 1 -let g:novim_mode_use_indenting = 1 -let g:novim_mode_use_finding = 1 -let g:novim_mode_use_undoing = 1 -let g:novim_mode_use_text_tricks = 1 +let g:heresy_use_general_app_shortcuts = 1 +let g:heresy_use_pane_controls = 1 +let g:heresy_use_copypasting = 1 +let g:heresy_use_indenting = 1 +let g:heresy_use_finding = 1 +let g:heresy_use_undoing = 1 +let g:heresy_use_text_tricks = 1 " Small fixes to HOME and PAGEUP behaviour -let g:novim_mode_use_editor_fixes = 1 +let g:heresy_use_editor_fixes = 1 " Allows scrolling through wrapped lines one visual line at a time -let g:novim_mode_use_better_wrap_navigation = 1 +let g:heresy_use_better_wrap_navigation = 1 ``` Lastly you can unmap a mapping using commands such as `nunmap`, `iunmap`, `sunmap`, etc. @@ -119,4 +117,3 @@ Lastly you can unmap a mapping using commands such as `nunmap`, `iunmap`, `sunma * In Neovim there seems to be a bug where only `SHIFT+TAB` and not `TAB` works for indenting during selection mode. * Mapping `` internally means mapping ``. This is a throwback to Vim's days as a pure terminal application. * `CTRL+BACKSPACE` internally represents ``, which can be annoying. Again this is a throwback to Vim's days as a pure terminal application. - diff --git a/autoload/heresy.vim b/autoload/heresy.vim new file mode 100644 index 0000000..9b25d32 --- /dev/null +++ b/autoload/heresy.vim @@ -0,0 +1,349 @@ +" A fundamental question for this plugin is whether insertmode +" is always relevant. This is where we try to get an answer. +function! s:IsEditableBuffer() + if &buftype ==# 'nofile' + \|| !&modifiable + \|| &readonly + return 0 + else + return 1 + endif +endfunction + +" Make sure insert mode is the default mode only when opening/switching +" to files that you want to edit. +function! s:InsertMode() + if s:IsEditableBuffer() == 1 + exe "set insertmode" + else + exe "set noinsertmode" + endif +endfunction + +" Count number of open buffers. They don't have to be visible. +function! s:CountListedBuffers() + let bfr_count = 0 + for bfr in range(1, bufnr("$")) + if buflisted(bfr) + \&& ! empty(bufname(bfr)) + \|| getbufvar(bfr, '&buftype') ==# 'help' + let bfr_count += 1 + endif + endfor + return bfr_count +endfunction + +" The number of visible lines in the current buffer. +" TODO: Include wrapped lines in the total, so that we can start scrolling +" through *visible* lines rather than file lines. +function! s:BufferLines() + return line('w$') - line('w0') +endfunction + +function! s:InsertAndSelectionBehaviour() + " Intelligently set/unset insertmode + augroup start_insertmode + autocmd! + if has('timers') == 1 + " The timer here delays the call to check whether the current buffer + " is an editable one. Without the delay, the check is often too early + " to correctly get the value of `&buftype`, etc. + autocmd BufEnter * call timer_start(1, {->execute('call s:InsertMode()')}) + else + autocmd BufEnter * call s:InsertMode() + endif + augroup END + + " Mostly changes the way selection works. + " See: http://vimdoc.sourceforge.net/htmldoc/gui.html#:behave + " An extract from the docs about the difference between `behave mswin` + " and `behave xterm`: + " mswin xterm + " 'selectmode' 'mouse,key' '' + " 'mousemodel' 'popup' 'extend' + " 'keymodel' 'startsel,stopsel' '' + " 'selection' 'exclusive' 'inclusive' + behave mswin + + " Make 'v' commands default to Visual mode. + " Not sure how useful this is because the mappings that use 'v'-based + " commands don't seem to follow this option. Thus why you will see + " after some selection-based commands to switch from Visual to Selection + " Mode. So might be better to give experienced users who are pressing + " 'v' in normal mode the expected behaviour. + set selectmode+=cmd +endfunction + +" All shortcuts in one function so they can be more easily controlled. +function! g:SetHeresyShortcuts() + " Basic interactions with the editor + if g:heresy_use_app_shortcuts == 1 + " CTRL+q to completely exit vim + inoremap :call heresy#ExitVim() + snoremap :call heresy#ExitVim() + nnoremap :call heresy#ExitVim() + + " CTRL+n for new file + inoremap :edit + " CTRL+o to open file + " TODO: hook into netrw or NERDTree + inoremap :edit + " CTRL+s saves + inoremap :update + + " Goto line number + inoremap :call heresy#GotoLine() + + " ALT+; for command prompt + inoremap : + snoremap : + inoremap : + snoremap : + nnoremap : + nnoremap : + + " replaces native for one-time normal mode commands. + inoremap + snoremap + endif + + " General fixes to editor behaviour + if g:heresy_use_editor_fixes == 1 + " Fix HOME to go back to the first non-whitespace character of the line. + inoremap ^ + " The same but for selection behaviour + inoremap ^ + snoremap ^ + + " Tweaks PageUp behaviour to get cursor to first line on top page + inoremap :call heresy#PageUp() + endif + + " Move between splits, panes, windows, etc and close them + if g:heresy_use_pane_controls == 1 + inoremap + snoremap + nnoremap + inoremap + snoremap + nnoremap + inoremap + snoremap + nnoremap + inoremap + snoremap + nnoremap + + " This allows unsaved buffers to be kept in the background. + set hidden + + " CTRL+w to delete current pane-like things. + inoremap :call heresy#ClosePane() + snoremap :call heresy#ClosePane() + nnoremap :call heresy#ClosePane() + end + + " Selecting, copy, paste, etc + if g:heresy_use_copypasting == 1 + " 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 system clipboard. + inoremap :call heresy#Paste() + " The odd here is because one-off Normal Mode commands + " don't seem to work as expected when some text is selected. Also just + " using on its own seems to cause weird behaviour too. + snoremap :call heresy#Paste() + cnoremap " + snoremap "+ygv + inoremap "+Y + snoremap "+xi + inoremap "+dd + " Select word under cursor + inoremap viw + " Select current line + inoremap V + " Append next line to selection + snoremap gj + + " CTRL-A for selecting all text + inoremap gggHG + snoremap gggHG + endif + + " Indenting + if g:heresy_use_indenting == 1 + " TODO: In Neovim TAB doesn't work in mswin selection mode, but SHIFT+TAB does?? + snoremap >gv + inoremap + snoremap >gv + " Unindenting + snoremap + snoremap / + " Find selected word under cursor + snoremap y/" + " Find next + inoremap n + " Find previous + inoremap N + " Find and replace + inoremap :%s/[FIND]/[REPLACE]/g + endif + + " Undo/redo + if g:heresy_use_undoing == 1 + " Use for native terminal backgrounding. + " The s used in the `snoremap` commands seem to prevent the selection + " process itself being put in the undo history - so now the undo actually undoes + " the last *text* activity. + inoremap u + snoremap u + " Map CTRL+u as well for now just because by default it deletes the line above + " the cursor. + inoremap u + snoremap u + " Redo + inoremap + snoremap + endif + + " Useful, but not necessarily core or conventional, shortcuts for manipulating + " text. + if g:heresy_use_text_tricks == 1 + " CTRL+ALTt+k deletes the current line under the cursor + " TODO: Doesn't work in terminal vim, even with vim-fixkey + inoremap "_dd + + " CTRL+ALT+d duplicates current line. + " NB. Uses the named 'd' register. + " TODO: Doesn't work in terminal vim, even with vim-fixkey + inoremap "dyy"dp + + " CTRL+DOWN/UP moves the current/selected line(s) up and down + inoremap :m -2 + snoremap :m '<-2gv=gv + inoremap :m +1 + snoremap :m '>+1gv=gv + endif +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. 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 + 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 -- I'm as good as certain this will need a patch to + " (n)vim's internals. + inoremap gk + inoremap gj + " For selection behaviour + snoremap gk + snoremap gj + " HOME/END for *visible* lines, not literal lines + inoremap g^ + inoremap g$ + " For selection behaviour + inoremap g^ + snoremap g^ + inoremap g$ + snoremap g$ +endfunction + +" Try to intuitively and intelligently close things like buffers, splits, +" panes, quicklist, etc, basically anything that looks like a pane. +function! heresy#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. + exe "cclose" + + if s:CountListedBuffers() > 1 + " By default if the buffer is the only one on screen, closing it closes the + " tab/window. So this little trick does a switch to the next buffer, + " then closes the previous buffer. + exe "bp\|bd #" + else + quit + endif + else + quit + endif +endfunction + +" TODO: Mention any unsaved buffers +function! heresy#ExitVim() + let l:confirmed = confirm('Do you really want to quit Vim?', "&Yes\n&No", 2) + if l:confirmed == 1 + quitall! + endif +endfunction + +function! heresy#GotoLine() + let l:line_number = input('Goto line: ') + execute line_number +endfunction + +" Just to get PAGEUP to move to the first line when on the first page. +function! heresy#PageUp() + " If current line is higher than the size of the buffer + if line(".") > s:BufferLines() + " Normal PageUp + execute "normal! \" + else + " Goto first line + execute "normal! gg" + endif +endfunction + +function! heresy#Paste() + set paste + execute 'normal! "+P' + set nopaste + call feedkeys("\") +endfunction + +function! g:heresy#StartHeresy() + call s:InsertAndSelectionBehaviour() + + if g:heresy_use_better_wrap_navigation == 1 + call s:SetWrappedTextNavigation() + endif + + if g:heresy_use_shortcuts == 1 + call g:SetHeresyShortcuts() + endif +endfunction diff --git a/autoload/novim_mode.vim b/autoload/novim_mode.vim deleted file mode 100644 index 9d09d58..0000000 --- a/autoload/novim_mode.vim +++ /dev/null @@ -1,349 +0,0 @@ -" A fundamental question for this plugin is whether insertmode -" is always relevant. This is where we try to get an answer. -function! s:IsEditableBuffer() - if &buftype ==# 'nofile' - \|| !&modifiable - \|| &readonly - return 0 - else - return 1 - endif -endfunction - -" Make sure insert mode is the default mode only when opening/switching -" to files that you want to edit. -function! s:InsertMode() - if s:IsEditableBuffer() == 1 - exe "set insertmode" - else - exe "set noinsertmode" - endif -endfunction - -" Count number of open buffers. They don't have to be visible. -function! s:CountListedBuffers() - let bfr_count = 0 - for bfr in range(1, bufnr("$")) - if buflisted(bfr) - \&& ! empty(bufname(bfr)) - \|| getbufvar(bfr, '&buftype') ==# 'help' - let bfr_count += 1 - endif - endfor - return bfr_count -endfunction - -" The number of visible lines in the current buffer. -" TODO: Include wrapped lines in the total, so that we can start scrolling -" through *visible* lines rather than file lines. -function! s:BufferLines() - return line('w$') - line('w0') -endfunction - -function! s:InsertAndSelectionBehaviour() - " Intelligently set/unset insertmode - augroup start_insertmode - autocmd! - if has('timers') == 1 - " The timer here delays the call to check whether the current buffer - " is an editable one. Without the delay, the check is often too early - " to correctly get the value of `&buftype`, etc. - autocmd BufEnter * call timer_start(1, {->execute('call s:InsertMode()')}) - else - autocmd BufEnter * call s:InsertMode() - endif - augroup END - - " Mostly changes the way selection works. - " See: http://vimdoc.sourceforge.net/htmldoc/gui.html#:behave - " An extract from the docs about the difference between `behave mswin` - " and `behave xterm`: - " mswin xterm - " 'selectmode' 'mouse,key' '' - " 'mousemodel' 'popup' 'extend' - " 'keymodel' 'startsel,stopsel' '' - " 'selection' 'exclusive' 'inclusive' - behave mswin - - " Make 'v' commands default to Visual mode. - " Not sure how useful this is because the mappings that use 'v'-based - " commands don't seem to follow this option. Thus why you will see - " after some selection-based commands to switch from Visual to Selection - " Mode. So might be better to give experienced users who are pressing - " 'v' in normal mode the expected behaviour. - set selectmode+=cmd -endfunction - -" All shortcuts in one function so they can be more easily controlled. -function! g:SetNoVimModeShortcuts() - " Basic interactions with the editor - if g:novim_mode_use_general_app_shortcuts == 1 - " CTRL+q to completely exit vim - inoremap :call novim_mode#ExitVim() - snoremap :call novim_mode#ExitVim() - nnoremap :call novim_mode#ExitVim() - - " CTRL+n for new file - inoremap :edit - " CTRL+o to open file - " TODO: hook into netrw or NERDTree - inoremap :edit - " CTRL+s saves - inoremap :update - - " Goto line number - inoremap :call novim_mode#GotoLine() - - " ALT+; for command prompt - inoremap : - snoremap : - inoremap : - snoremap : - nnoremap : - nnoremap : - - " replaces native for one-time normal mode commands. - inoremap - snoremap - endif - - " 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 ^ - " The same but for selection behaviour - inoremap ^ - snoremap ^ - - " Tweaks PageUp behaviour to get cursor to first line on top page - inoremap :call novim_mode#PageUp() - endif - - " Move between splits, panes, windows, etc and close them - if g:novim_mode_use_pane_controls == 1 - inoremap - snoremap - nnoremap - inoremap - snoremap - nnoremap - inoremap - snoremap - nnoremap - inoremap - snoremap - nnoremap - - " This allows unsaved buffers to be kept in the background. - set hidden - - " CTRL+w to delete current pane-like things. - inoremap :call novim_mode#ClosePane() - snoremap :call novim_mode#ClosePane() - nnoremap :call novim_mode#ClosePane() - end - - " Selecting, copy, paste, etc - if g:novim_mode_use_copypasting == 1 - " 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 system clipboard. - inoremap :call novim_mode#Paste() - " The odd here is because one-off Normal Mode commands - " don't seem to work as expected when some text is selected. Also just - " using on its own seems to cause weird behaviour too. - snoremap :call novim_mode#Paste() - cnoremap " - snoremap "+ygv - inoremap "+Y - snoremap "+xi - inoremap "+dd - " Select word under cursor - inoremap viw - " Select current line - inoremap V - " Append next line to selection - snoremap gj - - " CTRL-A for selecting all text - inoremap gggHG - snoremap gggHG - endif - - " Indenting - if g:novim_mode_use_indenting == 1 - " TODO: In Neovim TAB doesn't work in mswin selection mode, but SHIFT+TAB does?? - snoremap >gv - inoremap - snoremap >gv - " Unindenting - snoremap - snoremap / - " Find selected word under cursor - snoremap y/" - " Find next - inoremap n - " Find previous - inoremap N - " Find and replace - inoremap :%s/[FIND]/[REPLACE]/g - endif - - " Undo/redo - if g:novim_mode_use_undoing == 1 - " Use for native terminal backgrounding. - " The s used in the `snoremap` commands seem to prevent the selection - " process itself being put in the undo history - so now the undo actually undoes - " the last *text* activity. - inoremap u - snoremap u - " Map CTRL+u as well for now just because by default it deletes the line above - " the cursor. - inoremap u - snoremap u - " Redo - inoremap - snoremap - endif - - " Useful, but not necessarily core or conventional, shortcuts for manipulating - " text. - if g:novim_mode_use_text_tricks == 1 - " CTRL+ALTt+k deletes the current line under the cursor - " TODO: Doesn't work in terminal vim, even with vim-fixkey - inoremap "_dd - - " CTRL+ALT+d duplicates current line. - " NB. Uses the named 'd' register. - " TODO: Doesn't work in terminal vim, even with vim-fixkey - inoremap "dyy"dp - - " CTRL+DOWN/UP moves the current/selected line(s) up and down - inoremap :m -2 - snoremap :m '<-2gv=gv - inoremap :m +1 - snoremap :m '>+1gv=gv - endif -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. 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 - 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 -- I'm as good as certain this will need a patch to - " (n)vim's internals. - inoremap gk - inoremap gj - " For selection behaviour - snoremap gk - snoremap gj - " HOME/END for *visible* lines, not literal lines - inoremap g^ - inoremap g$ - " For selection behaviour - inoremap g^ - snoremap g^ - inoremap g$ - snoremap 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. - exe "cclose" - - if s:CountListedBuffers() > 1 - " By default if the buffer is the only one on screen, closing it closes the - " tab/window. So this little trick does a switch to the next buffer, - " then closes the previous buffer. - exe "bp\|bd #" - else - quit - endif - else - quit - endif -endfunction - -" TODO: Mention any unsaved buffers -function! novim_mode#ExitVim() - let l:confirmed = confirm('Do you really want to quit Vim?', "&Yes\n&No", 2) - if l:confirmed == 1 - quitall! - endif -endfunction - -function! novim_mode#GotoLine() - let l:line_number = input('Goto line: ') - execute line_number -endfunction - -" Just to get PAGEUP to move to the first line when on the first page. -function! novim_mode#PageUp() - " If current line is higher than the size of the buffer - if line(".") > s:BufferLines() - " Normal PageUp - execute "normal! \" - else - " Goto first line - execute "normal! gg" - endif -endfunction - -function! novim_mode#Paste() - set paste - execute 'normal! "+P' - set nopaste - call feedkeys("\") -endfunction - -function! g:novim_mode#StartNoVimMode() - call s:InsertAndSelectionBehaviour() - - if g:novim_mode_use_better_wrap_navigation == 1 - call s:SetWrappedTextNavigation() - endif - - if g:novim_mode_use_shortcuts == 1 - call g:SetNoVimModeShortcuts() - endif -endfunction diff --git a/doc/heresy.txt b/doc/heresy.txt new file mode 100644 index 0000000..72d8123 --- /dev/null +++ b/doc/heresy.txt @@ -0,0 +1,175 @@ +*heresy.txt* Vim keybindings for 'conventional' editor behaviour + + VIM-HERESY DOCUMENTATION + +============================================================================== +CONTENTS |vim-heresy-contents| + + Introduction ................................... |vim-heresy-introduction| + Installation ................................... |vim-heresy-installation| + Usage ................................................. |vim-heresy-usage| + Keybindings ..................................... |vim-heresy-keybindings| + Interoperability ........................... |vim-heresy-interoperability| + Known Issues ................................... |vim-heresy-known-issues| + References ................................. |vim-heresy-known-references| + +============================================================================== +1. Introduction *vim-heresy* *vim-heresy-introduction* + +vim-heresy makes Vim behave like a 'conventional', non-modal editor. Where key +presses default to inserting text, `CTRL+S` saves the file and so on. In the +same way that 'vim-mode' plugins are available for other editors to enable +Vim-style keybindings, so too is 'vim-heresy' available in Vim to enable +'traditional'-style keybindings. + +Vim is one of the most battle-tested, ubiquitous and extensible editors +available. If your muscle memory is already fluent with non-vim keybindings +then you will be able to instantly benefit from all that is valuable about +Vim without the learning curve of Normal Mode. + +============================================================================== +2. Installation *vim-heresy-installation* + +Use your favourite plugin manager, eg, for vim-plug; > + + Plug 'j-james/vim-heresy'` +< + +============================================================================== +3. Usage *vim-heresy-usage* + +Most keybindings should work as you might expect from, say Atom or Sublime +Text; `SHIFT+ARROW` to select and `CTRL+C/V` to copy/paste. But don't expect +Vim to completely bend to your will, it is still useful to familiarise yourself +with some of Vim's basic concepts. For instance you may on occasion find +yourself stuck in a particular Vim mode, like when pasting text without 'Paste +Mode' then inserted text can trigger random mappings. In such case `CTRL+Q` +may not kill Vim and you'll need to find a way of getting to Normal Mode and +typing `:q` then ``. Such is life with Vim, this plugin is highly +unlikely to ever change that. (BTW conventional pasting is on by default, +but to exit an errant 'Paste Mode' use `:set nopaste`.) + +If you are new to Vim, then perhaps the only remaining confusion after installing +this plugin will be about where files go when you open new ones. This question +will be answered by Vim's concept of 'buffers'. You may wish to install something +like [vim-buftabline](https://github.com/ap/vim-buftabline) to give a familiar +list of open files along the top of the editor. + +============================================================================== +4. Keybindings *vim-heresy-keybindings* + +Vim in the terminal + +Both Vim and Neovim can be used both as GUI apps and in the terminal. However, original Vim in the terminal has problems with many key combinations - essentially most combinations that are not a plain `CTRL+KEY`. To get around this you can use the `vim-fixkey`[2] plugin. It does have some caveats, which you can read about in its docs, but basically it just makes recording macros a little bit more tricky because of the timing between `Esc` combinations. `vim-fixkey` also doesn't enable `ALT+non-alphanumeric` combinations, but `vim-heresy` usually has alphanumeric siblings which you can still use. However, if you are not particularly tied to Vim, you can use Neovim in the terminal which has much better support for key combinations and will work without the need for `vim-fixkey`. Note that the GUI versions of both Vim and Neovim also don't have these key combination problems. + +Most terminal emulators (ie. `xterm`, `rxvt`, `PuTTY`, etc) default to intercepting `CTRL+S` to suspend output (`CTRL+Q` unsuspends if you're wondering), if so you will need to disable this behaviour to use `vim-heresy`'s shortcuts for saving and quitting. Most often you simply need to add the following to your `~/.bashrc`, `~/.zshrc` or similar: > + +stty -ixon +stty stop undef +< + +However some GUI terminals also have their own settings for suspension. For instance Konsole, which can be unset by going to `Settings -> Configure Profile -> Choose current profile -> Edit Profile -> Advanced Tab` and disabling `Enable flow control using Ctrl+S and Ctrl+Q` + +One further common problem is that `tmux` can change key combination behaviour, most notably for `SHIFT+ARROW` combinations, to overcome this add `set-window-option -g xterm-keys` to your `~/.tmux.conf` config. + +General editor shortcuts + * `CTRL+N`: Open a new file. + * `CTRL+O`: Open an existing file. + * `CTRL+S`: Saves the current file. + * `CTRL+G`: Goto line. + * `ALT+;` or `ALT+c`: Vim command prompt. + * `ALT+o`: Replaces native `CTRL+O` to give one-off Normal Mode commands. + +Pane controls + * `ALT+ARROW`: Change pane/buffer focus. + * `CTRL+W`: Closes current pane-like thing. Also closes associated + quickfix and location panes. + +Selecting, copy and paste + * `SHIFT+ARROW`: Select text + * `CTRL+C`: Copy selection or copy line if no selection. + * `CTRL+X`: Cut selection or cut line if no selection. + * `CTRL+V`: Paste current selection. + * `CTRL+A`: Select all. + * `CTRL+D`: Select word under cursor. Use something like vim-multicursors + [1] for multi cursor support. + * `CTRL+L`: Select line under cursor, repetition selects more lines. + +Indenting + * `TAB` or `ALT+]`: Indent current line or selected text. + * `SHIFT+TAB` or `ALT+[`: Unindent current line or selected text. + +Finding, replacing + * `CTRL+F`: Find text. When text is selected that selection is searched + for. + * `F3` and `SHIFT+F3`: Find next and previous occurences. + * `CTRL+H`: Find and replace. `[FIND]` and `[REPLACE]` are prepopulated. + +Undoing + * `CTRL+Z` or `CTRL+U`: Undo. + * `CTRL+Y`: Redo. + +Other text manipulation tricks + * `CTRL+LEFT/RIGHT`: Move cursor per word (works in selection as well). + * `CTRL+ALT+d`: Delete current line. + * `CTRL+ALT+k`: Duplicate current line. + * `CTRL+UP/DOWN`: Move current line or selected text up/down. + + +`CTRL`-based shortcuts are paired with uppercase letters here because Vim +does not recognise the difference between cases when using `CTRL` combinations +and documenting in uppercase implies something of this distinction. +============================================================================== +5. Interoperability *vim-heresy-interoperability* + +When adding a new binding of your own that needs Normal mode, you should use +`` before the targeted command, for example; > + + " Ensure CtrlP doesn't get overridden by autocomplete in insertmode + inoremap :CtrlP +< + +Overriding or disabling shortcuts in this plugin can be done in several +ways. The simplest way is to use: > + + let g:heresy_use_shortcuts = 0 + inoremap ... custom mapping ... + call heresy#StartHeresy() +< + +Alternatively you can unmap a mapping using commands such as `nunmap`, +`iunmap`, `sunmap`, etc. + +Lastly shorcuts are also grouped roughly under the headings described above, +so you may be able to disable one of the +following: > + + let g:heresy_use_general_app_shortcuts = 1 + let g:heresy_use_pane_controls = 1 + let g:heresy_use_copypasting = 1 + let g:heresy_use_indenting = 1 + let g:heresy_use_finding = 1 + let g:heresy_use_undoing = 1 + let g:heresy_use_text_tricks = 1 + + " Small fixes to HOME and PAGEUP behaviour + let g:heresy_use_editor_fixes = 1 + " Allows scrolling through wrapped lines one visual line at a time + let g:heresy_use_better_wrap_navigation = 1 +< +============================================================================== +6. Known Issues *vim-heresy-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. + * Mapping `` internally means mapping ``. This is a + throwback to Vim's days as a pure terminal application. + * `CTRL+BACKSPACE` internally represents ``, which can be annoying. + Again this is a throwback to Vim's days as a pure terminal application. + +============================================================================== +7. References *vim-heresy-references* + +[1] https://github.com/terryma/vim-multiple-cursors +[2] https://github.com/drmikehenry/vim-fixkey diff --git a/doc/novim_mode.txt b/doc/novim_mode.txt deleted file mode 100644 index ee277cd..0000000 --- a/doc/novim_mode.txt +++ /dev/null @@ -1,175 +0,0 @@ -*novim_mode.txt* Vim keybindings for 'conventional' editor behaviour - - NOVIM MODE DOCUMENTATION - -============================================================================== -CONTENTS |novim-mode-contents| - - Introduction ................................... |novim-mode-introduction| - Installation ................................... |novim-mode-installation| - Usage ................................................. |novim-mode-usage| - Keybindings ..................................... |novim-mode-keybindings| - Interoperability ........................... |novim-mode-interoperability| - Known Issues ................................... |novim-mode-known-issues| - References ................................. |novim-mode-known-references| - -============================================================================== -1. Introduction *novim-mode* *novim-mode-introduction* - -Novim-mode makes Vim behave like a 'conventional', non-modal editor. Where key -presses default to inserting text, `CTRL+S` saves the file and so on. In the -same way that 'vim-mode' plugins are available for other editors to enable -Vim-style keybindings, so too is 'novim-mode' available in Vim to enable -'traditional'-style keybindings. - -Vim is one of the most battle-tested, ubiquitous and extensible editors -available. If your muscle memory is already fluent with non-vim keybindings -then you will be able to instantly benefit from all that is valuable about -Vim without the learning curve of Normal Mode. - -============================================================================== -2. Installation *novim-mode-installation* - -Use your favourite plugin manager, eg, for vim-plug; > - - Plug 'tombh/novim-mode'` -< - -============================================================================== -3. Usage *novim-mode-usage* - -Most keybindings should work as you might expect from, say Atom or Sublime -Text; `SHIFT+ARROW` to select and `CTRL+C/V` to copy/paste. But don't expect -Vim to completely bend to your will, it is still useful to familiarise yourself -with some of Vim's basic concepts. For instance you may on occasion find -yourself stuck in a particular Vim mode, like when pasting text without 'Paste -Mode' then inserted text can trigger random mappings. In such case `CTRL+Q` -may not kill Vim and you'll need to find a way of getting to Normal Mode and -typing `:q` then ``. Such is life with Vim, this plugin is highly -unlikely to ever change that. (BTW conventional pasting is on by default, -but to exit an errant 'Paste Mode' use `:set nopaste`.) - -If you are new to Vim, then perhaps the only remaining confusion after installing -this plugin will be about where files go when you open new ones. This question -will be answered by Vim's concept of 'buffers'. You may wish to install something -like [vim-buftabline](https://github.com/ap/vim-buftabline) to give a familiar -list of open files along the top of the editor. - -============================================================================== -4. Keybindings *novim-mode-keybindings* - -Vim in the terminal - -Both Vim and Neovim can be used both as GUI apps and in the terminal. However, original Vim in the terminal has problems with many key combinations - essentially most combinations that are not a plain `CTRL+KEY`. To get around this you can use the `vim-fixkey`[2] plugin. It does have some caveats, which you can read about in its docs, but basically it just makes recording macros a little bit more tricky because of the timing between `Esc` combinations. `vim-fixkey` also doesn't enable `ALT+non-alphanumeric` combinations, but `novim-mode` usually has alphanumeric siblings which you can still use. However, if you are not particularly tied to Vim, you can use Neovim in the terminal which has much better support for key combinations and will work without the need for `vim-fixkey`. Note that the GUI versions of both Vim and Neovim also don't have these key combination problems. - -Most terminal emulators (ie. `xterm`, `rxvt`, `PuTTY`, etc) default to intercepting `CTRL+S` to suspend output (`CTRL+Q` unsuspends if you're wondering), if so you will need to disable this behaviour to use `novim-mode`'s shortcuts for saving and quitting. Most often you simply need to add the following to your `~/.bashrc`, `~/.zshrc` or similar: > - -stty -ixon -stty stop undef -< - -However some GUI terminals also have their own settings for suspension. For instance Konsole, which can be unset by going to `Settings -> Configure Profile -> Choose current profile -> Edit Profile -> Advanced Tab` and disabling `Enable flow control using Ctrl+S and Ctrl+Q` - -One further common problem is that `tmux` can change key combination behaviour, most notably for `SHIFT+ARROW` combinations, to overcome this add `set-window-option -g xterm-keys` to your `~/.tmux.conf` config. - -General editor shortcuts - * `CTRL+N`: Open a new file. - * `CTRL+O`: Open an existing file. - * `CTRL+S`: Saves the current file. - * `CTRL+G`: Goto line. - * `ALT+;` or `ALT+c`: Vim command prompt. - * `ALT+o`: Replaces native `CTRL+O` to give one-off Normal Mode commands. - -Pane controls - * `ALT+ARROW`: Change pane/buffer focus. - * `CTRL+W`: Closes current pane-like thing. Also closes associated - quickfix and location panes. - -Selecting, copy and paste - * `SHIFT+ARROW`: Select text - * `CTRL+C`: Copy selection or copy line if no selection. - * `CTRL+X`: Cut selection or cut line if no selection. - * `CTRL+V`: Paste current selection. - * `CTRL+A`: Select all. - * `CTRL+D`: Select word under cursor. Use something like vim-multicursors - [1] for multi cursor support. - * `CTRL+L`: Select line under cursor, repetition selects more lines. - -Indenting - * `TAB` or `ALT+]`: Indent current line or selected text. - * `SHIFT+TAB` or `ALT+[`: Unindent current line or selected text. - -Finding, replacing - * `CTRL+F`: Find text. When text is selected that selection is searched - for. - * `F3` and `SHIFT+F3`: Find next and previous occurences. - * `CTRL+H`: Find and replace. `[FIND]` and `[REPLACE]` are prepopulated. - -Undoing - * `CTRL+Z` or `CTRL+U`: Undo. - * `CTRL+Y`: Redo. - -Other text manipulation tricks - * `CTRL+LEFT/RIGHT`: Move cursor per word (works in selection as well). - * `CTRL+ALT+d`: Delete current line. - * `CTRL+ALT+k`: Duplicate current line. - * `CTRL+UP/DOWN`: Move current line or selected text up/down. - - -`CTRL`-based shortcuts are paired with uppercase letters here because Vim -does not recognise the difference between cases when using `CTRL` combinations -and documenting in uppercase implies something of this distinction. -============================================================================== -5. Interoperability *novim-mode-interoperability* - -When adding a new binding of your own that needs Normal mode, you should use -`` before the targeted command, for example; > - - " Ensure CtrlP doesn't get overridden by autocomplete in insertmode - inoremap :CtrlP -< - -Overriding or disabling shortcuts in this plugin can be done in several -ways. The simplest way is to use: > - - let g:novim_mode_use_shortcuts = 0 - inoremap ... custom mapping ... - call novim_mode#StartNoVimMode() -< - -Alternatively you can unmap a mapping using commands such as `nunmap`, -`iunmap`, `sunmap`, etc. - -Lastly shorcuts are also grouped roughly under the headings described above, -so you may be able to disable one of the -following: > - - let g:novim_mode_use_general_app_shortcuts = 1 - let g:novim_mode_use_pane_controls = 1 - let g:novim_mode_use_copypasting = 1 - let g:novim_mode_use_indenting = 1 - let g:novim_mode_use_finding = 1 - let g:novim_mode_use_undoing = 1 - let g:novim_mode_use_text_tricks = 1 - - " Small fixes to HOME and PAGEUP behaviour - let g:novim_mode_use_editor_fixes = 1 - " Allows scrolling through wrapped lines one visual line at a time - let g:novim_mode_use_better_wrap_navigation = 1 -< -============================================================================== -6. Known Issues *novim-mode-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. - * Mapping `` internally means mapping ``. This is a - throwback to Vim's days as a pure terminal application. - * `CTRL+BACKSPACE` internally represents ``, which can be annoying. - Again this is a throwback to Vim's days as a pure terminal application. - -============================================================================== -7. References *novim-mode-references* - -[1] https://github.com/terryma/vim-multiple-cursors -[2] https://github.com/drmikehenry/vim-fixkey diff --git a/plugin/heresy.vim b/plugin/heresy.vim new file mode 100644 index 0000000..e318f95 --- /dev/null +++ b/plugin/heresy.vim @@ -0,0 +1,50 @@ +" heresy.vim - Make Vim behave more like a "normal" editor +" Author: j-james +" Version: 0.1 +" +" ============================================================================ + +let s:save_cpo = &cpo +set cpo&vim + +let s:settings = { + \ 'use_general_app_shortcuts': 1, + \ 'use_editor_fixes': 1, + \ 'use_pane_controls': 1, + \ 'use_copypasting': 1, + \ 'use_indenting': 1, + \ 'use_finding': 1, + \ 'use_undoing': 1, + \ 'use_text_tricks': 1, + \ 'use_better_wrap_navigation': 1, + \ 'use_shortcuts': 1 +\} + +" Fetches existing values from user and sets defaults if not set. +function! s:init_settings(settings) + for [key, value] in items(a:settings) + let sub = '' + if type(value) == 0 + let sub = '%d' + elseif type(value) == 1 + let sub = '"%s"' + endif + let fmt = printf("let g:heresy_%%s=get(g:, 'heresy_%%s', %s)", + \ sub) + exec printf(fmt, key, key, value) + endfor +endfunction + +call s:init_settings(s:settings) + +if has('timers') == 0 + echo "vim-heresy: Your Vim version (Vim <7.5 or Neovim <0.1.5) doesn't " + echo "support `timer()`, which causes a bug where Insert Mode is " + echo "inappropriately set for some panes." +endif + +" Plugin entry point +call g:heresy#StartHeresy() + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/plugin/novim_mode.vim b/plugin/novim_mode.vim deleted file mode 100644 index c30d5de..0000000 --- a/plugin/novim_mode.vim +++ /dev/null @@ -1,50 +0,0 @@ -" novim_mode.vim - 'Conventional' editor keybindings plugin -" Author: tombh -" Version: 0.1 -" -" ============================================================================ - -let s:save_cpo = &cpo -set cpo&vim - -let s:settings = { - \ 'use_general_app_shortcuts': 1, - \ 'use_editor_fixes': 1, - \ 'use_pane_controls': 1, - \ 'use_copypasting': 1, - \ 'use_indenting': 1, - \ 'use_finding': 1, - \ 'use_undoing': 1, - \ 'use_text_tricks': 1, - \ 'use_better_wrap_navigation': 1, - \ 'use_shortcuts': 1 -\} - -" Fetches existing values from user and sets defaults if not set. -function! s:init_settings(settings) - for [key, value] in items(a:settings) - let sub = '' - if type(value) == 0 - let sub = '%d' - elseif type(value) == 1 - let sub = '"%s"' - endif - let fmt = printf("let g:novim_mode_%%s=get(g:, 'novim_mode_%%s', %s)", - \ sub) - exec printf(fmt, key, key, value) - endfor -endfunction - -call s:init_settings(s:settings) - -if has('timers') == 0 - echo "Novim-mode: Your Vim version (Vim <7.5 or Neovim <0.1.5) doesn't " - echo "support `timer()`, which causes a bug where Insert Mode is " - echo "innapropriately set for some panes." -endif - -" Plugin entry point -call g:novim_mode#StartNoVimMode() - -let &cpo = s:save_cpo -unlet s:save_cpo diff --git a/spec/heresy_spec.rb b/spec/heresy_spec.rb new file mode 100644 index 0000000..ce19704 --- /dev/null +++ b/spec/heresy_spec.rb @@ -0,0 +1,273 @@ +# Tip of the hat to terryma/vim-multiple-cursors for this style +# of testing Vim. +require 'spec_helper' + +describe 'Basic editing' do + specify 'writing simple text' do + initial <<-EOF + EOF + + type 'hello world' + + final <<-EOF + hello world + EOF + end + + specify ' goes to first non-whitespace char' do + initial <<-EOF + justified + indented + EOF + + type '!' + + final <<-EOF + justified + !indented + EOF + end + + specify 'copy and paste' do + initial <<-EOF + copy me + EOF + + type '' + + final <<-EOF + copy me copy me + EOF + end + + specify 'CTRL+ARROW jumps by word' do + initial <<-EOF + one two three four + EOF + + type 'XYZ' + + final <<-EOF + one Xtwo ZYthree four + EOF + end +end + +describe 'Selecting' do + specify 'select all and replace' do + initial <<-EOF + select me + EOF + + type 'gone' + + final <<-EOF + gone + EOF + end + + specify 'paste over selection' do + initial <<-EOF + cut me and paste over me + EOF + + 7.times { type '' } + type '' + 10.times { type '' } + 7.times { type '' } + type '' + + 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 '' } + type '' + 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 '' } + type '' + type '!' + + final <<-EOF + !of text + EOF + end + + specify 'CTRL+D selects the word under the cursor' do + initial <<-EOF + a line of text + EOF + + 4.times { type '' } + type '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 'XY' + + 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 'x' + + final <<-EOF + x! + EOF + end + + specify 'SHIFT+HOME selects line, even if off-screen' do + initial <<-EOF + !line line line line + EOF + + type 'x' + + final <<-EOF + !x + EOF + end +end + +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' + ] + use_extension 'txt' + end + + specify 'move up/down one wrapped line' do + initial <<-EOF + line line line line + EOF + + type 'down ' + type '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 '' + type '!' + + final <<-EOF + line1 !line3 line4 + EOF + end + + specify 'select wrapped line above' do + initial <<-EOF + line1 line2 line3 line4 + EOF + + type '' + type '!' + + final <<-EOF + line1 !line3 line4 + EOF + end + + specify ' goes to end of wrapped line' do + initial <<-EOF + line line line line + EOF + + type '!' + + final <<-EOF + line! line line line + EOF + end + + specify ' goes to beginning of wrapped line' do + initial <<-EOF + line line line line + EOF + + type '!' + + 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 ':copen' + pane_type = vim.command 'echo &buftype' + expect(pane_type).to eq 'quickfix' + + # Focus back to file + type '' + pane_type = vim.command 'echo &buftype' + + expect(pane_type).to eq '' + end + + specify 'closing a pane' do + # Open Netrw file manager in a sidebar + type 'Vexplore' + buffer_id = vim.command "echo bufnr('%')" + expect(buffer_id).to eq '2' + + # Close Netrw pane + type '' + buffer_id = vim.command "echo bufnr('%')" + expect(buffer_id).to eq '1' + end +end diff --git a/spec/novim_mode_spec.rb b/spec/novim_mode_spec.rb deleted file mode 100644 index ce19704..0000000 --- a/spec/novim_mode_spec.rb +++ /dev/null @@ -1,273 +0,0 @@ -# Tip of the hat to terryma/vim-multiple-cursors for this style -# of testing Vim. -require 'spec_helper' - -describe 'Basic editing' do - specify 'writing simple text' do - initial <<-EOF - EOF - - type 'hello world' - - final <<-EOF - hello world - EOF - end - - specify ' goes to first non-whitespace char' do - initial <<-EOF - justified - indented - EOF - - type '!' - - final <<-EOF - justified - !indented - EOF - end - - specify 'copy and paste' do - initial <<-EOF - copy me - EOF - - type '' - - final <<-EOF - copy me copy me - EOF - end - - specify 'CTRL+ARROW jumps by word' do - initial <<-EOF - one two three four - EOF - - type 'XYZ' - - final <<-EOF - one Xtwo ZYthree four - EOF - end -end - -describe 'Selecting' do - specify 'select all and replace' do - initial <<-EOF - select me - EOF - - type 'gone' - - final <<-EOF - gone - EOF - end - - specify 'paste over selection' do - initial <<-EOF - cut me and paste over me - EOF - - 7.times { type '' } - type '' - 10.times { type '' } - 7.times { type '' } - type '' - - 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 '' } - type '' - 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 '' } - type '' - type '!' - - final <<-EOF - !of text - EOF - end - - specify 'CTRL+D selects the word under the cursor' do - initial <<-EOF - a line of text - EOF - - 4.times { type '' } - type '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 'XY' - - 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 'x' - - final <<-EOF - x! - EOF - end - - specify 'SHIFT+HOME selects line, even if off-screen' do - initial <<-EOF - !line line line line - EOF - - type 'x' - - final <<-EOF - !x - EOF - end -end - -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' - ] - use_extension 'txt' - end - - specify 'move up/down one wrapped line' do - initial <<-EOF - line line line line - EOF - - type 'down ' - type '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 '' - type '!' - - final <<-EOF - line1 !line3 line4 - EOF - end - - specify 'select wrapped line above' do - initial <<-EOF - line1 line2 line3 line4 - EOF - - type '' - type '!' - - final <<-EOF - line1 !line3 line4 - EOF - end - - specify ' goes to end of wrapped line' do - initial <<-EOF - line line line line - EOF - - type '!' - - final <<-EOF - line! line line line - EOF - end - - specify ' goes to beginning of wrapped line' do - initial <<-EOF - line line line line - EOF - - type '!' - - 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 ':copen' - pane_type = vim.command 'echo &buftype' - expect(pane_type).to eq 'quickfix' - - # Focus back to file - type '' - pane_type = vim.command 'echo &buftype' - - expect(pane_type).to eq '' - end - - specify 'closing a pane' do - # Open Netrw file manager in a sidebar - type 'Vexplore' - buffer_id = vim.command "echo bufnr('%')" - expect(buffer_id).to eq '2' - - # Close Netrw pane - type '' - buffer_id = vim.command "echo bufnr('%')" - expect(buffer_id).to eq '1' - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cfe5a51..ad1d144 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ Vimrunner::RSpec.configure do |config| # Load the plugin plugin_path = File.expand_path('../..', __FILE__) - vim.add_plugin(plugin_path, 'plugin/novim_mode.vim') + vim.add_plugin(plugin_path, 'plugin/heresy.vim') # The returned value is the Client available in the tests. vim -- cgit v1.2.3-70-g09d2