Ah the joys of classic Unix text editing! Life would not be complete without the vi editor (or vim on most Linux systems). Whether you love it or hate it, there always seems to be a time when there is no other available editor so you must know how to use vi!
Here are some of my favorite vim settings. Put these in your ~/.vimrc file if you want to have them set every time you run vim.
set expandtab set ignorecase set shiftwidth=4 set tabstop=4 set ruler set autoindent
NOTE: autoindent will *break* your copy and paste (yank and put in vi-speak) operations – when you paste or put, the indentation will not match your original selection. To work around this, *turn off autoindent* with :set noautoindent, then paste/put, then turn it back on with :set autoindent.
Another one that I find useful if syntax highlighting makes things impossible to read, during a running vim session use :set background=dark, or :set background=light. When vim doesn’t properly guess your terminal background color, it can really choose a bad color scheme. A related hint – search results are highlighted, to turn off the highlighting until next search use :noh to highlight the last search result again, use /<ENTER> (slash followed by enter key).
Everyone has their favorite vim settings. These ones are especially helpful for Python programming where whitespace is significant. Other useful commands – :set list, :set nolist, :set number, :set nonumber (view whitespace and show line numbers respectively).
NOTE – for “:set list” to show dos file end-of-line characters as both carriage returns (^M) and new-lines (listed as $), start vim in “binary mode” with vim -b. This forces vim to ignore text file type detection (dos, unix, etc).
Happy vi editing! 🙂