Shlomif's Technical Posts Community [entries|archive|friends|userinfo]
Shlomif's Technical Posts Community

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

[Links:| Shlomi Fish's Homepage Main Journal Homesite Blog Planet Linux-IL Amir Aharoni in Unicode open dot dot dot ]

Announcing the Vim Beginners’ Site [Dec. 30th, 2012|02:48 pm]

[Tags|, , ]

I am glad to announce that I, along with some help from some other people, have set up the Vim Beginners’s Site - (or Vim-Begin for short). It aims to be a centrally managed, yet fully open content/open source site, for concentrating the Internet’s best material for learning about the Vim text editor and expanding one’s knowledge. The site was inspired by the Perl Beginners’ site (or “Perl-Begin” for short), and I set up the domains (and as a future redirect) to concentrate other similar high-quality sites introducing people to various technologies and topics. So if you want,,,, etc. then contact me and I’ll see what I can do.

The site is incomplete, and there's still a lot to do, but we have a Bitbucket mercurial repository, an issue tracker there, a TODO list, and we accept pull requests. The text for the site’s pages is under the Creative Commons Attribution 3.0 licence (unless noted otherwise) and whatever original source code is found there is under the MIT/X11 licence, and both were chosen to allow for maximal reuse. Nevertheless, we may mirror, restore, or link to, resources under different licences.

Cheers, happy new year, and happy Vimming!

LinkLeave a comment

Tech Tips: Vim, Facebook and Firefox’s Personas Rotator Extension [Oct. 18th, 2012|11:11 pm]

[Tags|, , , , , ]
[Current Location |Home]
[Current Mood |geeky]
[Current Music |Kid Rock - Born Free]

Here are three tech tips, that I felt did not necessitate their own entry.

In the Vim text editor(homepage), one can use the keybinding Ctrl+W ; O to close all windows except the current one, which will be the only one left open (hence the "O").

In Facebook (Wikipedia page) one can use Shift+Enter to start newlines in the messages you compose in the site’s composer. Press it twice to start a new paragraph.

If you are using Firefox’s Personas Rotator Extension ( page), then you can switch the currently shown persona ( in case you don't want it at the moment) using Ctrl+Alt+P or an alternate configurable keybinding. I discovered this latest tip by accident and can no longer imagine my life without it.


LinkLeave a comment

New Vim Plugin: Add to Word Search [Apr. 24th, 2012|10:51 am]

[Tags|, , , , ]
[Current Location |Home]
[Current Mood |lazylazy]
[Current Music |Lutricia McNeal - Stranded]

I’ve released a new plugin for the Vim text editor, called "add-to-word-search" ( GitHub repository, Vim Scripts page), and I’d like to introduce it here. If you like Vim, please let me know what you think by commenting below.

In order to properly introduce the plugin, one first should introduce the different (and useful) commands of Vim of * and #. What they do is search forward or backward for the complete word under the cursor (or somewhat before it or after it). Bram Moolenaar (the creator of Vim) covers them in his “Seven habits of effective text editing” document (there’s also a video available), and I think I covered them in a previous Vim tip.

Now, here is the use case that often bugged me: sometimes I searched for a certain function, found it in the text and then found a function that called this function (or often in the case of C code, a preprocessor macro that wrapped it), and wanted to look for its occurrences as well as those of the previous term. I wasn't aware of any good way to do it, so I ended up writing the “add-to-word-search” plugin.

After installing it, and after having searched for a word using * or #, one can press \** to search forward for an additional word under the cursor (or \## to search backward), and then use it more times to add additional words.

After publishing this plugin and mentioning it on #vim, “ironcamel” reported an issue that it gives an error if you have set nowrapscan. I fixed it, but was only able to do so by temporarily disabling nowrapscan, and then enabling it if it was previously enabled. (Apparently, vimscript’s exception-handling cannot handle some of the built-in errors.)

I also demonstrated it to my (now former) co-worker, who had been trying to get used to Vim, and he said it looked useful, but asked if there was an easy way to remove terms from the search query (which there is not at the moment), and I noted it may be a good idea.

Anyway, this Vim plugin is open-source and available under the MIT/X11 licence. Enjoy!

Link2 comments|Leave a comment

Vim Tips: scp URLs, "set tabpagemax" and fixing C indentation [Feb. 18th, 2012|06:24 pm]

[Tags|, , , , , ]
[Current Location |Home]
[Current Music |Simple Minds - Don't You Forget About Me (Live)]

Here are some Vim tips I ran into recently. First of all, when opening scp:// URLs, one should use two slashes after the hostname instead of 1, like scp://hostname//home/myuser/foo.txt instead of scp://hostname/home/myuser/foo.txt. I don’t know why that is the case, but it does not work properly without it. It also seems that netrw is buggy as it displays an irritating grey line on the cursor, the syntax highlighting tends to be off and saving a file displays several lines at the bottom.

Another tip is that gvim limits the number of tabs it opens when doing gvim -p [file1] [file2] [file3]. As a result, it is possible that not all files will be opened. If you want to change it you can set set tabpagemax in your .vimrc.

Finally, I noticed that Vim c-indentation tends to indent parameters to functions on subsequent lines using 8 spaces instead of 4 by default. I was able to change it to 4, which is my preference by adding set cinoptions+='(0,W4' to my .vimrc. There is plenty of other nifty stuff available in the cinoptions parameter.


Link2 comments|Leave a comment

More Vim Tips [Jul. 18th, 2011|12:09 pm]

[Tags|, , , , ]
[Current Location |Home]
[Current Music |George Harrison - I got my mind set on you]

Here are some more Vim tips I collected recently:

  1. One can repeat the last t, f, T or F command which moves to the next specified character in a line, or right before that, using ;, and repeat in the opposite direction using ,. I discovered those after starting to read through the vim usr_* manuals.

  2. One can get the Unicode value of the character under the cursor using the :ascii command-line command or the ga normal mode command.

  3. If you want to find how many lines/words/etc. are in a visual block, you can select it using "v" and friends and then type g-Ctrl+G.

  4. Finally, you can pipe the contents of the buffer or a range to an external program and view its output temporarily. So you can say :w !grep 'FOO' | wc -l to find the number of lines containing 'FOO', or :'a,'bw !grep 'FOO' | wc -l within a range.

I should note that one thing that annoyed me lately, is the fact that after I have a visual selection (v or V), I sometimes press u instead of y (because they are so nearby) and so cause the selection to become lowercase instead of yanking it.

Happy Vimming!

Link1 comment|Leave a comment

Perl: Using Vim's snipMate for Perl 5 snippets [Jan. 21st, 2010|06:26 pm]

[Tags|, , , , , , , , , ]
[Current Location |Home]
[Current Music |Ronald Jenkees - Let's Ride]

I noticed that there was some Perl 5 code that I had to type or copy-and-paste again and again on many occasions. So I decided to find a way to put it in one place and then recall it. I thought of writing it myself, but then recalled the snipMate snippets extension for Vim (which Peteris Krumins covered in a blog post), which allows that. After a little reading, I was able to prepare the snippets.

I placed the following under ~/.vim/snippets/perl/_slurp.snippet :

sub _slurp
	my $filename = shift;

	open my $in, "<", $filename
		or die "Cannot open '$filename' for slurping - $!";

	local $/;
	my $contents = <$in>;


	return $contents;

And now I can type "_slurp<TAB>" to recall it. The existing "slurp" snippet in ~/.vim/snippets/perl.snippets is quite evil, with an ugly inline line, typeglobs, and a two args open without a die statement. Thanks, but no thanks.

Afterwards I added the following in ~/.vim/snippets/perl/_ltestb.snippet

	local $Test::Builder::Level = $Test::Builder::Level + 1;

And now I can type "_ltestb" (short for "local Test::Builder") and put this line there to create my own custom Test::More/Test::Builder tests.

Thus, using snipMate, you can create your own short-hands for commonly-used snippets like that.

Link4 comments|Leave a comment

Vim Tip: Finding the First Non-Matching Line from the Cursor [Dec. 30th, 2009|06:47 pm]

[Tags|, , , , , , , , , , , , ]
[Current Location |Home]
[Current Mood |productive]
[Current Music |Atomic Kitten - Whole Again]

For a long time I've been viewing and editing vim text files, for example those of the UNIX find output or of archive contents, that contained many consecutive lines of similar data. What I wanted to do is find the line where these consecutive data end where there was something else instead. Among the workarounds I tried was to jump to the end of the file (using G) and then search backwards for the last matching line (which may not be very reliable). But a few days ago I decided that I had enough and sought a better way, and I indeed found one.

You can do it using a negated pattern. If for example you enter / home\/shlomi\/\(Arcs\/\)\@! you will find the first line that contains "home/shlomi" that is not followed by "home/shlomi/Arcs/". For information see :help \@!.

LinkLeave a comment

Random Stuff: Word Count Vim Tip, Mirroring CPAN Using rsync, and Mozbot [Nov. 30th, 2009|11:45 pm]

[Tags|, , , , , , , , , , , , , , ]
[Current Location |Home]
[Current Music |Roxette - Run To You (YouTube)]

This is a "random stuff" entry because I'm too lazy to write separate entries for each of the topics.

First of all the vim tip: you can do word count in Vim, by selecting a text using "v" and then typing "g" and then "Ctrl+g". This will display statistics on the text including word count. I always assumed it existed in a form but didn't had to use it until recently when I wrote a scene in a screenplay and wanted to see how long it was. This tip can also be found at ":help word-count".

The second tip is that in order to mirror a mini-CPAN that contains only the most recent releases using rsync instead of minicpan's HTTP or FTP download, one can use mst's in conjuction with the list of CPAN rsync mirrors. I needed to modify slightly in order to mkdir the "work" directory which it requires. I changed:




if ! test -e "work" ; then
    mkdir "work"

Finally, a little "recent hacktivity log": at one point someone on asked me if I could help them with their IRC bot called firebot and yesterday I decided to take a look at its core called "Mozbot", and maybe try to improve it. I took a look and detected many vestiges of "Ancient Perl" there, and other anti-patterns such as long subroutines or use of Net::IRC and decided to work on improving it.

After reading the "Using Mercurial locally with CVS" document on the Mozilla site (first hit in a Google search for "hg cvs") and setting up a "mozbot-shlomif" Mercurial repository to work on it, I submitted my first patch and have done more changes in the mozbot-shlomif repository. The code is not perfect, but at least it has "use strict;", the "-w" flag and the "-T" flag, so it could be much worse. I'd still like to move away from Net::IRC to POE-Component-IRC and maybe even try to port the entire Mozbot to buu's buubot. But it will take some time.

LinkLeave a comment

Source for the "E Text Editor" Was Released [May. 14th, 2009|01:03 pm]

[Tags|, , , , , , , , , , ]
[Current Location |Home]
[Current Music |Paul Simon - 50 Way to Leave Your Lover]

Apparently, the source for E Text Editor, a multi-platform Textmate clone was released under a not-entirely-open-source licence. This is good news despite the fact that it is not a fully-open-source licene, because now Textmate-like functionality is available for Linux and other platforms, and not only on the Mac.

I'm still sticking with Vim, though, which is fully cross-platform, open-source and even GPL-compatible.

LinkLeave a comment

Several Vim Tips [Apr. 30th, 2009|12:58 pm]

[Tags|, , , , , , , , , , , , , , , ]
[Current Location |Home]
[Current Mood |productive]
[Current Music |Nivel del Mar - Welcome Wilderness]

I have collected several vim tips in the past weeks, so here they are:

  1. One can use the :sp(lit) command to split a window into two. :new splits and starts editing a new buffer. Finally, both of these commands followed by a filename stats editing the specified file in the new viewport.

  2. This tip is long overdue. You can make Vim behave more like a Windows-like editor by adding source $VIMRUNTIME/mswin.vim to your .vimrc. Reportedly, it causes many problems and is not recommended, but I still like to use it, afer all these years.

  3. One can match any char including newline using \_.. The "\_" construct works for other character classes, and allows you to match all of them as well as newline.

    It took me a long time to find that, back when I did, so I'm documenting it here.

  4. After one indents or unindents several lines using "<", ">", "<<", ">>", etc. and the indentation level needs to be promoted or demoted further, one can use the "." (= repeat) command to repeat the shifting again (and again) until it is right.

    I discovered this trick by accident, but immediately found it useful.

Hope all Israelis had a nice Independence Day. Happy Vimming!

Link1 comment|Leave a comment

[ viewing | most recent entries ]
[ go | earlier ]