Live data from Hacker News

Five lines I put in a blank .vimrc

swordandsignals.com

71–80 of 133 posts

Re: Five lines I put in a blank .vimrc

#71

Another approach to the swap file thing: view foo # opens read-only, no swap file vi foo # opens read-write Another benefit of this habit is, if you know you'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.

Nice, that'll come handy

Re: Five lines I put in a blank .vimrc

#73
post #45
post #35

Earlier quoted context omitted.

> Or typing only Q because you didn't hit the : and accidentally entering ex mode. I'm not certain this is different (because I don't use either deliberately) but I'm forever hitting q (not even trying to quit) and entering some kind of macro recording mode. I think the only reason I haven't yet disabled it like you suggest (after doing it for years now) is that... Well 'some kind of macro recording' does sound like…

Macros are really nice, you can automate transforming several lines of text with them. The Vim plugin in Intellij supports them. Worth learning IMHO.

Indeed, I would not recommend disabling q unless you know what it does and tried it a few times.

For a quick demo, try it on this file:

    hello world!
    here's wolves
    what's up with the hackers?
Go to the first line and do:

    1. qq starts a macro named 'q'
    2. $vbgUj select last word on line, uppercase it, go down one line
    3. q to end macro recording
    4. @q run the macro
    4b. @@ repeats the last macro
    4c. 100@q runs the macro 100 times
When you want to do multi-line edits and the columns are not aligned (so block mode, Ctrl+V, doesn't work), this works wonders. You just record whatever you would do on every line plus whatever motions you use to go to the next occurrence, using things like "f|" (find the next pipe symbol) or "/examplen" (find the next instance of "example"), and then run the macro however many times. If you specify a number of times greater than the file is large, it will automatically stop at end of file, and you can also cancel if it takes too long (Ctrl+C) and undo what it did so far (u).

Alternatively, sed -i s/a/b/ my.txt is much much faster than macros, but macros can be more complex and are often easier to record (since you're just showing the computer what to do in a human way) than trying to regex the line.

I tried recording it for the lazy but asciinema is having issues (server error when uploading).

Re: Five lines I put in a blank .vimrc

#74
post #61

Earlier quoted context omitted.

Line numbers are great, until you try to cut and paste. But then again, VI/M wasn't designed for GUIs.

If your vim is compiled with the correct flag for GUI operations (I forget which), you can yank/delete text into the * or + registers to make it available to the system clipboards. This won't bring the line numbers, and lets you avoid using the mouse.

I think it's just called +clipboard. And with the setting "set clipboard=unnamedplus" Vim will use the system clipboard for yank, delete and paste by default.

Re: Five lines I put in a blank .vimrc

#75
> Unfortunately, Vim’s default configurations lack several important usability features compared to popular alternative text editors, such as VSCode.

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.

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.

Re: Five lines I put in a blank .vimrc

#76
post #21

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't used it because you don't know how to use it or you only rarely use Vim, then I'd encourage you to either try it first or leave it enabled (as it is by default) until it becomes a nuisance. And like u/strogonoff, I also disable line numbers, but that's just personal preference of…

I hit :w so reflexively and regularly in working files that swap files only occasionally saves my butt: when I've done substantial work in a new buffer that I haven't figured out how to name yet and there's a crash. This happens just often enough that I have to regard it as useful, but it's also less common than crashes that leave me with swaps to contend with across a dozen files that really were pretty much fine. T…

> I don't think the problem is actually swap files themselves, though, but the user experience with them.

Agreed, the UX is 99% the reason of me hating swap files. More often than not I choose recover, only to discover the diff is literally null. Come on, you could not check for that before interrupting? And then in any case you have double the annoyance with that recovered buffer as the old swap remains and you have to delete it or you get the warning again on the next open.

It’s kind of like changing branches with git and then back again, vim notices the time stamp of an opened file changed vs the last buffer save, lets you change the file but complains on :w that the file “changed” outside, yet is unable to a) show you a diff of current buffer vs current file, nor b) realised that the filesystem state vs buffer state at last save (which vim fully knows about) produces a null diff, so the buffer changes are safe to write.

Re: Five lines I put in a blank .vimrc

#78
post #47

Kinda derailing the thread but might ask anyway, does anyone got recommendations on dot files synchronization through personal devices? I'm currently using a git+ss repo on a personal server. I wonder if there are more convenient ways to do this.

I have a shell script that either symlinks dot files from my git repo or writes them. Then I use git normally.

Re: Five lines I put in a blank .vimrc

#79
post #47

Kinda derailing the thread but might ask anyway, does anyone got recommendations on dot files synchronization through personal devices? I'm currently using a git+ss repo on a personal server. I wonder if there are more convenient ways to do this.

I have tried a custom linking script, Ansible, and stow. The best I have found is to just use a bare git repo based off of: https://www.atlassian.com/git/tutorials/dotfiles

The idea is to make an alias that runs git so that it treats your home directory as a git repository and you can directly commit them.

I would recommend bypassing that article's `config config --local status.showUntrackedFiles no` setting and setting a `~/.gitignore`. This way, git will never tinker with your home directory if you accidentally run the wrong command.

So the complete list of setup commands is:

    # Only needs to be done the first time
    cat >~/.gitignore
One caveat is adding files in subdirectories (`~/. config/...`), but just requires changes in your gitignore
Post reply on HN