The Archives
-
05.15.12ASCII codes in VimToday, a work mate asked if anyone had an ASCII code table at hand. He was editing a file in Vim and wanted to know the ASCII code for a certain character. Here is the answer: While having the cursor on the character, type: <ESC>:ascii<ENTER> Enjoy!
-
03.06.12Colored diffAs a programmer I am used to dealing with diff files. If you do not know what a diff file is, here you can find a nice description. They are simply text files so they can be viewed with less, more, cat and other common utilities. The main problem is that those utilities do not recognize these files' special syntax. cdiff (/usr/ports/textproc/cdiff) is a small utility that shows diff files in a colored fashion. It can be used this way: $ cdiff file.diff Of course, Vim can be useful here too ;) svn diff | vim -R - Enjoy!
-
01.09.12Greping from inside VimHi there, First things first: Happy New Year! :) One task I usually perform when I am writing code is grepping the code for a certain string. In order to do that, I used to exit Vim (either with :q or suspending the process), grep the files and then go back to my Vim session. This approximation has one main drawback: I usually don't remember all the matches reported by grep. Vim provides a mechanism for invoking grep from a Vim session. The command is: :grep string files This way, one can invoke his local grep command and the results will be integrated into the ...
-
02.04.11Easy svn blame vim mappingThe other day, this colleague of mine asked me how he could use svn blame on the same file he was editing without leaving his vim session. This is a mapping I wrote for that purpose. :map <F3> :sp %.tmp_svnblame \| :r! svn blame $(basename % .tmp_svnblame)<CR> Enjoy!
-
10.23.10Vim. MacrosYou have probably seen something like this in other editors. Macros (or "complex repetitions" as Vim's help puts it) is a way to repeat complex commands sequences. In order to get the most out of this feature, you need to master movement and insertion commands. The work cycle is the following: start recording, execute commands, stop recording. Then, you are ready to execute the whole sequence of commands you have recorded. Let us see this in more detail. To start recording, we use the "q" command followed by a register name in which the sequence of commands will be stored. qa At that ...
-
09.04.10Vim. Key mappingMaps are a way to create an association between a set of key strokes and a set of actions. They are really powerful. However, in this post, I will not explain them in the deepest detail. If you need further information, you will need a good Vim manual. As it happens with abbreviations, maps can be used regardless of the mode you are in Vim or they can be restricted to a certain operation mode. They work the same way in every mode. Type :help :map to know which map commands work in which mode. First off, :map ... ... <Esc>OM <CR> <Esc>Ol ...
-
01.22.10Vim for programmers (III)Welcome to the last "Vim for programmers" issue. Ironically, in this issue I will show you some nice characteristics despite they are not specific of programming. However they make much more sense when they are applied to programming. Getting C help This first feature is oriented directly to C programming. In most UNIX systems, there is a collection of system manual pages available with the command "man". Although I will not explain man in detail (you can read more here (or type man man) it is worth saying it shows information about the command, system call, file, etc passed as parameter. ...
-
01.07.10Vim for programmers (II)In the first part of this series, we visited some Vim features that help us in programming. In this second issue, I will show you some other important things you should know to really appreciate the power of Vim. Completion Completion is not a programming specific feature in Vim, however it is in programming where I find it to be more useful. There are several completion options, but I will explain the ones I find more interesting. Completion is a sub mode of insert mode. This means the commands are applied while being in insert mode. Line completion: Ctrl-x ...
-
11.01.09Vim. Editing multiple filesIn previous issues, we have edited one file at a time. We did this because there were other points of interest at that time. However, Vim can handle more than one file at a time using several different techniques including buffers, viewports and tabs last one, since Vim 7. In this issue we take a look at these handy mechanisms that will speed up your work. Buffers We can think of a buffer as a place inside Vim where a file is loaded. In the following example, I will use a couple of files: $ cat file1 file2 This is file 1 This is ...
-
10.03.09Vim. Copy & PasteCopy & Paste are two of the most important operations when writing a text. It is easy to know why: you save a lot of time. Vim handles copy & paste powerfully and gracefully. In Vim you can yank (copy), cut and paste text objects. There are two basic ways for selecting text: either using the normal vim commands or going into visual mode. Let us see all of this with some examples: This is a sample text (Bold letters indicate the cursor position as in the previous issues.) Now type: yw followed by ESC o As you can expect, you have just yanked a word ...