The Archives

  • 04.Feb.15
    Editing Binary Files shell | rafacas | (0)
    In a previous post we learnt how to back up the MBR of a hard disk in a file called mbr.img. That file has the first 512 bytes (the first sector) of the hard disk. One way to see the content of a binary file is dumping it to hexadecimal. In Linux the xxd command makes a hex dump: $ xxd mbr.img 0000000: eb63 9010 8ed0 bc00 b0b8 0000 8ed8 8ec0 .c.............. 0000010: fbbe 007c bf00 06b9 0002 f3a4 ea21 0600 ...|.........!.. 0000020: 00be be07 3804 750b 83c6 1081 fefe 0775 ....8.u........u 0000030: f3eb 16b4 02b0 01bb 007c b280 8a74 018b .........|...t.. 0000040: 4c02 ...
  • 12.Mar.13
    Spell checking shell | fernape | (0)
    aspell is a command-line spell checker. It is a replacement for the older ispell. It can be used to manage dictionaries, to check a complete file, or words typed in your terminal, among other uses. We can invoke aspell this way: $ aspell -a --lang=en @(#) International Ispell Version 3.1.20 (but really Aspell 0.60.3) This leaves us with a prompt in which we can type a word. For instance, if we type: @(#) International Ispell Version 3.1.20 (but really Aspell 0.60.3) hello * The asterisk indicates that aspell found the word in the dictionary. On the contrary, if we type: @(#) International Ispell Version 3.1.20 (but really Aspell 0.60.3) rescoe & ...
  • 25.Oct.12
    utf-8 blues in snow leopard with mutt and vim shell | pfortuny | (0)
    Yes, it looks like a true spam page. But it is the only way to describe my problem. I was trying to set up mutt (yes, I am a bit fed up with Mail.app and its inability to be controlled with the keyboard alone in any sensible way). Terminal.app seems to work OK with utf-8. However, the included vim does not. Any time you type an accented char and delete it, the text gets mangled (you know, typical off-by-one cursor position). The solution for vim is incredibly stupid: open up vim and write :set encoding=utf-8 (or do that at any ...
  • 23.Jul.12
    gdb & nice Vim macro shell | fernape | (0)
    Imagine we have a simple program like the one below: #include <stdio.h> int main(int argc, char **argv) { char *str = "Hello guys, this is just a bit large string to test a nice Vim macro"; printf("%s\n", str); return (0); } This program is pretty simple, but it will serve its purpose. Imagine we have to inspect the content of str or for the same matter, any other memory address. We want to do it while we are inside a gdb session or while we are analyzing a core file. The simplest case is to do ...
  • 15.May.12
    ASCII codes in Vim shell | fernape | (2)
    Today, 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!
  • 06.Mar.12
    Colored diff shell | fernape | (0)
    As 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!
  • 09.Jan.12
    Greping from inside Vim shell | fernape | (0)
    Hi 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 ...
  • 04.Feb.11
    Easy svn blame vim mapping shell | fernape | (0)
    The 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!
  • 23.Oct.10
    Vim. Macros shell | fernape | (0)
    You 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 ...
  • 04.Sep.10
    Vim. Key mapping shell | fernape | (2)
    Maps 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 ...