emacs.d/clones/scheme/docs.racket-lang.org/guide/Vim.html

55 lines
25 KiB
HTML
Raw Normal View History

2022-09-30 11:00:09 +02:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=0.8"/><title>24.3&nbsp;Vim</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_0&quot;);">&#9658;</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">The Racket Guide</a></td></tr></table></div><div class="tocviewsublisttop" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1&nbsp;</td><td><a href="intro.html" class="tocviewlink" data-pltdoc="x">Welcome to Racket</a></td></tr><tr><td align="right">2&nbsp;</td><td><a href="to-scheme.html" class="tocviewlink" data-pltdoc="x">Racket Essentials</a></td></tr><tr><td align="right">3&nbsp;</td><td><a href="datatypes.html" class="tocviewlink" data-pltdoc="x">Built-<wbr></wbr>In Datatypes</a></td></tr><tr><td align="right">4&nbsp;</td><td><a href="scheme-forms.html" class="tocviewlink" data-pltdoc="x">Expressions and Definitions</a></td></tr><tr><td align="right">5&nbsp;</td><td><a href="define-struct.html" class="tocviewlink" data-pltdoc="x">Programmer-<wbr></wbr>Defined Datatypes</a></td></tr><tr><td align="right">6&nbsp;</td><td><a href="modules.html" class="tocviewlink" data-pltdoc="x">Modules</a></td></tr><tr><td align="right">7&nbsp;</td><td><a href="contracts.html" class="tocviewlink" data-pltdoc="x">Contracts</a></td></tr><tr><td align="right">8&nbsp;</td><td><a href="i_o.html" class="tocviewlink" data-pltdoc="x">Input and Output</a></td></tr><tr><td align="right">9&nbsp;</td><td><a href="regexp.html" class="tocviewlink" data-pltdoc="x">Regular Expressions</a></td></tr><tr><td align="right">10&nbsp;</td><td><a href="control.html" class="tocviewlink" data-pltdoc="x">Exceptions and Control</a></td></tr><tr><td align="right">11&nbsp;</td><td><a href="for.html" class="tocviewlink" data-pltdoc="x">Iterations and Comprehensions</a></td></tr><tr><td align="right">12&nbsp;</td><td><a href="match.html" class="tocviewlink" data-pltdoc="x">Pattern Matching</a></td></tr><tr><td align="right">13&nbsp;</td><td><a href="classes.html" class="tocviewlink" data-pltdoc="x">Classes and Objects</a></td></tr><tr><td align="right">14&nbsp;</td><td><a href="units.html" class="tocviewlink" data-pltdoc="x">Units</a></td></tr><tr><td align="right">15&nbsp;</td><td><a href="reflection.html" class="tocviewlink" data-pltdoc="x">Reflection and Dynamic Evaluation</a></td></tr><tr><td align="right">16&nbsp;</td><td><a href="macros.html" class="tocviewlink" data-pltdoc="x">Macros</a></td></tr><tr><td align="right">17&nbsp;</td><td><a href="languages.html" class="tocviewlink" data-pltdoc="x">Creating Languages</a></td></tr><tr><td align="right">18&nbsp;</td><td><a href="concurrency.html" class="tocviewlink" data-pltdoc=
for Racket. As of <a href="https://github.com/vim/vim/commit/1aeaf8c0e0421f34e51ef674f0c9a182debe77ae">version 7.3.518</a>,
Vim detects files with the extension <span class="stt">.rkt</span> as having the
<span class="stt">scheme</span> filetype. <a href="https://github.com/vim/vim/commit/9cd91a1e8816d727fbdbf0b3062288e15abc5f4d">Version 8.2.3368</a>
added support for <span class="stt">.rktd</span> and <span class="stt">.rktl</span>.</p><p>In older versions, you can enable filetype detection of Racket
files as Scheme with the following:</p><p><table cellspacing="0" cellpadding="0" class="SVerbatim"><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">if has("autocmd")</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt"></span><span class="hspace">&nbsp;&nbsp;</span><span class="stt">autocmd filetypedetect BufReadPost *.rkt,*.rktl,*.rktd set filetype=scheme</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">endif</span></p></td></tr></table></p><p>If your Vim supports the ftdetect system, in which case it&rsquo;s likely new enough
to support Racket already, you can nevertheless put the following in
<span class="stt">"~/.vim/ftdetect/racket.vim"</span>
(<span class="stt">"$HOME/vimfiles/ftdetect/racket.vim"</span> on MS-Windows; see <span class="stt">:help runtimepath</span>).</p><p><table cellspacing="0" cellpadding="0" class="SVerbatim"><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">" :help ftdetect</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">" If you want to change the filetype only if one has not been set</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">autocmd BufRead,BufNewFile *.rkt,*.rktl,*.rktd setfiletype scheme</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">" If you always want to set this filetype</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">autocmd BufRead,BufNewFile *.rkt,*.rktl,*.rktd set filetype=scheme</span></p></td></tr></table></p><h5 x-source-module="(lib &quot;scribblings/guide/guide.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;vim-plugins&quot;">24.3.1<tt>&nbsp;</tt><a name="(part._vim-plugins)"></a>Plugins</h5><p><div class="SIntrapara">Alternatively, you can use a plugin such as </div><div class="SIntrapara"><ul><li><p><a href="https://github.com/wlangstroth/vim-racket">wlangstroth/vim-racket</a></p></li><li><p><a href="https://github.com/benknoble/vim-racket">benknoble/vim-racket</a></p></li></ul></div><div class="SIntrapara"><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>The major difference between the two is that the
<span class="stt">benknoble/vim-racket</span> fork supports more features out of the box and is
updated more frequently.</p></blockquote></blockquote></blockquote></div><div class="SIntrapara">to enable auto-detection, indentation, and syntax highlighting specifically for
Racket files.</div></p><p><div class="SIntrapara">These plugins work by setting the <span class="stt">filetype</span> option based on the <a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a>
line. For example:</div><div class="SIntrapara"><ul><li><p>A file starting with <a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><a href="https://download.racket-lang.org/releases/8.6/doc/local-redirect/index.html?doc=reference&amp;rel=index.html&amp;version=8.6" class="RktModLink Sq" data-pltdoc="x"><span class="RktSym">racket</span></a><span class="RktMeta"></span> or <a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><a href="https://download.racket-lang.org/releases/8.6/doc/local-redirect/index.html?doc=reference&amp;rel=index.html&amp;version=8.6" class="RktModLink Sq" data-pltdoc="x"><span class="RktSym">racket/base</span></a><span class="RktMeta"></span>
has <span class="stt">filetype</span> equal to <span class="stt">racket</span>.</p></li><li><p>A file starting with <a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><a href="https://download.racket-lang.org/releases/8.6/doc/local-redirect/index.html?doc=scribble&amp;rel=base.html&amp;version=8.6" class="RktModLink Sq" data-pltdoc="x"><span class="RktSym">scribble/base</span></a><span class="RktMeta"></span> or <a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><a href="https://download.racket-lang.org/releases/8.6/doc/local-redirect/index.html?doc=scribble&amp;rel=manual.html&amp;version=8.6" class="RktModLink Sq" data-pltdoc="x"><span class="RktSym">scribble/manual</span></a><span class="RktMeta"></span>
has <span class="stt">filetype</span> equal to <span class="stt">scribble</span>.</p></li></ul></div><div class="SIntrapara">Depending on which plugin you have, modifiers like <span class="RktSym">at-exp</span><span class="RktMeta"></span> may also be
ignored, so that <a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><a href="https://download.racket-lang.org/releases/8.6/doc/local-redirect/index.html?doc=scribble&amp;rel=reader-internals.html%23%2528mod-path._at-exp%2529&amp;version=8.6" class="RktModLink Sq" data-pltdoc="x"><span class="RktSym">at-exp</span></a><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><span class="RktSym">racket</span><span class="RktMeta"></span> is still a <span class="stt">filetype</span> of
<span class="stt">racket</span>.</div></p><p>This approach is more flexible but may lead to more work. Since each
<a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a> has its own <span class="stt">filetype</span>, options, syntax highlighting, and other
features need to be configured for each filetype. This can be done via the
standard <span class="stt">ftplugin</span> mechanism. See for example <span class="stt">:help ftplugin-overrule</span>
and <span class="stt">:help ftplugin</span>: place your options for <span class="stt">&lt;lang&gt;</span> in
<span class="stt">"~/.vim/after/ftplugin/&lt;lang&gt;.vim"</span>
(<span class="stt">"$HOME/vimfiles/after/ftplugin/&lt;lang&gt;.vim"</span> on MS-Windows). Similarly,
syntax files follow the standard mechanism documented in <span class="stt">:help syntax</span>.</p><p>Both plugins come with configuration for Racket
(and possibly other <a href="Module_Syntax.html#%28part._hash-lang%29" class="RktModLink" data-pltdoc="x"><span class="RktMod">#lang</span></a>s) as <span class="stt">ftplugin</span>s. To enable them, use the
<span class="stt">:filetype</span> command as documented in <span class="stt">:help :filetype</span>. You likely want to
turn on filetype plugins (<span class="stt">:help :filetype-plugin-on</span>) and filetype indent
plugins (<span class="stt">:help :filetype-indent-on</span>).</p><h5 x-source-module="(lib &quot;scribblings/guide/guide.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;Indentation&quot;">24.3.2<tt>&nbsp;</tt><a name="(part._.Indentation)"></a>Indentation</h5><p>You can enable indentation for Racket by setting both the <span class="stt">lisp</span> and
<span class="stt">autoindent</span> options in Vim. You will want to customize the buffer-local
<span class="stt">lispwords</span> option to control how special forms are indented. See <span class="stt">:help</span><span class="stt">
</span><span class="stt"></span><span class="stt">&rsquo;</span><span class="stt">lispwords</span><span class="stt">&rsquo;</span><span class="stt"></span>. Both plugins mentioned in <a href="Vim.html#%28part._vim-plugins%29" data-pltdoc="x">Plugins</a> set this option for
you.</p><p>However, the indentation can be limited and may not be as complete as what you
can get in Emacs. You can also use Dorai Sitaram&rsquo;s
<a href="https://github.com/ds26gte/scmindent">scmindent</a> for better
indentation of Racket code. The instructions on how to use the indenter are
available on the website.</p><h5 x-source-module="(lib &quot;scribblings/guide/guide.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;Highlighting&quot;">24.3.3<tt>&nbsp;</tt><a name="(part._.Highlighting)"></a>Highlighting</h5><p>The <a href="https://www.vim.org/scripts/script.php?script_id=1230">Rainbow
Parenthesis</a> script for Vim can be useful for more visible parenthesis
matching. Syntax highlighting for Scheme is shipped with Vim on many platforms,
which will work for the most part with Racket. The vim-racket script
provides good default highlighting settings for you.</p><h5 x-source-module="(lib &quot;scribblings/guide/guide.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;Structured_Editing&quot;">24.3.4<tt>&nbsp;</tt><a name="(part._.Structured_.Editing)"></a>Structured Editing</h5><p>The <a href="https://www.vim.org/scripts/script.php?script_id=2531">Slimv</a>
plugin has a paredit mode that works like paredit in Emacs. However, the plugin
is not aware of Racket. You can either set Vim to treat Racket as Scheme files
or you can modify the paredit script to load on <span class="stt">".rkt"</span> files.</p><p><div class="SIntrapara">For a more Vim-like set of key-mappings, pair either of </div><div class="SIntrapara"><ul><li><p><a href="https://github.com/guns/vim-sexp">guns/vim-sexp</a></p></li><li><p><a href="https://github.com/benknoble/vim-sexp">benknoble/vim-sexp</a></p></li></ul></div><div class="SIntrapara"><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>The <span class="stt">benknoble/vim-sexp</span> fork is slightly more modern vimscript.</p></blockquote></blockquote></blockquote></div><div class="SIntrapara">with <a href="https://github.com/tpope/vim-sexp-mappings-for-regular-people">tpope/vim-sexp-mappings-for-regular-people</a>.
The experience is on par with paredit, but more comfortable for the fingers.</div></p><h5 x-source-module="(lib &quot;scribblings/guide/guide.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;REPLs&quot;">24.3.5<tt>&nbsp;</tt><a name="(part._.R.E.P.Ls)"></a>REPLs</h5><p><div class="SIntrapara">There are many general-purpose Vim + REPL plugins out there. Here are a few that
support Racket out of the box: </div><div class="SIntrapara"><ul><li><p><a href="https://github.com/rhysd/reply.vim">rhysd/reply.vim</a></p></li><li><p><a href="https://github.com/kovisoft/slimv">kovisoft/slimv</a>, if you are using the <span class="stt">scheme</span> filetype</p></li><li><p><a href="https://github.com/benknoble/vim-simpl">benknoble/vim-simpl</a></p></li></ul></div></p><h5 x-source-module="(lib &quot;scribblings/guide/guide.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;Scribble&quot;">24.3.6<tt>&nbsp;</tt><a name="(part._.Scribble)"></a>Scribble</h5><p><div class="SIntrapara">Vim support for writing scribble documents is provided by </div><div class="SIntrapara"><ul><li><p><a href="https://github.com/wilbowma/scribble.vim">wilbowma/scribble.vim</a></p></li><li><p><a href="https://github.com/benknoble/scribble.vim">benknoble/scribble.vim</a></p></li></ul></div><div class="SIntrapara"><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>Again, <span class="stt">benknoble/scribble.vim</span> is updated more frequently and
is somewhat more modern.</p></blockquote></blockquote></blockquote></div></p><h5 x-source-module="(lib &quot;scribblings/guide/guide.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;Miscellaneous&quot;">24.3.7<tt>&nbsp;</tt><a name="(part._.Miscellaneous)"></a>Miscellaneous</h5><p>If you are installing many Vim plugins (not necessary specific to Racket), we
recommend using a plugin that will make loading other plugins easier. There are
many plugin managers.</p><p><a href="https://github.com/tpope/vim-pathogen">Pathogen</a> is one plugin that
does this; using it, you can install new plugins by extracting them to
subdirectories in the <span class="stt">"bundle"</span> folder of your personal Vim files
(<span class="stt">"~/.vim"</span> on Unix, <span class="stt">"$HOME/vimfiles"</span> on MS-Windows).</p><p>With newer Vim versions, you can use the package system (<span class="stt">:help packages</span>).</p><p>One relatively up-to-date reference on the various managers is
<a href="https://vi.stackexchange.com/q/388/10604">What are the differences between the vim plugin managers?</a>.
The same site, <a href="https://vi.stackexchange.com">Vi &amp; Vim</a> is a great
place to get help from Vimmers.</p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" id="searchbox" type="text" tabindex="1" placeholder="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, &quot;8.6&quot;, &quot;../&quot;);"/></form>&nbsp;&nbsp;<a href="https://docs.racket-lang.org/index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot(&quot;8.6&quot;);">top</a><span class="tocsettoggle">&nbsp;&nbsp;<a href="javascript:void(0);" title="show/hide table of contents" onclick="TocsetToggle();">contents</a></span></span><span class="navright">&nbsp;&nbsp;<a href="Emacs.html" title="backward to &quot;24.2 Emacs&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="other-editors.html" title="up to &quot;24 Command-Line Tools and Your Editor of Choice&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="Sublime_Text.html" title="forward to &quot;24.4 Sublime Text&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div></div></div><div id="contextindicator">&nbsp;</div></body></html>