TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Five lines I put in a blank .vimrc

153 点作者 jiannengli超过 4 年前

27 条评论

ogre_codes超过 4 年前
I find it odd that you would use the short version of a command in a config file. Brevity is important when you are doing repetitive tasks. In a config file (or code), clarity is more important that brevity. I know you could argue that you know VI so well that you know these commands off the top of your head.. even so, it's particularly pointless to list them this way in a blog where you have to turn around and explain them anyhow.
评论 #25411120 未加载
评论 #25411090 未加载
评论 #25415063 未加载
评论 #25411195 未加载
lucb1e超过 4 年前
The swap file saved my work a number of times. If you never use recover and use Vim regularly, then go ahead and disable it; if you haven&#x27;t used it because you don&#x27;t know how to use it or you only rarely use Vim, then I&#x27;d encourage you to either try it first or leave it enabled (as it is by default) until it becomes a nuisance.<p>And like u&#x2F;strogonoff, I also disable line numbers, but that&#x27;s just personal preference of course. For vim newbies, relative lines might also be worth checking out: &quot;set relativenumber&quot;.<p>One thing that really annoys me is :Wq or :Q not being commands. Or typing only Q because you didn&#x27;t hit the : and accidentally entering ex mode. Or hitting F1 instead of escape. I can recommend:<p><pre><code> command Wq wq command WQ wq command W w command Q q nnoremap Q &lt;nop&gt; map &lt;F1&gt; &lt;Esc&gt; imap &lt;F1&gt; &lt;Esc&gt; </code></pre> Or for the non-newbie that has the &#x27;too many terminals&#x27; problem, &quot;set title&quot; will give your terminals more useful titles. There are a bunch more things, of course, but these are the lines in my vimrc that I think are useful to most people.
评论 #25411362 未加载
评论 #25412006 未加载
评论 #25411040 未加载
评论 #25411925 未加载
评论 #25414890 未加载
strogonoff超过 4 年前
Why not one line?<p><pre><code> set hls ic is nu noswf </code></pre> On a serious note, personally disabling line numbers is the first thing I do in a new editor. Reduces visual noise—status line usually shows current line number anyway, jumping to a line might take a second and I found I don’t need to know my line numbers more frequently than once per month or so.<p>What I do like to enable in an editor is visible whitespace characters (helps notice levels of indent, for example). In Vim that can be accomplished with:<p><pre><code> set list listchars+=space:• </code></pre> (Might take some tweaking to make whitespace appear subtly enough, depending on your color scheme.)
评论 #25410822 未加载
评论 #25410830 未加载
评论 #25411052 未加载
评论 #25411426 未加载
评论 #25410876 未加载
评论 #25410956 未加载
评论 #25410993 未加载
adrianmonk超过 4 年前
Another approach to the swap file thing:<p><pre><code> view foo # opens read-only, no swap file vi foo # opens read-write </code></pre> Another benefit of this habit is, if you know you&#x27;re not going to want to modify a file, you can protect yourself against errors like accidentally changing something and then absentmindedly saving the file.
评论 #25411449 未加载
lilyball超过 4 年前
Keeping the swapfile on is really helpful when I accidentally open the same file in two different vim editors. But I do recommend configuring vim to place swapfiles in a different location, so you’re not scattering them all over your disk.
评论 #25410815 未加载
thih9超过 4 年前
These seem a bit too opinionated to me, mostly because of &#x27;set noswapfile&#x27;.<p>For me vim-sensible [1] has a more useful set of defaults (although more than five lines). Also, the readme of that project lists benefits of using a universal set of defaults.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;tpope&#x2F;vim-sensible" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tpope&#x2F;vim-sensible</a>
toxik超过 4 年前
I&#x27;d prefer one line it and use the &quot;long&quot; names and add nocompatible<p><pre><code> set nocompatible hlsearch incsearch ignorecase number </code></pre> then sane tabs<p><pre><code> set et sts=4 sw=4</code></pre>
评论 #25410994 未加载
评论 #25411063 未加载
评论 #25410819 未加载
arendtio超过 4 年前
&gt; Unfortunately, Vim’s default configurations lack several important usability features compared to popular alternative text editors, such as VSCode.<p>I find it odd, to compare Vim with VSCode and pretend that those 5 lines close the gap (especially when 3 of those lines are primarily about search). My own .vimrc has 166 lines (custom snippets, key bindings, plugin configurations (e.g. powerline, tmux navigator) and comments) and I try not to use more plugins than necessary.<p>I say that as someone who loves Vim. But not just for its features, but also for those that are not present (by default) and make it as fast as it is.
bluenose69超过 4 年前
Line numbers can be quite handy when coding with somebody over a video connection. Instead of saying &quot;I think the problem is 8 or 9 lines up from the cursor&quot;, it&#x27;s just easier to say &quot;look at line 314&quot; or whatever. I seldom use j and k to go more than a line or two, preferring absolute or relative line jumps, and I find absolute jumps easier to do accurately, especially if I&#x27;m tired.
ogre_codes超过 4 年前
I guess it depends if you are doing systems admin or coding, but when I&#x27;m coding, I&#x27;ve gotten very dependent on Fuzzy Search like what Sublime Text introduced.<p>So for me, installing CtrP or FZF is pretty much mandatory (I&#x27;ve settled on FZF). I know this is about config options, and this is an extension, but for me, fuzzy search is pretty much essential for coding once you get to a moderate sized code-base.
leephillips超过 4 年前
It’s not enough. You should go all the way:<p><pre><code> set nobackup set nowritebackup set noundofile set noswapfile </code></pre> I explain why at <a href="https:&#x2F;&#x2F;lee-phillips.org&#x2F;badvim&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lee-phillips.org&#x2F;badvim&#x2F;</a><p>Also, it’s best to just have one instance of Vim running, in server mode, so you can send files to it from the command line.
评论 #25410963 未加载
评论 #25410977 未加载
评论 #25415327 未加载
russellbeattie超过 4 年前
I have a .vimrc I set up a decade or so ago. I can&#x27;t remember what&#x27;s in it, just that I have to comment out a few lines every time I copy it from a Mac to Linux or vice versa.<p>In retrospect, I probably should have just gotten used to whatever the default is, because using Vim without my .vimrc doesn&#x27;t actually feel like Vim to me.
jlgaddis超过 4 年前
&gt; <i>Also, as mentioned below, this is for temporary environments where you read more than you edit.</i><p>It might be more convenient to just do a one-time setup of something like &quot;bring your .bashrc, .vimrc, etc. with you when you ssh&quot; [0] (previously discussed on HN [1]).<p>Personally, I&#x27;ve got a shell script that I just scp over and execute to set up my dotfiles (in a git repo) if they aren&#x27;t already present on a host, but that may not be an option for some (although I guess I <i>could</i> use sshrc to do that too).<p>--<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;danrabinowitz&#x2F;sshrc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;danrabinowitz&#x2F;sshrc</a> (note: clone of the original repo, which now 404s).<p>[1]: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8343469" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8343469</a>
superasn超过 4 年前
Very useful thanks. I&#x27;ve already added it in my .vimrc. One more setting that I find really useful is this:<p><pre><code> map &lt;F5&gt; &lt;Esc&gt;:w&lt;CR&gt; :!&quot;%:p&quot;&lt;CR&gt; </code></pre> Especially since I&#x27;m used to running my code with F5 since Delphi
CalChris超过 4 年前
I&#x27;m not going to <i>set noswf</i>. However, I run into the problem the writer mentions all the time where I&#x27;m opening an already opened file. Is it possible to just switch to the already opened file?
评论 #25410821 未加载
评论 #25410953 未加载
gpvos超过 4 年前
Tastes differ; I would <i>never</i> set &#x27;ignorecase&#x27; as a default, and instead of &#x27;number&#x27;, which is only occasionally necessary and most of the time is visually disturbing, I&#x27;d set &#x27;ruler&#x27;, or a slightly more fancy &#x27;statusline&#x27;. The most important one, however, for me is &#x27;set guicursor+=a:blinkon0&#x27;.
评论 #25410894 未加载
评论 #25411373 未加载
BalinKing超过 4 年前
In Firefox on macOS, the font fallback to &quot;Apple Color Emoji&quot; is doing really weird things on my machine (like cutting off the top of the number &quot;5&quot;).<p>With that said, thanks for the tips—`set noswapfile` definitely fits my workflow more than not.
评论 #25411073 未加载
ulzeraj超过 4 年前
Kinda derailing the thread but might ask anyway, does anyone got recommendations on dot files synchronization through personal devices? I&#x27;m currently using a git+ss repo on a personal server.<p>I wonder if there are more convenient ways to do this.
评论 #25411565 未加载
评论 #25411280 未加载
评论 #25419112 未加载
评论 #25414813 未加载
评论 #25411554 未加载
_wldu超过 4 年前
Disabling swap files is smart especially if you edit files directly on a web server using vim. I&#x27;ve found index.php~ and .index.php.swp on a number of web servers over the years.
评论 #25416384 未加载
aftbit超过 4 年前
I&#x27;ve started writing<p><pre><code> set mouse=&quot;&quot; </code></pre> into all of my Debian server vimrc files so I can still use my middle-click paste buffer over ssh.
pletnes超过 4 年前
I have «relativenumber» but I’ve never touched swapfile. Otherwise I have the same 5. Funny - I often felt vim’s defaults are almost intentionally archaic.
phodge超过 4 年前
`set confirm` is another great option to turn on all the time. It will save you having to retype a command with the `!` added.
bonquesha99超过 4 年前
nmap ; :
评论 #25411242 未加载
评论 #25410878 未加载
评论 #25414193 未加载
aliceryhl超过 4 年前
Mine are:<p><pre><code> inoremap jk &lt;esc&gt; nnoremap &lt;space&gt; :</code></pre>
29athrowaway超过 4 年前
What is the kakoune equivalent of these options?
评论 #25426454 未加载
prussian超过 4 年前
if you&#x27;re a fan of incsearch, you may also be a fan of neovim&#x27;s inccommand=nosplit as well.
njharman超过 4 年前
Holy crap, first 4 lines are cancer! HATE hilight, incremental, very much want case sensitivity, and don’t need wasted space and attention with numbering every line. Current line (and column) in status bar is enough.<p>No swap file is good though.