Edit Page
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 15: | Line 15: | ||
Here is a macro to insert footnotes. It requires two differents shortcuts, one for entering the first footnote, the other one for all subsequent footnotes. |
Here is a macro to insert footnotes. It requires two differents shortcuts, one for entering the first footnote, the other one for all subsequent footnotes. |
||
− | When you hit "K0" (first footnote) or "KK" (all other footnotes) in normal mode, your cursor is positioned at the end of the document, in the footnote & in insert mode. The "a" bookmark is set to the place where you entered the footnote in the text. so a "`a" will bring you back to the location of the footnote in the text. |
+ | When you hit "K0" (first footnote) or "KK" (all other footnotes) in normal mode, your cursor is positioned at the end of the document, in the footnote & in insert mode. The "a" bookmark is set to the place where you entered the footnote in the text. so a "`a" will bring you back to the location of the footnote in the text. |
<pre> |
<pre> |
||
− | " for now requires entering K0 for the first footnote and then KK nmap K0 i[0] |
+ | " for now requires entering K0 for the first footnote and then KK nmap K0 i[0]<esc>maG$i<end><enter>[0] |
− | nmap KK maG$?\[[0-9]*\] |
+ | nmap KK maG$?\[[0-9]*\]<enter>yt]G$i<end><enter><esc>p<C-a>i<end>]<esc>`aP<C-a><right>i]<esc>maG$i<end><end> |
</pre> |
</pre> |
||
Line 43: | Line 43: | ||
here is the updated code: |
here is the updated code: |
||
<pre> |
<pre> |
||
− | nmap K0 i[0] |
+ | nmap K0 i[0]<esc>maG?--<enter><up>$i<end><enter>[0] |
− | nmap KK maG$?\[[0-9]*\] |
+ | nmap KK maG$?\[[0-9]*\]<enter>yt]G?--<enter><up>$i<end><enter><esc>p<C-a>i<end>]<esc>`aP<C-a><right>i]<esc>maG?--<enter><up>$i<end><end> |
</pre> |
</pre> |
||
Line 54: | Line 54: | ||
here is the whole code: |
here is the whole code: |
||
<pre> |
<pre> |
||
− | nmap KK :call InsertFootNote() |
+ | nmap KK :call InsertFootNote()<LF> |
function! InsertFootNote() |
function! InsertFootNote() |
||
Line 63: | Line 63: | ||
. " was there already a footnote? |
. " was there already a footnote? |
||
. if search("\[[0-9]*]", "w") |
. if search("\[[0-9]*]", "w") |
||
− | . . " yes = |
+ | . . " yes => get the number, copy it, increase |
. . " it, put it at the footnote position, put |
. . " it, put it at the footnote position, put |
||
. . " the footnote text and position the cursor back. |
. . " the footnote text and position the cursor back. |
||
− | . . execute "normal G$?\[[0-9]*\]\ |
+ | . . execute "normal G$?\[[0-9]*\]\<enter>yt]:call GotoFootNoteLocation()\<LF>$i\<end>\<enter>\<esc>p\<C-a>i\<end>] " . footNoteText . "\<esc>`aP\<C-a>\<right>i]\<esc>" |
. else |
. else |
||
− | . . " no = |
+ | . . " no => put [0], add at the end [0] + footnote text |
. . " and position cursor back |
. . " and position cursor back |
||
− | . . execute "normal i[0]\ |
+ | . . execute "normal i[0]\<esc>:call GotoFootNoteLocation()\<LF>$i\<end> |
− | \ |
+ | \<enter>\<enter>[0] " . footNoteText . "\<esc>`a" |
. endif |
. endif |
||
endfunction |
endfunction |
||
Line 97: | Line 97: | ||
. . " ok, there's a sig. |
. . " ok, there's a sig. |
||
. . " just go on top of it. |
. . " just go on top of it. |
||
− | . . execute "normal \ |
+ | . . execute "normal \<up>" |
. else |
. else |
||
. . " no sig: we go at the end of the |
. . " no sig: we go at the end of the |
||
Line 109: | Line 109: | ||
This is easier: |
This is easier: |
||
<pre> |
<pre> |
||
− | inoremap ,f |
+ | inoremap ,f <esc>:call VimFootnotes()<cr> |
− | inoremap ,r |
+ | inoremap ,r <esc>:exe b:pos<cr> |
function! VimFootnotes() |
function! VimFootnotes() |
||
Line 118: | Line 118: | ||
else |
else |
||
let b:vimfootnotenumber = 0 |
let b:vimfootnotenumber = 0 |
||
− | let cr = "\ |
+ | let cr = "\<cr>" |
endif |
endif |
||
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l' |
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l' |
||
− | exe "normal a[".b:vimfootnotenumber."]\ |
+ | exe "normal a[".b:vimfootnotenumber."]\<esc>G" |
if search("-- $", "b") |
if search("-- $", "b") |
||
exe "normal O".cr."[".b:vimfootnotenumber."] " |
exe "normal O".cr."[".b:vimfootnotenumber."] " |
||
Line 132: | Line 132: | ||
---- |
---- |
||
− | This works just fine -- and is a pretty cool idea -- except that it would be nice if ,r would restart insert-mode when done. Replacing the beginning of the rhs with |
+ | This works just fine -- and is a pretty cool idea -- except that it would be nice if ,r would restart insert-mode when done. Replacing the beginning of the rhs with <c-o> instead of <esc> works in all cases except when the footnote was added to the end of the line (more likely than not, actually, since footnotes might be added during the initial text entry). |
---- |
---- |
||
Line 146: | Line 146: | ||
else |
else |
||
let b:vimfootnotenumber = 0 |
let b:vimfootnotenumber = 0 |
||
− | let cr = "\ |
+ | let cr = "\<cr>" |
endif |
endif |
||
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l' |
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l' |
||
− | exe "normal a[".b:vimfootnotenumber."]\ |
+ | exe "normal a[".b:vimfootnotenumber."]\<esc>G" |
if search("-- $", "b") |
if search("-- $", "b") |
||
exe "normal O".cr."[".b:vimfootnotenumber."] " . footNoteText |
exe "normal O".cr."[".b:vimfootnotenumber."] " . footNoteText |
||
Line 169: | Line 169: | ||
Play with b:vimfootnotetype :) Alpha, alpha, arabic - roman for footnotes is rare |
Play with b:vimfootnotetype :) Alpha, alpha, arabic - roman for footnotes is rare |
||
<pre> |
<pre> |
||
− | inoremap ,f |
+ | inoremap ,f <C-O>:call VimFootnotes()<CR> |
− | inoremap ,r |
+ | inoremap ,r <C-O>:q<CR><Right> |
let b:vimfootnotetype = "alpha" |
let b:vimfootnotetype = "alpha" |
||
Line 183: | Line 183: | ||
let upper = "-32" |
let upper = "-32" |
||
endif |
endif |
||
− | if (a:footnumber |
+ | if (a:footnumber <= 26) |
let ftnumber = nr2char(a:footnumber+96+upper) |
let ftnumber = nr2char(a:footnumber+96+upper) |
||
− | elseif (a:footnumber |
+ | elseif (a:footnumber <= 52) |
let ftnumber = nr2char(a:footnumber+70+upper).nr2char(a:footnumber+70+upper) |
let ftnumber = nr2char(a:footnumber+70+upper).nr2char(a:footnumber+70+upper) |
||
else |
else |
||
Line 205: | Line 205: | ||
let b:vimfootnotenumber = 1 |
let b:vimfootnotenumber = 1 |
||
let b:vimfootnotemark = VimFootnoteType(b:vimfootnotenumber) |
let b:vimfootnotemark = VimFootnoteType(b:vimfootnotenumber) |
||
− | let cr = "\ |
+ | let cr = "\<cr>" |
endif |
endif |
||
"let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l' |
"let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l' |
||
− | exe "normal a[".b:vimfootnotemark."]\ |
+ | exe "normal a[".b:vimfootnotemark."]\<esc>" |
− | let splitposition = &splitbelow |
+ | let splitposition = &splitbelow |
set splitbelow |
set splitbelow |
||
:5 split |
:5 split |
||
− | let &splitbelow = splitposition |
+ | let &splitbelow = splitposition |
normal G |
normal G |
||
if search("^-- $", "bW") |
if search("^-- $", "bW") |
||
Line 240: | Line 240: | ||
" Because I don't like to start the footnotes with [0] |
" Because I don't like to start the footnotes with [0] |
||
− | if !hasmapto(' |
+ | if !hasmapto('<Plug>AddVimFootnote', 'i') |
− | imap |
+ | imap <C-X>f <Plug>AddVimFootnote |
endif |
endif |
||
− | if !hasmapto(' |
+ | if !hasmapto('<Plug>AddVimFootnote', 'n') |
− | nmap |
+ | nmap <leader>af <Plug>AddVimFootnote |
endif |
endif |
||
− | nnoremap |
+ | nnoremap <Plug>AddVimFootnote :call <sid>VimFootnotes('a')<cr> |
− | inoremap |
+ | inoremap <Plug>AddVimFootnote <c-o>:call <sid>VimFootnotes('i')<cr> |
− | "Note: be sure there is *NO* space after the ' |
+ | "Note: be sure there is *NO* space after the '<cr>' when you copy-paste. |
" The previous paragraph enables anyone to remap the functions calls |
" The previous paragraph enables anyone to remap the functions calls |
||
" to anything else that the developper's default bindings. To do so, add into |
" to anything else that the developper's default bindings. To do so, add into |
||
" your .vimrc something like : |
" your .vimrc something like : |
||
− | " nmap ,f |
+ | " nmap ,f <Plug>AddVimFootNote |
function! s:VimFootnotes(appendcmd) |
function! s:VimFootnotes(appendcmd) |
||
.... |
.... |
||
:below 3sp |
:below 3sp |
||
" note that you don't need change the value of 'splitbelow' |
" note that you don't need change the value of 'splitbelow' |
||
− | exe "normal ".a:appendcmd."[".b:vimfootnotenumber."]\ |
+ | exe "normal ".a:appendcmd."[".b:vimfootnotenumber."]\<esc>G" |
... |
... |
||
</pre> |
</pre> |