From 9bdfb49d08232b9c226cbdc31fe4a820696bb597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 7 Nov 2015 23:28:03 +0100 Subject: [PATCH] Updated initialization of default mappings Now a default mapping is not created if the user has defined a custom mapping for the corresponding (vimtex-...) mapping. --- autoload/vimtex.vim | 131 +++++++++++++++++++++++--------------------- doc/vimtex.txt | 28 +++++++--- 2 files changed, 88 insertions(+), 71 deletions(-) diff --git a/autoload/vimtex.vim b/autoload/vimtex.vim index 077dc25..6928ed1 100644 --- a/autoload/vimtex.vim +++ b/autoload/vimtex.vim @@ -183,6 +183,7 @@ function! s:init_buffer() " {{{1 " " Attach autocommands " + augroup vimtex_buffers au BufFilePre call s:filename_changed_pre() au BufFilePost call s:filename_changed_post() @@ -195,84 +196,90 @@ endfunction function! s:init_mappings() " {{{1 if !get(g:,'vimtex_mappings_enabled', 1) | return | endif - nmap li (vimtex-info) + function! s:map(mode, lhs, rhs) + if !hasmapto(a:rhs, a:mode) + silent execute a:mode . 'map ' a:lhs a:rhs + endif + endfunction - nmap dse (vimtex-delete-env) - nmap dsc (vimtex-delete-cmd) - nmap cse (vimtex-change-env) - nmap csc (vimtex-change-cmd) - nmap tse (vimtex-toggle-star) - nmap tsd (vimtex-toggle-delim) - nmap (vimtex-create-cmd) - imap (vimtex-create-cmd) - imap ]] (vimtex-close-env) + call s:map('n', 'li', '(vimtex-info)') + + call s:map('n', 'dse', '(vimtex-delete-env)') + call s:map('n', 'dsc', '(vimtex-delete-cmd)') + call s:map('n', 'cse', '(vimtex-change-env)') + call s:map('n', 'csc', '(vimtex-change-cmd)') + call s:map('n', 'tse', '(vimtex-toggle-star)') + call s:map('n', 'tsd', '(vimtex-toggle-delim)') + call s:map('n', '', '(vimtex-create-cmd)') + call s:map('i', '', '(vimtex-create-cmd)') + call s:map('i', ']]', '(vimtex-close-env)') if g:vimtex_latexmk_enabled - nmap ll (vimtex-compile-toggle) - nmap lo (vimtex-compile-output) - nmap lk (vimtex-stop) - nmap lK (vimtex-stop-all) - nmap le (vimtex-errors) - nmap lc (vimtex-clean) - nmap lC (vimtex-clean-full) - nmap lg (vimtex-status) - nmap lG (vimtex-status-all) + call s:map('n', 'll', '(vimtex-compile-toggle)') + call s:map('n', 'lo', '(vimtex-compile-output)') + call s:map('n', 'lk', '(vimtex-stop)') + call s:map('n', 'lK', '(vimtex-stop-all)') + call s:map('n', 'le', '(vimtex-errors)') + call s:map('n', 'lc', '(vimtex-clean)') + call s:map('n', 'lC', '(vimtex-clean-full)') + call s:map('n', 'lg', '(vimtex-status)') + call s:map('n', 'lG', '(vimtex-status-all)') endif if g:vimtex_motion_enabled - nmap % (vimtex-%) - xmap % (vimtex-%) - omap % (vimtex-%) - nmap } (vimtex-}) - nmap { (vimtex-{) - xmap } (vimtex-}) - xmap { (vimtex-{) - omap } (vimtex-}) - omap { (vimtex-{) - xmap ip (vimtex-ip) - xmap ap (vimtex-ap) - omap ip (vimtex-ip) - omap ap (vimtex-ap) - nmap ]] (vimtex-]]) - nmap ][ (vimtex-][) - nmap [] (vimtex-[]) - nmap [[ (vimtex-[[) - xmap ]] (vimtex-]]) - xmap ][ (vimtex-][) - xmap [] (vimtex-[]) - xmap [[ (vimtex-[[) - omap ]] (vimtex-]]) - omap ][ (vimtex-][) - omap [] (vimtex-[]) - omap [[ (vimtex-[[) - xmap ie (vimtex-ie) - xmap ae (vimtex-ae) - omap ie (vimtex-ie) - omap ae (vimtex-ae) - xmap i$ (vimtex-i$) - xmap a$ (vimtex-a$) - omap i$ (vimtex-i$) - omap a$ (vimtex-a$) - xmap id (vimtex-id) - xmap ad (vimtex-ad) - omap id (vimtex-id) - omap ad (vimtex-ad) + call s:map('n', '%', '(vimtex-%)') + call s:map('x', '%', '(vimtex-%)') + call s:map('o', '%', '(vimtex-%)') + call s:map('n', '}', '(vimtex-})') + call s:map('n', '{', '(vimtex-{)') + call s:map('x', '}', '(vimtex-})') + call s:map('x', '{', '(vimtex-{)') + call s:map('o', '}', '(vimtex-})') + call s:map('o', '{', '(vimtex-{)') + call s:map('n', ']]', '(vimtex-]])') + call s:map('n', '][', '(vimtex-][)') + call s:map('n', '[]', '(vimtex-[])') + call s:map('n', '[[', '(vimtex-[[)') + call s:map('x', ']]', '(vimtex-]])') + call s:map('x', '][', '(vimtex-][)') + call s:map('x', '[]', '(vimtex-[])') + call s:map('x', '[[', '(vimtex-[[)') + call s:map('o', ']]', '(vimtex-]])') + call s:map('o', '][', '(vimtex-][)') + call s:map('o', '[]', '(vimtex-[])') + call s:map('o', '[[', '(vimtex-[[)') + call s:map('x', 'ie', '(vimtex-ie)') + call s:map('x', 'ae', '(vimtex-ae)') + call s:map('o', 'ie', '(vimtex-ie)') + call s:map('o', 'ae', '(vimtex-ae)') + call s:map('x', 'i$', '(vimtex-i$)') + call s:map('x', 'a$', '(vimtex-a$)') + call s:map('o', 'i$', '(vimtex-i$)') + call s:map('o', 'a$', '(vimtex-a$)') + call s:map('x', 'id', '(vimtex-id)') + call s:map('x', 'ad', '(vimtex-ad)') + call s:map('o', 'id', '(vimtex-id)') + call s:map('o', 'ad', '(vimtex-ad)') + call s:map('x', 'ip', '(vimtex-ip)') + call s:map('x', 'ap', '(vimtex-ap)') + call s:map('o', 'ip', '(vimtex-ip)') + call s:map('o', 'ap', '(vimtex-ap)') endif if g:vimtex_toc_enabled - nmap lt (vimtex-toc-open) - nmap lT (vimtex-toc-toggle) + call s:map('n', 'lt', '(vimtex-toc-open)') + call s:map('n', 'lT', '(vimtex-toc-toggle)') endif if g:vimtex_labels_enabled - nmap ly (vimtex-labels-open) - nmap lY (vimtex-labels-toggle) + call s:map('n', 'ly', '(vimtex-labels-open)') + call s:map('n', 'lY', '(vimtex-labels-toggle)') endif if g:vimtex_view_enabled - nmap lv (vimtex-view) + call s:map('n', 'lv', '(vimtex-view)') if has_key(b:vimtex.viewer, 'reverse_search') - nmap lr (vimtex-reverse-search) + call s:map('n', 'lr', '(vimtex-reverse-search)') endif endif endfunction diff --git a/doc/vimtex.txt b/doc/vimtex.txt index fbb95db..27f121b 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -244,22 +244,32 @@ USAGE *vimtex-usage* Default mappings~ *vimtex-default-mappings* -|vimtex| is designed to be controlled by a selection of mappings. The default -mappings are listed below. Most of the mappings are also available as -commands, see |vimtex-commands|. +|vimtex| is designed to be controlled by a selection of mappings. Note, +though, that most of the mappings are also available as commands, see +|vimtex-commands|. -In addition to the mappings listed below, |vimtex| provides convenient insert -mode mappings to make it easier and faster to type mathematical equations. -This feature is explained in more detail later, see |vimtex-imaps|. +Many of the mappings utilize the |maplocalleader|. The right-hand sides are +provided as -mappings, see |using-|. For any given map, the +default mapping will only be created if it does not already exist. This means +that if a user defines a custom mapping, e.g. with > -If one prefers, one may disable the default mappings through the option -|g:vimtex_mappings_enabled|. One can then define custom mappings through the -listed RHS -maps or by mapping the available commands. + nmap li (vimtex-info) + +then the corresponding default left-hand side will not be mapped. + +If one prefers, one may disable all the default mappings through the option +|g:vimtex_mappings_enabled|. One must then define custom mappings for all +desired features through the listed RHS -maps or by mapping the +available commands. In the below list of mappings, LHS is the default mapping, RHS is the corresponding -maps, and MODE indicates in which vim mode the mappings are valid. +In addition to the mappings listed below, |vimtex| provides convenient insert +mode mappings to make it easier and faster to type mathematical equations. +This feature is explained in more detail later, see |vimtex-imaps|. + -----------------------------------------------------------~ LHS RHS MODE~ -----------------------------------------------------------~