Save vim settings across launches?

14

4

My professor assigned an ssh account to every student in my programming class and mandated that we use VIM for text editing. I discovered :set nu and :set auto indent via Google. I noticed that those two settings reset after every launch. Is there a way to make them persist on my ssh account? What about on VIM on my local machine?

Moshe

Posted 2012-02-01T12:34:36.097

Reputation: 5 474

@BobbyMarinoff haha yup. This was one of my early CS classes. The professor is (still) the only one in the department who teaches this way. – Moshe – 2016-06-20T13:48:31.983

3"mandated that you use Vim" ?! – Rook – 2012-02-01T12:50:02.257

Yup. That's the class text editor. – Moshe – 2012-02-01T14:02:25.903

1On either your ssh account or your local machine, execute vimtutor. That will help you learn how to use Vim. When you're done with that, execute :help within Vim to see an overview of how to use the help system and some more introductory reading. – garyjohn – 2012-02-01T15:49:32.283

Answers

12

Put them in your vimrc (see :help vimrc). You can then sync that file between machines.

Another option is to have vimrc set up on the local machine, and use e.g. bcvi to transfer files transparently from remote to local and back again.

Cat Plus Plus

Posted 2012-02-01T12:34:36.097

Reputation: 245

7

When you are in Vim, type :echo $VIM ... that should give you the location where your _vimrc (or .vimrc) should go. Edit a file under that name, put those two lines inside

   set nocompatible
   set number
   set autoindent

and save it.

Yell if you have any problems with this.

Rook

Posted 2012-02-01T12:34:36.097

Reputation: 21 622

According to :help vimrc, $VIM is possibly Mac thing. Just sayin'. – marflar – 2014-06-27T09:00:54.177

6No, $VIM is not where your _vimrc or .vimrc should go. Those files should go in $HOME. – garyjohn – 2012-02-01T15:46:41.177

@garyjohn - Says who? Putting them in $HOME on Windows creates two possible problems; one - HOME creates a hard to make portable installation, and two, it may already be taken by emacs :/ – Rook – 2012-02-01T17:55:57.777

2@Idigas: Because $VIM is accessible by all users. It may be OK on a personal computer used by only one person, but it is not OK on a multi-user Unix system, as the poster's ssh account presumably is. I don't understand how using $HOME makes it less portable, unless you have Vim installed on a thumb drive, but that wasn't being discussed. Emacs's use of $HOME or anything else should not have anything to do with where one puts ones _vimrc or .vimrc. – garyjohn – 2012-02-01T18:57:53.650

2

There is also the modeline where you can configure vim file-wise and are not dependent on any local vim configuration.

  • One can customise the behaviour of vim for specific files using modelines.
  • Modelines are included at the beginning/end of the file and invoke "setlocal" on vim variables.
  • This is useful for setting options like the behaviour of tabs, the file mode , etc.

jofel

Posted 2012-02-01T12:34:36.097

Reputation: 271

1

If you are on a Mac you might use a Vim Options application:

  1. Search for "nu", set "On".
  2. Search for "autoindent", set "On".
  3. Save the file as ".vimrc" in your home directory.

After that it's possible to transfer the vim config file to a remote SSH machine using "scp" command like:

scp ~/.vimrc moshe@professor.com

battlmonstr

Posted 2012-02-01T12:34:36.097

Reputation: 111