Vim Tips Wiki
Register
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

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]<Esc>maG$i<End><CR>[0]
+
" for now requires entering K0 for the first footnote and then KK nmap K0 i[0]&lt;esc&gt;maG$i&lt;end&gt;&lt;enter&gt;[0]
nmap KK maG$?\[[0-9]*\]<CR>yt]G$i<End><CR><Esc>p<C-a>i<End>]<Esc>`aP<C-a><Right>i]<Esc>maG$i<End><End>
+
nmap KK maG$?\[[0-9]*\]&lt;enter&gt;yt]G$i&lt;end&gt;&lt;enter&gt;&lt;esc&gt;p&lt;C-a&gt;i&lt;end&gt;]&lt;esc&gt;`aP&lt;C-a&gt;&lt;right&gt;i]&lt;esc&gt;maG$i&lt;end&gt;&lt;end&gt;
 
</pre>
 
</pre>
   
Line 43: Line 43:
 
here is the updated code:
 
here is the updated code:
 
<pre>
 
<pre>
nmap K0 i[0]<Esc>maG?--<CR><Up>$i<End><CR>[0]
+
nmap K0 i[0]&lt;esc&gt;maG?--&lt;enter&gt;&lt;up&gt;$i&lt;end&gt;&lt;enter&gt;[0]
nmap KK maG$?\[[0-9]*\]<CR>yt]G?--<CR><Up>$i<End><CR><Esc>p<C-a>i<End>]<Esc>`aP<C-a><Right>i]<Esc>maG?--<CR><Up>$i<End><End>
+
nmap KK maG$?\[[0-9]*\]&lt;enter&gt;yt]G?--&lt;enter&gt;&lt;up&gt;$i&lt;end&gt;&lt;enter&gt;&lt;esc&gt;p&lt;C-a&gt;i&lt;end&gt;]&lt;esc&gt;`aP&lt;C-a&gt;&lt;right&gt;i]&lt;esc&gt;maG?--&lt;enter&gt;&lt;up&gt;$i&lt;end&gt;&lt;end&gt;
 
</pre>
 
</pre>
   
Line 54: Line 54:
 
here is the whole code:
 
here is the whole code:
 
<pre>
 
<pre>
nmap KK :call InsertFootNote()<LF>
+
nmap KK :call InsertFootNote()&lt;LF&gt;
   
 
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 => get the number, copy it, increase
+
. . " yes =&gt; 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]*\]\<CR>yt]:call GotoFootNoteLocation()\<LF>$i\<End>\<CR>\<Esc>p\<C-a>i\<End>] " . footNoteText . "\<Esc>`aP\<C-a>\<Right>i]\<Esc>"
+
. . execute "normal G$?\[[0-9]*\]\&lt;enter&gt;yt]:call GotoFootNoteLocation()\&lt;LF&gt;$i\&lt;end&gt;\&lt;enter&gt;\&lt;esc&gt;p\&lt;C-a&gt;i\&lt;end&gt;] " . footNoteText . "\&lt;esc&gt;`aP\&lt;C-a&gt;\&lt;right&gt;i]\&lt;esc&gt;"
 
. else
 
. else
. . " no => put [0], add at the end [0] + footnote text
+
. . " no =&gt; put [0], add at the end [0] + footnote text
 
. . " and position cursor back
 
. . " and position cursor back
. . execute "normal i[0]\<Esc>:call GotoFootNoteLocation()\<LF>$i\<End>
+
. . execute "normal i[0]\&lt;esc&gt;:call GotoFootNoteLocation()\&lt;LF&gt;$i\&lt;end&gt;
\<CR>\<CR>[0] " . footNoteText . "\<Esc>`a"
+
\&lt;enter&gt;\&lt;enter&gt;[0] " . footNoteText . "\&lt;esc&gt;`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 \<Up>"
+
. . execute "normal \&lt;up&gt;"
 
