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, XXX and TODO tags in current file, display them and go to the tag with just one keypress. If you use these tags, consider installing this one
dbext 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, sqlplus and 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 the g mode in s///g - with that option /g will be used by default, so you don't need to add it every time - just add it to turn it off
set incsearch ignorecase smartcase hlsearch: essential for searching through files - incremental, shows matches in real time, search ignores case unless you use upper case letters
set pastetoggle=<F6>: or other key which you prefer, toggles between paste and nopaste modes, 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 xxsig and press space, it will be changed to something like harnir 20090531. For this to work correctly with root (ie. write your user name instead of root), you need to log in using sudo.
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:
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
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
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.
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.
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.
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 usingdarcs
- 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/likegit
, 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 onhttp://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
,XXX
andTODO
tags 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
,sqlplus
and 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 configuration options
Most of the configuraion options is very popular, like
set nocompatible ruler
etc. Very good options to have are:set gdefault
: inverses theg
mode ins///g
- with that option/g
will 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 betweenpaste
andnopaste
modes, 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
xxsig
and 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
.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: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).Not really sure what part of this is specifically sysadmin related, but my essentials are:
I also always ensure the machine has access to the nginx syntax highlighting file.
If you are usually working at a user, than this make it possible to "pipe" a file to sudo so it can be saved.
use the command:
to envoke sudo and save the file.
Our CTO has a pretty feature-filled Vim configuration on GitHub.
Highlights:
I find it great for Ruby coding, as our system administration tools are written in Ruby.
You can also look at this SO question: What's in your vimrc?
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.
http://www.vim.org/scripts/script.php?script_id=563
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.
At least a portion of my answer is the same as my programming .vimrc:
If at least some files that you're editing aren't in RCS, they should be! :)
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.