<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>emacs &amp;mdash; Little Step</title>
    <link>https://rex.writeas.com/tag:emacs</link>
    <description></description>
    <pubDate>Sat, 09 May 2026 23:27:18 +0000</pubDate>
    <item>
      <title>Write with sudo</title>
      <link>https://rex.writeas.com/write-with-sudo?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Today I learn a trick on nixCraft to save a file without root permission in vim.&#xA;&#xA;The simple case is like this:&#xA;&#xA;You want to change a config file using vim, and after you edit, you got a permission problem, you don&#39;t have the permission.&#xA;&#xA;So how to keep the current edit and save the change, the simple command is :w !sudo tee %.&#xA;&#xA;Explanation as below:&#xA;&#xA;:w – Write a file (actually buffer).&#xA;!sudo – Call shell with sudo command.&#xA;tee – The output of write (vim :w) command redirected using tee.&#xA;% – The % is nothing but current file name.&#xA;&#xA;But what about Emacs, how do we do this in Emacs, we also got one:&#xA;&#xA;C-x C-f /sudo::/path/to/file&#xA;&#xA;It uses Tramp module to do the same thing.&#xA;&#xA;#vim #emacs]]&gt;</description>
      <content:encoded><![CDATA[<p>Today I learn a trick on <a href="https://www.cyberciti.biz/faq/vim-vi-text-editor-save-file-without-root-permission/" rel="nofollow">nixCraft </a>to save a file without root permission in vim.</p>

<p>The simple case is like this:</p>

<p>You want to change a config file using vim, and after you edit, you got a permission problem, you don&#39;t have the permission.</p>

<p>So how to keep the current edit and save the change, the simple command is <strong>:w !sudo tee %</strong>.</p>

<p>Explanation as below:</p>

<pre><code>:w – Write a file (actually buffer).
!sudo – Call shell with sudo command.
tee – The output of write (vim :w) command redirected using tee.
% – The % is nothing but current file name.
</code></pre>

<p>But what about Emacs, how do we do this in Emacs, we also got <a href="https://stackoverflow.com/questions/95631/open-a-file-with-su-sudo-inside-emacs" rel="nofollow">one</a>:</p>

<pre><code>C-x C-f /sudo::/path/to/file
</code></pre>

<p>It uses Tramp module to do the same thing.</p>

<p><a href="https://rex.writeas.com/tag:vim" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">vim</span></a> <a href="https://rex.writeas.com/tag:emacs" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">emacs</span></a></p>
]]></content:encoded>
      <guid>https://rex.writeas.com/write-with-sudo</guid>
      <pubDate>Sun, 12 Dec 2021 14:27:38 +0000</pubDate>
    </item>
  </channel>
</rss>