diff options
author | Thomas Buckley-Houston | 2017-05-30 09:24:00 +0000 |
---|---|---|
committer | Thomas Buckley-Houston | 2017-05-30 09:24:00 +0000 |
commit | 79bd6b4273325f891d2fcdb2a79ede59e313e414 (patch) | |
tree | 48028cfaf00bdd6ef82b83afb638317db4a9a53d /plugin | |
parent | 37905d1bad1dd19cca13fd36022b0cffb811b699 (diff) |
Formalise plugin: functions, autoload, tests
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/novim-mode.vim | 92 | ||||
-rw-r--r-- | plugin/novim_mode.vim | 38 |
2 files changed, 38 insertions, 92 deletions
diff --git a/plugin/novim-mode.vim b/plugin/novim-mode.vim deleted file mode 100644 index 5df9bba..0000000 --- a/plugin/novim-mode.vim +++ /dev/null @@ -1,92 +0,0 @@ -" Make sure insert mode is the default mode when opening/switching to files -function! InsertMode() - if &buftype ==# 'nofile' - \|| !&modifiable - \|| &readonly - \|| bufname('%') =~# 'NERD_tree_' - exe "set noinsertmode" - else - exe "set insertmode" - endif -endfunction - -augroup start_insertmode - autocmd! - autocmd BufEnter * call InsertMode() -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 - -" Copy and paste stuff -inoremap <C-V> <C-O>p -vnoremap <C-C> y -vnoremap <C-X> x - -" CTRL-A for selecting all text -inoremap <C-A> <C-O>gg<C-O>gH<C-O>G -cnoremap <C-A> <C-C>gggH<C-O>G -vnoremap <C-A> <C-C>gggH<C-O>G - -" Indenting -" TODO: TAB doesn't work in mswin selection mode, but SHIFT+TAB does?? -vnoremap <Tab> > -vnoremap <S-Tab> < - -" CTRL+q to exit pane/app -inoremap <C-Q> <C-O>:q<CR> -" Useful for exiting buffers like NERDTree that don't use insertmode -nnoremap <C-Q> :q<CR> - -" Find -inoremap <C-F> <C-O>/ -" Find next -inoremap <F3> <C-O>n -" Find previous -inoremap <S-F3> <C-O>N -" Clears highlighting. NB. Overriding ESC makes it very hard to get into -" NORMAL mode. -inoremap <silent> <Esc> <C-O>:noh<CR> - -" Undo/redo -" Doesn't use Ctrl+Z because that's already a significant *nix shortcut -" Unfortunately Vim can't use uppercase (shifted) key combos, otherwise -" we'd use CTRL+SHIFT+U here. -inoremap <silent> <C-U> <C-O>u -inoremap <silent> <C-R> <C-O><C-R> - -" CTRL+s saves -inoremap <silent> <C-S> <C-O>:update<CR> - -" CTRL+k deletes the current line -inoremap <silent> <C-K> <C-O>"_dd - -" CTRL+d duplicates current line -" TODO: don't put it in vim's clipboard, so CTRL+V works as expected -inoremap <silent> <C-D> <C-O>yy<C-O>p - -" Alt+/- moves the current line up and down -inoremap <silent> <M--> <C-O>:m -2<CR> -inoremap <silent> <M-=> <C-O>:m +1<CR> - -" Home goes back to the first non-whitespace character of the line -inoremap <silent> <Home> <C-O>^ - -" Allow text to wrap in text files -au BufNewFile,BufRead *.txt,*.md,*.markdown setlocal linebreak spell -" Make arrow keys move through wrapped lines -" TODO: -" * Make this feature optional. -" * 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 -" 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 diff --git a/plugin/novim_mode.vim b/plugin/novim_mode.vim new file mode 100644 index 0000000..fbfdb1b --- /dev/null +++ b/plugin/novim_mode.vim @@ -0,0 +1,38 @@ +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) + +" Plugin entry point +call novim_mode#StartNoVimMode() + +let &cpo = s:save_cpo +unlet s:save_cpo |