aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorj-james2020-11-15 08:55:46 +0000
committerj-james2020-11-15 08:55:46 +0000
commit0ba5c5211d96dd53af9d3b47b9a436048de4a3b1 (patch)
treebfd34aa77d7f4b6133c525f3f8582bdd2b049aa3
parentd6b8c141238a5b01531454814c8604ee941259b4 (diff)
Refactor method names
-rw-r--r--README.md20
-rw-r--r--autoload/heresy.vim296
-rw-r--r--doc/heresy.txt20
-rw-r--r--plugin/heresy.vim23
4 files changed, 179 insertions, 180 deletions
diff --git a/README.md b/README.md
index 07ba6ca..eb8f518 100644
--- a/README.md
+++ b/README.md
@@ -89,25 +89,25 @@ 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:heresy_use_shortcuts = 0
+let g:heresy_shortcuts = 0
inoremap ... custom mapping ...
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: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
+let g:heresy_app_shortcuts = 1
+let g:heresy_copypaste_shortcuts = 1
+let g:heresy_undo_shortcuts = 1
+let g:heresy_find_shortcuts = 1
+let g:heresy_line_shortcuts = 1
+let g:heresy_pane_shortcuts = 1
+let g:heresy_indentation_shortcuts = 1
" Small fixes to HOME and PAGEUP behaviour
-let g:heresy_use_editor_fixes = 1
+let g:heresy_navigation_fixes = 1
" Allows scrolling through wrapped lines one visual line at a time
-let g:heresy_use_better_wrap_navigation = 1
+let g:heresy_better_wrap_navigation = 1
```
Lastly you can unmap a mapping using commands such as `nunmap`, `iunmap`, `sunmap`, etc.
diff --git a/autoload/heresy.vim b/autoload/heresy.vim
index 9b25d32..02dc3bd 100644
--- a/autoload/heresy.vim
+++ b/autoload/heresy.vim
@@ -75,52 +75,85 @@ function! s:InsertAndSelectionBehaviour()
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 <silent> <C-Q> <C-O>:call heresy#ExitVim()<CR>
- snoremap <silent> <C-Q> <C-O>:call heresy#ExitVim()<CR>
- nnoremap <silent> <C-Q> :call heresy#ExitVim()<CR>
-
- " CTRL+n for new file
+function! g:SetShortcuts()
+
+ if g:heresy_app_shortcuts == 1
+ " Completely exit vim
+ inoremap <silent> <C-Q> <C-O>:call heresy#CloseVim()<CR>
+ snoremap <silent> <C-Q> <C-O>:call heresy#CloseVim()<CR>
+ nnoremap <silent> <C-Q> :call heresy#CloseVim()<CR>
+ " Close current pane-like things.
+ inoremap <silent> <C-W> <C-O>:call heresy#ClosePane()<CR>
+ snoremap <silent> <C-W> <C-O>:call heresy#ClosePane()<CR>
+ nnoremap <silent> <C-W> :call heresy#ClosePane()<CR>
+ " Save file
+ inoremap <silent> <C-S> <C-O>:update<CR>
+ " New file
inoremap <C-N> <C-O>:edit<Space>
- " CTRL+o to open file
- " TODO: hook into netrw or NERDTree
+ " Open file (TODO: hook into netrw or NERDTree)
inoremap <C-O> <C-O>:edit<Space>
- " CTRL+s saves
- inoremap <silent> <C-S> <C-O>:update<CR>
-
- " Goto line number
- inoremap <C-G> <C-O>:call heresy#GotoLine()<CR>
+ endif
- " ALT+; for command prompt
- inoremap <M-;> <C-O>:
- snoremap <M-;> <C-O>:
- inoremap <M-c> <C-O>:
- snoremap <M-c> <C-O>:
- nnoremap <M-;> :
- nnoremap <M-c> :
+ if g:heresy_copypaste_shortcuts == 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
+ " Cut selected text / current line
+ snoremap <C-X> <C-O>"+xi
+ inoremap <C-X> <C-O>"+dd
+ " Copy selected text / current line
+ snoremap <C-C> <C-O>"+ygv
+ inoremap <C-C> <C-O>"+Y
+ " Paste system clipboard
+ inoremap <C-V> <C-O>:call heresy#Paste()<CR>
+ " The odd <Space><Backspace> here is because one-off Normal Mode commands
+ " don't seem to work as expected when some text is selected. Also just
+ " using <Backspace> on its own seems to cause weird behaviour too.
+ snoremap <C-V> <Space><Backspace><C-O>:call heresy#Paste()<CR>
+ cnoremap <C-V> <C-R>"
+ endif
- " <ALT+o> replaces native <C-O> for one-time normal mode commands.
- inoremap <M-o> <C-O>
- snoremap <M-o> <C-O>
+ " Use <M-o><C-Z> for native terminal backgrounding.
+ " The <Esc>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.
+ if g:heresy_undo_shortcuts == 1
+ " Undo
+ inoremap <silent> <C-Z> <C-O>u
+ snoremap <silent> <C-Z> <Esc><C-O>u
+ " Redo
+ inoremap <silent> <C-Y> <C-O><C-R>
+ snoremap <silent> <C-Y> <Esc><C-O><C-R>
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 <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>^
+ if g:heresy_find_shortcuts == 1
+ " Find
+ inoremap <C-F> <C-O>/
+ " Find selected word under cursor
+ snoremap <C-F> <C-O>y/<C-R>"<CR>
+ " Find next
+ " inoremap <F3> <C-O>n
+ " Find previous
+ " inoremap <S-F3> <C-O>N
+ " Find and replace
+ inoremap <C-G> <C-O>:%s/[FIND]/[REPLACE]/g
+ " Jump to a line
+ " inoremap <C-?> <C-O>:call heresy#GotoLine()<CR>
+ " Multi-select VSCode style
+ " snoremap <C-D> ???
+ endif
- " Tweaks PageUp behaviour to get cursor to first line on top page
- inoremap <silent> <PageUp> <C-O>:call heresy#PageUp()<CR>
+ if g:heresy_line_shortcuts == 1
+ " Move the current / selected line(s) up
+ inoremap <silent> <C-Up> <C-O>:m -2<CR>
+ snoremap <silent> <C-Up> <C-O>:m '<-2<CR>gv=gv<C-G>
+ " Move the current / selected line(s) down
+ inoremap <silent> <C-Down> <C-O>:m +1<CR>
+ snoremap <silent> <C-Down> <C-O>:m '>+1<CR>gv=gv<C-G>
endif
- " Move between splits, panes, windows, etc and close them
- if g:heresy_use_pane_controls == 1
+ if g:heresy_pane_shortcuts == 1
+ " Move between splits, panes, windows, etc and close them
inoremap <silent> <M-Left> <C-O><C-W><Left>
snoremap <silent> <M-Left> <Esc><C-W><Left>
nnoremap <silent> <M-Left> <C-W><Left>
@@ -136,44 +169,12 @@ function! g:SetHeresyShortcuts()
" This allows unsaved buffers to be kept in the background.
set hidden
-
- " CTRL+w to delete current pane-like things.
- inoremap <silent> <C-W> <C-O>:call heresy#ClosePane()<CR>
- snoremap <silent> <C-W> <C-O>:call heresy#ClosePane()<CR>
- nnoremap <silent> <C-W> :call heresy#ClosePane()<CR>
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 <C-V> <C-O>:call heresy#Paste()<CR>
- " The odd <Space><Backspace> here is because one-off Normal Mode commands
- " don't seem to work as expected when some text is selected. Also just
- " using <Backspace> on its own seems to cause weird behaviour too.
- snoremap <C-V> <Space><Backspace><C-O>:call heresy#Paste()<CR>
- 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
- inoremap <C-L> <C-O>V<C-G>
- " Append next line to selection
- snoremap <C-L> <C-O>gj
-
- " CTRL-A for selecting all text
- inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
- snoremap <C-A> <C-O><C-C>gggH<C-O>G
- endif
-
- " Indenting
- if g:heresy_use_indenting == 1
- " TODO: In Neovim TAB doesn't work in mswin selection mode, but SHIFT+TAB does??
+ " TODO: Shift+TAB doesn't work in insert mode, but does in selection mode??
+ " TODO: In Neovim TAB doesn't work in mswin selection mode, but SHIFT+TAB does??
+ if g:heresy_indentation_shortcuts == 1
+ " Indenting
snoremap <Tab> <C-O>>gv
inoremap <M-]> <C-T>
snoremap <M-]> <C-O>>gv
@@ -183,53 +184,48 @@ function! g:SetHeresyShortcuts()
snoremap <M-[> <C-O><gv
endif
- if g:heresy_use_finding == 1
- " Find
- inoremap <C-F> <C-O>/
- " Find selected word under cursor
- snoremap <C-F> <C-O>y/<C-R>"<CR>
- " Find next
- inoremap <F3> <C-O>n
- " Find previous
- inoremap <S-F3> <C-O>N
- " Find and replace
- inoremap <C-H> <C-O>:%s/[FIND]/[REPLACE]/g
- endif
+ if g:heresy_navigation_fixes == 1
+ " Fix HOME to go back to the first non-whitespace character of the line.
+ 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>^
- " Undo/redo
- if g:heresy_use_undoing == 1
- " Use <M-o><C-Z> for native terminal backgrounding.
- " The <Esc>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 <silent> <C-Z> <C-O>u
- snoremap <silent> <C-Z> <Esc><C-O>u
- " Map CTRL+u as well for now just because by default it deletes the line above
- " the cursor.
- inoremap <silent> <C-U> <C-O>u
- snoremap <silent> <C-U> <Esc><C-O>u
- " Redo
- inoremap <silent> <C-Y> <C-O><C-R>
- snoremap <silent> <C-Y> <Esc><C-O><C-R>
+ " Tweaks PageUp behaviour to get cursor to first line on top page
+ inoremap <silent> <PageUp> <C-O>:call heresy#PageUp()<CR>
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 <silent> <C-M-K> <C-O>"_dd
+endfunction
- " CTRL+ALT+d duplicates current line.
- " NB. Uses the named 'd' register.
- " TODO: Doesn't work in terminal vim, even with vim-fixkey
- inoremap <silent> <C-M-D> <C-O>"dyy<C-O>"dp
+" TODO: Mention any unsaved buffers
+function! heresy#CloseVim()
+ let l:confirmed = confirm('Do you really want to quit Vim?', "&Yes\n&No", 2)
+ if l:confirmed == 1
+ quitall!
+ endif
+endfunction
- " CTRL+DOWN/UP moves the current/selected line(s) up and down
- inoremap <silent> <C-Up> <C-O>:m -2<CR>
- snoremap <silent> <C-Up> <C-O>:m '<-2<CR>gv=gv<C-G>
- inoremap <silent> <C-Down> <C-O>:m +1<CR>
- snoremap <silent> <C-Down> <C-O>:m '>+1<CR>gv=gv<C-G>
+" 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
@@ -280,38 +276,6 @@ function! s:WrappedTextBehaviour()
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! 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
@@ -339,11 +303,43 @@ endfunction
function! g:heresy#StartHeresy()
call s:InsertAndSelectionBehaviour()
- if g:heresy_use_better_wrap_navigation == 1
+ if g:heresy_better_wrap_navigation == 1
call s:SetWrappedTextNavigation()
endif
- if g:heresy_use_shortcuts == 1
- call g:SetHeresyShortcuts()
+ if g:heresy_shortcuts == 1
+ call g:SetShortcuts()
endif
endfunction
+
+" ALT+; for command prompt
+" inoremap <M-;> <C-O>:
+" snoremap <M-;> <C-O>:
+" inoremap <M-c> <C-O>:
+" snoremap <M-c> <C-O>:
+" nnoremap <M-;> :
+" nnoremap <M-c> :
+
+" <ALT+o> replaces native <C-O> for one-time normal mode commands.
+" inoremap <M-o> <C-O>
+" snoremap <M-o> <C-O>
+
+" Select word under cursor
+" inoremap <C-D> <C-O>viw<C-G>
+" Select current line
+" inoremap <C-L> <C-O>V<C-G>
+" Append next line to selection
+" snoremap <C-L> <C-O>gj
+
+" CTRL-A for selecting all text
+" inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
+" snoremap <C-A> <C-O><C-C>gggH<C-O>G
+
+" CTRL+ALTt+k deletes the current line under the cursor
+" TODO: Doesn't work in terminal vim, even with vim-fixkey
+" inoremap <silent> <C-M-K> <C-O>"_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 <silent> <C-M-D> <C-O>"dyy<C-O>"dp
diff --git a/doc/heresy.txt b/doc/heresy.txt
index 72d8123..7135bc5 100644
--- a/doc/heresy.txt
+++ b/doc/heresy.txt
@@ -132,7 +132,7 @@ When adding a new binding of your own that needs Normal mode, you should use
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
+ let g:heresy_shortcuts = 0
inoremap ... custom mapping ...
call heresy#StartHeresy()
<
@@ -144,18 +144,18 @@ 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
+ let g:heresy_app_shortcuts = 1
+ let g:heresy_copypaste_shortcuts = 1
+ let g:heresy_undo_shortcuts = 1
+ let g:heresy_find_shortcuts = 1
+ let g:heresy_line_shortcuts = 1
+ let g:heresy_pane_shortcuts = 1
+ let g:heresy_indentation_shortcuts = 1
" Small fixes to HOME and PAGEUP behaviour
- let g:heresy_use_editor_fixes = 1
+ let g:heresy_navigation_fixes = 1
" Allows scrolling through wrapped lines one visual line at a time
- let g:heresy_use_better_wrap_navigation = 1
+ let g:heresy_better_wrap_navigation = 1
<
==============================================================================
6. Known Issues *vim-heresy-known-issues*
diff --git a/plugin/heresy.vim b/plugin/heresy.vim
index e318f95..f414a66 100644
--- a/plugin/heresy.vim
+++ b/plugin/heresy.vim
@@ -7,17 +7,20 @@
let s:save_cpo = &cpo
set cpo&vim
+" Choose what groups of shortcuts to use (default: all)
+" 0 is off, 1 is on
+" 'shortcuts' controls all but 'better_wrap_navigation'
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
+ \ 'shortcuts': 1,
+ \ 'app_shortcuts': 1,
+ \ 'copypaste_shortcuts': 1,
+ \ 'undo_shortcuts': 1,
+ \ 'find_shortcuts': 1,
+ \ 'line_shortcuts': 1,
+ \ 'pane_shortcuts': 1,
+ \ 'indentation_shortcuts': 1,
+ \ 'navigation_fixes': 1,
+ \ 'better_wrap_navigation': 1
\}
" Fetches existing values from user and sets defaults if not set.