<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>blog.n11n [tag: tips]</title>
  <link>https://blog.n11n.ca</link>
  <description>Nicholas' blog</description>
  <language>en</language>
  <atom:link href="https://blog.n11n.ca/rss.xml" rel="self" type="application/rss+xml" />

  <item>
    <title>Vim tips</title>
    <pubDate>Thu, 19 Feb 2026 00:00:00 +0000</pubDate>
    <link>https://blog.n11n.ca/vim-tips</link>
    <guid>https://blog.n11n.ca/3</guid>
    <description>Some useful tips for using vim</description>
    <content:encoded><![CDATA[<p>Here are a handful of useful tips for using <a href="https://www.vim.org">Vim</a> that I've picked up over the years.</p> <h2>Custom functions</h2> <p>Defining a <a href="https://vimdoc.sourceforge.net/htmldoc/usr_41.html#41.7">custom function</a> can be done like:</p> <pre><code>function! InsertDate()</code><br><code>  execute "normal \"=strftime('%FT%T%z')\&lt;CR>p"</code><br><code>endfunction</code><br><br><code>" names must start with an uppercase letter</code></pre> <p>then called using <code>:call InsertDate()</code> or simplified with a user-defined command:</p> <pre><code>command! Date call InsertDate()</code></pre> <p>and simply called with <code>:Date</code></p> <h2>Maps</h2> <p>I try not to rely on too many <a href="https://vimdoc.sourceforge.net/htmldoc/map.html#mapping">maps</a>, but I do use these everyday:</p> <pre><code>" open netrw in directory of current file</code><br><code>nnoremap &lt;ESC> :Ex&lt;CR></code><br><br><code>" move visually selected blocks up/down</code><br><code>vnoremap K :m '&lt;-2&lt;CR>gv=gv</code><br><code>vnoremap J :m '>+1&lt;CR>gv=gv</code><br><br><code>" escape terminal mode</code><br><code>tnoremap &lt;Esc> &lt;C-\>&lt;C-n></code></pre> <p>and some for working with multiple windows:</p> <pre><code>" resize windows</code><br><code>nnoremap &lt;C-Up> 2&lt;C-w>+&lt;CR></code><br><code>nnoremap &lt;C-Down> 2&lt;C-w>-&lt;CR></code><br><code>nnoremap &lt;C-Left> 2&lt;C-w>&lt;&lt;CR></code><br><code>nnoremap &lt;C-Right> 2&lt;C-w>>&lt;CR></code><br><br><code>" switch windows</code><br><code>nnoremap &lt;C-h> &lt;C-w>h</code><br><code>nnoremap &lt;C-j> &lt;C-w>j</code><br><code>nnoremap &lt;C-k> &lt;C-w>k</code><br><code>nnoremap &lt;C-l> &lt;C-w>l</code></pre> <h2>Settings</h2> <p>A few of the more important settings in my <code>.vimrc</code> file:</p> <ul> <li> <strong>set lazyredraw</strong> - makes macros complete faster by not redrawing the screen each time. </li><li> <strong>set smartcase/ignorecase</strong> - both of these on allows for searches without capital letters to be case insensitive, while searches with a capital character are case sensitive. </li><li> <strong>set undofile</strong> - persistent undo even after closing Vim. </li> </ul> <h2>Shell commands</h2> <p>Vim can <a href="https://vimdoc.sourceforge.net/htmldoc/usr_21.html#21.2">execute shell commands</a> using <code>:!{command}</code>. The command is run in a new window before prompting you to hit <strong>ENTER</strong> to return where you were.</p> <p>This can be modified in a few useful ways:</p> <pre><code>:r !{command}    execute {command} and read output into Vim</code><br><code>:.!{command}     execute {command} and replace current line with output</code><br><code>:w !{command}    execute {command} with text as input to {command}</code><br><code>:3,6!{command}   filter lines 3-6 through {command}</code></pre> <p>Note: pressing <code>!!</code> in Normal mode results in <code>:.!</code></p> <h2>Other</h2> <p>Lines in a file can be sorted using <code>:sort</code> - this also works on visually selected lines.</p> <p>Use <code>:sort u</code> to remove any duplicates when sorting.</p> <p>Numbers in Vim can be incremented and decremented with <code>Ctrl-a</code> and <code>Ctrl-x</code> respectively. This jumps to the next number on the line after the cursor. A count can also be specified like <code>5&lt;C-a></code> to increment the value by 5. Even better, this works on numbers in binary (0b1010), hexadecimal (0x1abc), and octal (07) as well.</p> <p>The ASCII value of the character under the cursor can be displayed by pressing <code>ga</code> in Normal mode or <code>:as</code> / <code>:ascii</code> on the command line.</p> <h2>vimtutor</h2> <p>A program called <strong>vimtutor</strong> comes installed with Vim and is designed to help learn concepts through hands on examples.</p> <p><a href="https://www.vim.org/vim-9.2-released.php">Vim 9.2</a> was just released and includes a new built-in tutor plugin started via <code>:Tutor</code>. It looks like a nice modern version of the original, and after trying it I would highly recommend checking it out.</p>         <div class="tags"><a href="https://blog.n11n.ca/tag/editor">editor</a> <a href="https://blog.n11n.ca/tag/tips">tips</a> <a href="https://blog.n11n.ca/tag/vim">vim</a></div> <br>]]></content:encoded>
  </item>
</channel>
</rss>