. 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 <Esc>:call VimFootnotes()<CR>
+
inoremap ,f &lt;esc&gt;:call VimFootnotes()&lt;cr&gt;
inoremap ,r <Esc>:exe b:pos<CR>
+
inoremap ,r &lt;esc&gt;:exe b:pos&lt;cr&gt;
   
 
function! VimFootnotes()
 
function! VimFootnotes()
Line 118: Line 118:
 
else
 
else
 
let b:vimfootnotenumber = 0
 
let b:vimfootnotenumber = 0
let cr = "\<CR>"
+
let cr = "\&lt;cr&gt;"
 
endif
 
endif
 
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
 
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
exe "normal a[".b:vimfootnotenumber."]\<Esc>G"
+
exe "normal a[".b:vimfootnotenumber."]\&lt;esc&gt;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 <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).
+
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 &lt;c-o&gt; instead of &lt;esc&gt; 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 = "\<CR>"
+
let cr = "\&lt;cr&gt;"
 
endif
 
endif
 
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
 
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
exe "normal a[".b:vimfootnotenumber."]\<Esc>G"
+
exe "normal a[".b:vimfootnotenumber."]\&lt;esc&gt;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 <C-O>:call VimFootnotes()<CR>
+
inoremap ,f &lt;C-O&gt;:call VimFootnotes()&lt;CR&gt;
inoremap ,r <C-O>:q<CR><Right>
+
inoremap ,r &lt;C-O&gt;:q&lt;CR&gt;&lt;Right&gt;
   
 
let b:vimfootnotetype = "alpha"
 
let b:vimfootnotetype = "alpha"
Line 183: Line 183:
 
let upper = "-32"
 
let upper = "-32"
 
endif
 
endif
if (a:footnumber <= 26)
+
if (a:footnumber &lt;= 26)
 
let ftnumber = nr2char(a:footnumber+96+upper)
 
let ftnumber = nr2char(a:footnumber+96+upper)
elseif (a:footnumber <= 52)
+
elseif (a:footnumber &lt;= 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 = "\<CR>"
+
let cr = "\&lt;cr&gt;"
 
endif
 
endif
 
"let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
 
"let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
exe "normal a[".b:vimfootnotemark."]\<Esc>"
+
exe "normal a[".b:vimfootnotemark."]\&lt;esc&gt;"
let splitposition = &splitbelow
+
let splitposition = &amp;splitbelow
 
set splitbelow
 
set splitbelow
 
:5 split
 
:5 split
let &splitbelow = splitposition
+
let &amp;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('<Plug>AddVimFootnote', 'i')
+
if !hasmapto('&lt;Plug&gt;AddVimFootnote', 'i')
imap <C-X>f <Plug>AddVimFootnote
+
imap &lt;C-X&gt;f &lt;Plug&gt;AddVimFootnote
 
endif
 
endif
if !hasmapto('<Plug>AddVimFootnote', 'n')
+
if !hasmapto('&lt;Plug&gt;AddVimFootnote', 'n')
nmap <Leader>af <Plug>AddVimFootnote
+
nmap &lt;leader&gt;af &lt;Plug&gt;AddVimFootnote
 
endif
 
endif
nnoremap <Plug>AddVimFootnote :call <SID>VimFootnotes('a')<CR>
+
nnoremap &lt;Plug&gt;AddVimFootnote :call &lt;sid&gt;VimFootnotes('a')&lt;cr&gt;
inoremap <Plug>AddVimFootnote <c-o>:call <SID>VimFootnotes('i')<CR>
+
inoremap &lt;Plug&gt;AddVimFootnote &lt;c-o&gt;:call &lt;sid&gt;VimFootnotes('i')&lt;cr&gt;
"Note: be sure there is *NO* space after the '<CR>' when you copy-paste.
+
"Note: be sure there is *NO* space after the '&lt;cr&gt;' 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 <Plug>AddVimFootNote
+
" nmap ,f &lt;Plug&gt;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."]\<Esc>G"
+
exe "normal ".a:appendcmd."[".b:vimfootnotenumber."]\&lt;esc&gt;G"
 
...
 
...
 
</pre>
 
</pre>
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)