Tech Tip: Some Useful Vim Options
Vim is one the more popular choices of text editors for Linux. For vim, there are a few non-default options that may be useful whether editing config files or writing scripts in your favorite language.
Global options for vim are enabled in the vimrc file, which may be located in /etc or /etc/vim, depending on the distribution you are using. Note that the vimrc file uses a double quotation mark (") to start a comment.
You may find some or all of the following options useful, simply copy and paste them into your vimrc file:
syntax on " Turn on syntax highlighting
" (makes code and config files more readable)
set background=dark " If using a dark background, instead of the
" usual white background in Terminal
" (makes darker colors brighter)
set incsearch " Used for incremental searching
" (useful when searching large text files)
set hlsearch " Turns on highlighting for matched search patterns
" (use :nohlsearch inside vim to turn off highlights
" after a search)
set tabstop=4 " Sets the tab size to 4
" (tabs are usually 8 spaces)
set expandtab " Tab key inserts spaces instead of tabs
set shiftwidth=4 " Sets spaces used for (auto)indent
set shiftround " Indent to nearest tabstop
set autoindent " Carries over previous indent to the next line
Feel free to leave a comment with your own useful vim options and macros.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Dynamic DNS—an Object Lesson in Problem Solving
- Designing Electronics with Linux
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Web & UI Developer (JavaScript & j Query)
- Senior Perl Developer
- Technical Support Rep
- Symbolic Math with Python
- UX Designer
- Network Monitoring with Ethereal
- Not only you I too assumed
13 min 29 sec ago - another very interesting
2 hours 6 min ago - Reply to comment | Linux Journal
3 hours 59 min ago - Reply to comment | Linux Journal
10 hours 54 min ago - Reply to comment | Linux Journal
11 hours 10 min ago - Favorite (and easily brute-forced) pw's
13 hours 1 min ago - Have you tried Boxen? It's a
18 hours 53 min ago - seo services in india
23 hours 24 min ago - For KDE install kio-mtp
23 hours 25 min ago - Evernote is much more...
1 day 1 hour ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Quick :nohlsearch
Quick way to turn off the highlights when you're done with them, just search for something you know is not there.
/a;lsdkj [enter]It LIKELY won't find anything and turns off highlights.
Much quicker than :nohlsearch and gets the job done.
write as root
This mapping allows writing a file that requires root permissions.
If you get into a file as a non-root user and then decide to make edits, it
can be annoying to have to save to a temporary file and leave vi to use sudo.
Going beyond the normal ":w" and ":w!" commands, ":w!!" will write as root.
(It will prompt for a password if you haven't used sudo recently.)
cmap w!! set bt=nowrite :%!sudo tee "%"
Do NOT change tabstop. Leave
Do NOT change tabstop. Leave it at 8. Otherwise a bear
to share files with someone who uses a different value.
Use shiftwidth to change your indenting, but not tabstop.
Daniel
@electronjunkie (Python and tabs)
Python is OK with *either* tabs *or* spaces for indents, but *not* a *mixture*. You can use any number of them to indent, as you see fit.
HOWEVER: NEVER MIX TABS AND SPACES.
This is because python counts indents by character, not by print width (tabs have no "official" width associated with them.
Bad Example: (\t=tab,_=space)
num={0:"zero",1:"one",2:"two",3:"three",4:"four",5:"five",
_____6:"six",7:"seven",8:"eight",9:"nine"}
for n in range(10:
\tprint n
________print num[n]
# This will fail with an indentation error, but you probably won't see it in vim. In these cases, cat -A is your friend ;-)
This is why I hate Python
Having whitespace characters define blocks is bad, m'kay?
The very fact that a tab looks like one or more spaces, but isn't treated as equivalent (other than in quoted strings) by the language interpreter/compiler, is craziness.
Are braces really that bad?
Complement to "set hlsearch "
A hint I read in a message (bad me, didn't kept the reference), I only kept the comment and the hint itself in my '~/.vimrc' :
"
" This is great !!
" So when I'm done, searching, I just hit CR and all highlighting turns
" off. I can still use n/N to resume searching and it will highlight
" again!
" nnoremap ^M :noh^M
nnoremap :noh
Other ViM Files
ViM has other places where its configuration files can be placed.
~/.vimrc-- your personal ViM configuration file.~/.gvimrc-- your personal configuration file that only applies to GUI ViMUsing the config hierarchy.
There is an hierarchy of startup file search. The GUI (gvim) search for '~/.gvimrc', if not fount it looks for a '~/.vimrc' and if not found I think it will look for a '~/.exrc' like the classic 'vi'. The Vim will look for a '~/.vimrc' and if not found will look for a '~/.exrc'.
I use to work in a complex environment mixing Linux and Unices and some of them does not have Vim installed. Some have Vim but no GVim. My $HOME is shared using NFS, so in order to make as similar as possible my options I have a '~/.gvimrc' with few options, but the first macro is just :
:so ~/.vimrc
This way I can put the common configuration in '~/.vimrc' and only those restricted to GVim in the '~/.gvimrc'.
Likewise, my '~/.vimrc' starts with a :
:source ~/.exrc
And I can have a number of common macros shared by classical VI, the Vim and GVim.
This hierachy makes all environment very similar for me.
HTH
filetype?
I'd like to know how to enable some options based on file type. For example, I'd like to have a shiftwidth of 8 for C files and of 4 for cpp/python files.
By File Type
Add something like this to you ~/.vimrc:
Then put this in ~/.vim/c.vim:
And this in ~/.vim/py.vim:
That'll cause vim to source the specified file when the corresponding file type is read (or when a new file of the corresponding type is created).
Mitch Frazier is an Associate Editor for Linux Journal.
within vim....
Once you're inside Vim a lot of these can be turned on or off:
:set nonu
Turn off line numbering, or
:set nu
Turn numbers on
:set noai
Turn off auto-indent
:set ai
or turn it on.
I would bet most of the above can be done the same way.
set number
set number
Line numbers in vim. :)
set mouse=a rarely use it,
set mouse=a
rarely use it, but on occasion I accidentally try to scroll using the scroll wheel and this makes that work.
Do NOT change tabstop. Leave
Do NOT change tabstop. Leave it at 8. Otherwise a bear
to share files with someone who uses a different value.
Use shiftwidth to change your indenting, but not tabstop.
expand tab
Be careful w/ expand tab. It will screw up a Makefile and probably python too.
just add this to the rc
just add this to the rc file:
nice one
really nice collection and information.
set expandtab set
set expandtab
set softtabstop=4
set ai
"Map tabs like firefox
:nmap :tabprevious
:nmap :tabnext
:map :tabprevious
:map :tabnext
:imap :tabpreviousi
:imap :tabnexti
:nmap :tabnew
:imap :tabnew