Vim for C Programmers
If there is one feature in Vim for which it wins hands-down compared to any other editor or IDE, it is full-featured syntax highlighting. The colors available in Vim make it a veritable delight to work with source code. It not only makes your life colorful, it also makes it easy to spot errors ahead of compilation. Common errors such as a mismatched ),} or ] in the code are easy to see. It also reminds you if you have left a string hanging without the closing " or '. It tells you the comment doesn't end with */, or that you are nesting comments. Syntax highlighting is smart when it comes to C syntax.
Typically, you wouldn't have to do anything to enable Vim's syntax highlighting; :sy on does the job in case your distribution doesn't enable it by default. As with other commands, you can add this to your ~/.vimrc file.
If colors still don't show up, something is wrong with your terminal. Fix it first. :se filetype on is another thing you can try in addition to :sy enable.
Let us assume that you have colors displayed correctly. Say you don't like a certain color, or because blue is not visible in dark backgrounds, you can't read C comments. To solve the second problem, a simple :se background=dark does the job. If you want to disable syntax highlighting for C comments, type :highlight clear comment.
To change colors, first use the :syntax command to display all the syntax items for the given buffer. Then, identify the syntax group you want to change. If you want strings displayed in a bright white color, which is easy to read against a black background, simply enter:
:highlight String ctermfg=white
or, for gvim users, type:
:highlight String guifg=white
You also can change the syntax color of any group. Typical syntax groups are Statement, Label, Conditional, Repeat, Todo and Special. You can change the attributes of highlighting as well, such as underline and bold. For instance, if you want to display NOTE, FIXME, TODO and XXX with underlining, you can use:
:highlight Todo cterm=underline
or you can both add bold and change the color:
:highlight Repeat ctermfg=yellow cterm=bold
You can create your own set of highlight commands and save it in your ~/.vimrc file so that every time you edit your source code, your favorite colors are displayed.
In addition, Vim has a feature for variable name completion. While typing, simply press Ctrl-N or Ctrl-P in insert mode. Remember, this works only in insert mode. All other commands mentioned above work in command mode. You can cycle through possible completions by pressing Ctrl-N again.
This helps us avoid errors while typing, because structure members and function names often can be misspelled. This works best when Vim can use tags, so make sure a ctags file is in place.
Vim understands C well enough to be able to indent code automatically. The default indentation style uses tabs, which may not be appropriate for some people. In order to remove tabs completely from the source, enter:
:set expandtab :retab
which converts all tabs into spaces in such a way that the indentation is preserved. While typing C text, Vim automatically indents for you. This helps you figure out where you have your matching brace. You can match braces, ), ] and } with the % command in command mode. Simply take the cursor to a brace and press %, which takes you to the corresponding closing or opening brace. This works for comments as well as for #if, #ifdef and #endif.
After finishing typing the program, if you want to indent the whole file at one go, type gg=G in command mode. You then can remove tabs if you want by the above-mentioned method. gq is the command sequence for indenting comments. You can select a region and indent it too with the = operator.
If Vim's default tab indentation is painful to use, you can disable it by setting :se nocindent. Other indentation options are available. You can indent code between two braces and between certain line numbers. You can learn more by typing :help indent.txt.
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
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Linux Systems Administrator
- Validate an E-Mail Address with PHP, the Right Way
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Technical Support Rep
- Senior Perl Developer
- UX Designer
- Introduction to MapReduce with Hadoop on Linux
- Weechat, Irssi's Little Brother
- user namespaces
2 hours 10 min ago - yea
2 hours 36 min ago - One advantage with VMs
5 hours 5 min ago - about info
5 hours 38 min ago - info
5 hours 39 min ago - info
5 hours 40 min ago - info
5 hours 42 min ago - info
5 hours 43 min ago - abut info
5 hours 45 min ago - info
5 hours 46 min ago
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
Please Help
Hello sirs,
I have Vim and Code Blocks and am very much new to Vim and would like to know how does one build and run a script? (Yes...I am a newbie).
Nice article, concise and
Nice article, concise and useful.
Seems like the author was trying to educate newcomers without trying to impress readers with unix-speak. I hope I can find more of his articles.
(windows programmer).
Try c.vimYou can get this
Try c.vim
You can get this from vim.org
An amazing plugin for working with C files in gvim.
Editing between marks
Excellent article, here's another little tip for marks and replacing.
Mark two points in the file with say ma and mb, you can then replace between the marks with
:'a,'bs/foo/bar/
or a single mark and then you can do current position to the mark with
:.,'as/foo/bar/
I find this incredibly useful, hopefully you will to.
Adding a small note
The article was quite marvellous and useful.
I just wanted to add, for those who are new to vim, that most of the settings like "se nu" can be made to persist across logins by just putting that setting in .vimrc file in the user's home directory.