Live data from Hacker News

Five lines I put in a blank .vimrc

swordandsignals.com

111–120 of 133 posts

Re: Five lines I put in a blank .vimrc

#111
post #109

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 expla…

It's not a big deal. You can just hit K on any you're not sure about to see the help. Might need to set keywordprg=:help.

> Might need to set keywordprg=:help.

    echo 'set keywordprg=:help' >> ~/.vimrc
:)

Re: Five lines I put in a blank .vimrc

#112

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 expla…

Yes, I definitely am much descriptive for the config file on my personal computer. The configs I'm recommending here is more for ephemeral machines that you are using just to look at files (such as sshing into a VM that was created to run integration tests). For those cases, being able to quickly type something into the .vimrc and improve your experience is nice.

I once had to connect to machines regularly where I did not have a home directory. This happened so often that I wrote a wrapper to log in:

It would log into the remote machine using Expect, then it would send a command to the remote end that tested whether a home directory already existed. If so, it spawned a new shell in it. Otherwise it created a "home directory" in /tmp, pulled a tarball from a server, and extracted it into the "home directory". Then it spawned a new shell there.

Depending on how often it happens, you could also have a separate command that does the initial setup, and then call that as required.

Re: Five lines I put in a blank .vimrc

#113

Earlier quoted context omitted.

Yes, I definitely am much descriptive for the config file on my personal computer. The configs I'm recommending here is more for ephemeral machines that you are using just to look at files (such as sshing into a VM that was created to run integration tests). For those cases, being able to quickly type something into the .vimrc and improve your experience is nice.

I once had to connect to machines regularly where I did not have a home directory. This happened so often that I wrote a wrapper to log in: It would log into the remote machine using Expect, then it would send a command to the remote end that tested whether a home directory already existed. If so, it spawned a new shell in it. Otherwise it created a "home directory" in /tmp, pulled a tarball from a server, and extrac…

That's cool. Do you have a write-up of this somewhere?

Re: Five lines I put in a blank .vimrc

#114
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…

inoremap jk inoremap kj are essential to me... press both at the same time and you exit insert mode regardless of which one gets pressed slightly faster and you never leave the home row and if you press it when you are not in insert mode it's basically a nop unless you are at the start or end of the file. even if you are you might move down or up a line accidentally but i've never had that happen personally.

Then you can't type words that have jk or kj in them, right? :) Depending on languages used it could be a blocker

Re: Five lines I put in a blank .vimrc

#115

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.

I don’t copy and paste, I just don’t see the need for line numbers. But then I also code with syntax highlighting off about half of the time.

Hah, I'm the exact opposite. Greatly enjoy very colored themes, but it feels like almost all themes are about 50% white text with only a handful of things colored.

Re: Five lines I put in a blank .vimrc

#116

It’s not enough. You should go all the way: set nobackup set nowritebackup set noundofile set noswapfile I explain why at https://lee-phillips.org/badvim/ 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.

Persistent undo is one of the best features in Vim. On any permanent working environment, I would definitely enable it.

My undo files are in ~/.cache/

Re: Five lines I put in a blank .vimrc

#117
post #2

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.

I actually went full on in the other direction and often have multiple vim instances working on the same file. It feels so much better than having to deal with swap file error messages. With the below it reloads the file when the window gets into focus. Super helpful when working in lots of terminal tabs. You just have to get into a habit of saving after every change as it conflicts otherwise. " check for and load fi…

Maybe could have it work on a cloned temp file, and then autosaving on losing focus. Opening the same real-file would lead to the same temp-file. Might be able to make manual :w save the temp to the real, but may be better to have it as a separate command.

Re: Five lines I put in a blank .vimrc

#118
> Also, as mentioned below, this is for temporary environments where you read more than you edit.

It might be more convenient to just do a one-time setup of something like "bring your .bashrc, .vimrc, etc. with you when you ssh" [0] (previously discussed on HN [1]).

Personally, I've got a shell script that I just scp over and execute to set up my dotfiles (in a git repo) if they aren't already present on a host, but that may not be an option for some (although I guess I could use sshrc to do that too).

--

[0]: https://github.com/danrabinowitz/sshrc (note: clone of the original repo, which now 404s).

[1]: https://news.ycombinator.com/item?id=8343469

Re: Five lines I put in a blank .vimrc

#119
post #60

Earlier quoted context omitted.

I bind those commands to "shift-j" and "shift-k" and heavily abuse them. It's not pretty, one could argue that the mouse is more efficient for such movements, but for me it's faster in practice than moving my hand to the mouse/trackpad, or than looking up a line number (either absolute or relative) and then typing it. And it has no mental burden.

I usually go with { and } for those to jump between paragraphs, as that is usually a sensible distance of movement. But your approach is also an interesting addition as it's more consistent.

I use them heavily. Also, check out ]] [[ and ]m (jump to end of function).

Re: Five lines I put in a blank .vimrc

#120
post #80

Disabling swap files is smart especially if you edit files directly on a web server using vim. I've found index.php~ and .index.php.swp on a number of web servers over the years.

You can set a few variables to change where these files go:

• 'directory' controls where swap files go, toggled by 'swapfile' (default on), filenames like […].swp; ~/.cache/vim/swap// is a good choice.

• 'undodir' controls where undo files go, toggled by 'undofile' (default off), filenames […].un~; ~/.cache/vim/undo// is a good choice.

• 'backupdir' controls where backup files go, toggled by 'backup' (default off), filename […]~; ~/.cache/vim/backup// is an interesting choice.

Arch Linux actually ships a runtime file that sets these paths, creating the directories if they don’t exist: https://github.com/archlinux/svntogit-packages/blob/packages....

(Note that the double trailing slashes are significant and necessary if you’re using a central location for these files. Refer to the help for explanation.)

Post reply on HN