At the very least I always uncomment "syntax on" in /etc/vim/vimrc
10 Answers
First, if you have more than a couple machines you work with, consider putting your ~/.vim/, ~/.vimrc and other useful config files (screen, your shell, etc.) in a revision control system. I prefer using darcs - it's cheap on Debian systems (no need to install Haskell compiler, just install the package directly), distributed, and has great interactive modes. If you know/like git, you can also stick with that.
My current config files are available in my darcs repository, http://repo.harnir.net/. Some specific examples from my ~/.vimrc follow. Sorry, no links for scripts, etc. because I'm a new user, but all those you can find on http://vim.org/.
Essential ViM scripts for sysadmins
a backup script is a must, when you edit remote files. I use cbackup.vim script, which keeps last 10 copies of each edited file in a central directory and automatically removes old ones - just put in your
~/.vim/plugins/directory and forget about it :-)TaskList lets you quickly search for
FIXME,XXXandTODOtags in current file, display them and go to the tag with just one keypress. If you use these tags, consider installing this onedbext is essential for all DBA, also very useful for programmers working with databases. Let's you run queries, check structure of the databases and whatnot. It is essentially a front end for tools like
mysql,sqlite3,sqlplusand others. If you work with databases, it's a must!
Syntax files
I haven't seen many useful syntax in the wild, most files sysadmins work with are configs in /etc and they are usually pretty well highlighted. In my ~/.vim/syntax/ I currently have syntax for CSS colors, which is awesome (also good for web developers), but the rest isn't very well written, I'll perhaps update them in the spare time. Additional syntax files worth having are for: dhcpd.conf, /etc/network/interfaces, nginx configuration files, and SpamAssassin's local.cf.
Useful tip with syntax: if a configuration file isn't recognized (has a weird name, like /etc/apache2/sites-enabled/some.domain.com, you can either append correct extension to it's name (in this case .conf) or add a ViM modeline at the end of it:
# vim:filetype=apache
ViM configuration options
Most of the configuraion options is very popular, like set nocompatible ruler etc. Very good options to have are:
set gdefault: inverses thegmode ins///g- with that option/gwill be used by default, so you don't need to add it every time - just add it to turn it offset incsearch ignorecase smartcase hlsearch: essential for searching through files - incremental, shows matches in real time, search ignores case unless you use upper case lettersset pastetoggle=<F6>: or other key which you prefer, toggles betweenpasteandnopastemodes, a must if you copy-paste something from a web pages like ServerFault :-)set noerrorbells visualbell t_vb=: get rid of the annoying bell or visual bell every time you do something ;)
Functions, keyboard mappings
paste your user name and current date into a file, useful if you work in a team and add comments in files about who changed something when. Just write
xxsigand press space, it will be changed to something likeharnir 20090531. For this to work correctly with root (ie. write your user name instead ofroot), you need to log in usingsudo.iabbrev xxsig <Esc>:r ![ -n "$SUDO_USER" ] && echo "$SUDO_USER `date '+\%Y\%m\%d'`" \|\| echo "$USER `date '+\%Y\%m\%d'`"<CR>I<BS><Esc>A
Insert comment "lines", like
# -- Some title -------------------{{{1, length 78 characters - press\com#in normal mode and there it is. You will be automatically in Replace mode so you can add the title:nmap \com# O# <Esc>72A-<Esc>3A{<Esc>A1<Esc><Home>4<Right>R<Space>
You can easily modify it for other comment systems (", //, etc.), or just check my config file.
Ending touch
If you have your configuration files in RCS system, you might want to sometimes include configuration options specific to a certain machine. For that, it's good to have ~/.vimrc.local file, included automatically at the end of the configuration (if it's present, of course).
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
- 554
Not really sure what part of this is specifically sysadmin related, but my essentials are:
syntax on
set background=dark
set shiftwidth=2
set tabstop=2
if has("autocmd")
filetype plugin indent on
endif
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set incsearch " Incremental search
I also always ensure the machine has access to the nginx syntax highlighting file.
- 7,607
Our CTO has a pretty feature-filled Vim configuration on GitHub.
Highlights:
- Syntax highlighting, 2 space tabstop, expanded tabs.
- NERDtree, a file-tree view similar to TextMate's project drawer.
- FuzzyFileFinder, plugin to do TextMate's cmd-T functionality.
- Lots of color themes with a nice one (twilight) default.
I find it great for Ruby coding, as our system administration tools are written in Ruby.
- 7,665
If you are usually working at a user, than this make it possible to "pipe" a file to sudo so it can be saved.
cmap w!! %!sudo tee > /dev/null %
use the command:
:w!!
to envoke sudo and save the file.
- 696
Shameless plug. This is not really a .vimrc change but rather a VIM plugin. I use RCSVers on every installed version of VIM. Basically it uses the RCS command to save off a version of any file you edit. You don't know how many times I've screwed up a config file only to have RCSVers save me by showing me the changes I've made.
- 153
Don't use .vimrc to avoid learning VIM
Since I know that a lot of VIM new comers will read this, the best suggestion I have is: "Do not get lazy and put map entries in your .vimrc" Learning non-standard ways of doing things in VIM will make you feel like a total gimp when you are without your vimrc. The learning curve for vi is steep, but you are not doing yourself any favors by choosing not to learn.
- 4,599
At least a portion of my answer is the same as my programming .vimrc:
set hidden
map <TAB> :e#<CR>
map <F7> :set paste!<CR>
map <F8> :set hlsearch!<CR>
map <F9> :!co -l %<CR>:e<CR>
map <F10> :!rcsdiff %<CR>
map <F11> :!ci -u %<CR>:e<CR>
If at least some files that you're editing aren't in RCS, they should be! :)
- 40,079
Disabling all the "smart" indentation modes. Great for programming, hell for config file.
I often end up using strace to track down odd issues. As a result, trying to syntax highlight some of the lines can get ridiculous with a large string string. This being the case, I use set synmaxcol=2048 to limit the syntax highlighting to 2048 columns.
I'm also quite a fan of the taglist plugin which uses exuberant tags. So far I've been able to push around the compiled ctags binary around and haven't come across any library issues. This quickly allows me to navigate among any of the code I work with. Those generally being Perl, Python, or C.
- 1