Posts Tagged ‘Vim’

2011w29

Sunday, July 24th, 2011

vim and ctags

I’ve been meaning to look into ctags for a while, mostly because I’ve wanted some better way of being able to locate the definition or calls of a function, than popping up a new terminal and running grep. I know of :[l]grep and :[l]vimgrep and should really spend a day or two learning those as well, but ctags looks like it could be more useful to know immediately so for now I’ll focus on getting acquainted with these keybindings.

ctags itself is “exuberant ctags” and is found on sourceforge, if not available from your package manager. If you’re using vim you’ll also want to grab the ctags.vim script and just drop it into your ${HOME}/.vim/plugin/ directory.

In your source directory simply run $ ctags -R and you will have yourself a tags file for this directory and all subdirectories. Opening a file and calling :TlistOpen will give you a list of all the found definitions in the project. Unfortunately for me, I want all the newly created windows from a split to appear to the right or below, the original window, EXCEPT for this tag list window ;)

The solution to that came in a StackOverflow thread and is called Ctrl-W R

There are several good posts which helped me come to terms with ctags.

firefox and sorting downloads

For a while now *cough*since around 2006*cough* I have been using the absolutely asskicking add-on Download Sort for Firefox. You set up your rules for where files with a certain extension should go, and then you just start downloading files, and they all end up where they should.

Or so the theory goes. But let’s say that you get tired of having to move all your wallpapers downloaded from deviantart.com or wherever, to your wallpapers folder, from the generic images folder?

Then Download Sort is looking less good. There just isn’t a way to differentiate between an “image” jpg and a “wallpaper” jpg.
Sadly, the only add-on I’ve found which advertises the features I want, Automatic Save Folder, didn’t work for me at all. It might be my overly paranoid security settings screwing things up, but for some reason it just won’t remember any of the rules I set into place…

urxvt-tabbedex

I started playing with tabbed urxvt. I ultimately ended up installing urxvt-tabbedex and using that instead. The differences are small, but tabbedex doesn’t provide a “new” button (a new shell is spawned using Shift-Down, and tabbedex provides (the perhaps less useful) feature of renaming a tab (Shift-Up).

wmii

I have lived under the impression that I was using a really old wmii (even though the package I used was wmii-hg which should pull the latest version from the repository). The reason I was under the impression that this was old was that it never came any updates when I executed a $ yaourt -Sayu.

When I finally looked into it yesterday I finally realized that I was running on bleeding edge. The trick to wmii-hg, apparently, is that you need to manually re-install it to have it fetch the latest updates… What I took as project inactivity (and must thus be an old branch) was in fact not so.

As tagrules are severely broken in wmii-hg it hasn’t been fun using it (and colrules behaved very strange, but strange in a way I have now come to appreciate… go figure) but there were always issues with the wmii package in the repository, most having to do with an insane amount of flickering when creating a new terminal, or moving one about etc.

The flickering parts seems to have been solved, it might have had something to do with my transparent terminals and not a problem with wmii, I don’t know, but now it works.

Thanks goes out to pesa for single-handedly seeking out and vanquishing my final annoyance of wmii 3.9.2: that every now and then it would start spawning more than one terminal when I issued a command to get one.

When I was reloading the configuration, the old process remained, and with it, the listeners for keyboard commands… like starting a new terminal…

mercurial-server

I’ve been running the mercurial-server package on my server to provide me with easy access to (mercurial) repositories. This week, for some reason, it started failing.

I had updated mercurial from 1.3 to 1.9 and my first thought was that this had broken mercurial-server somehow, but after reverting the package, the problem came back.

Not immediately, mind you, which makes this whole thing even stranger.

But this has just provided me with the right amount of kick in the ass to get on my way and convert from mercurial to git, so all in all perhaps not a bad thing?

Links

Why I’m not going near spotify: It sums up pretty well my own feelings about Spotify…

In certain (rather specific) contexts, I even despise Spotify users, and here’s why: Imagine that you are sitting on a train, and you will be doing so for the next seven hours or so. The train has “internet”, via one 3G modem.

Now picture ten other passengers ALSO going online, their objective being to listen to Spotify. Can haz moar bandwifs plz? kthxbai

:wq

2011w26

Sunday, July 3rd, 2011

How silly of me… I totally forgot to publish last weeks summary yesterday. So without further ado, only one day late:

bashPhotoGallery

I don’t know how I get myself into these things… all of a sudden I found myself needing a, reproducible, way of setting up a photo gallery, complete with thumbnails and affixing a content license to the images.

When it comes to creating a batch of thumbnails, imagemagick is the tool to use. Accept no substitutes!

I am also going through a little crush on markdown.

Getting rid of UTM variables

I am not all that fond of those UTM variables that some “services” tack onto their links in order to better track where people are coming from (I understand why they’d do it, but I have no interest in being tracked, even if all they want to know is whether or not their push to be visible on $SOCIAL_MEDIA_SITE_OF_THE_MONTH is successful.
I know that I by accident stumbled upon a blog post outlining how to get rid of them programmatically, and I also know that I for some reason or other couldn’t find it, but without being too paranoid, I can understand why Google might not want to help people find the knowledge to do that ;)
In any case, I stumbled upon two resources for doing just that, but I think that was more due to dumb luck than any concentrated effort on my part, actually, it was quite by accident while looking for something else.

Bash is so cool!

I already knew about echo {A,B,C,D} (great in conjunction with mkdir -p, but I have realized that bash is cooler than that.
echo {A..D} delivers the same result, without the need to explicitly specify all of the chars I want expanded. Nice!

makefile blogging :: comments

psquid had a rather interesting solution to blog comments. I’ll have to think more about this. I don’t know how I feel about letting some other party (even if it is as nice a party as identi.ca) host “my” comments, but it is totally worth considering.

Wednesday

All in all a pretty good day. Got to assist razor with both vim and LaTeX skills (the student has become the master, yay!), got some writing out of my head, and ended up doing a little Test-Driven Python hacking.

And although I was a bit sceptical about OlofB‘s pyTDDmon, especially about it blinking continuously, which could get really old really fast, at first, I have to say that it has kindof grown on me since.

2011w25

Sunday, June 26th, 2011

Last week was rather eventful, the largest thing being the one thing I naturally forgot to write about (go figure…), my appointment as deputy coordinator of FSFE Sweden. This is nice :)

That has however meant that this week hasn’t seemed as eventful, and I don’t know, for some reason I got off to a really slow start of the week, the only worthwhile things to write about started happening this Thursday.

nginx and password-protected directories

My father asked me for help in getting a bunch of files in his possession, over to some friends of his (who are, to the best of my knowledge, as computer illiterate as he is).

This meant that my first idea, to just set up an FTP-account on my server and have them log into that and download the files, wouldn’t work. I would need something simpler, but still with restricted access.

Preferably they’d just surf to some place, enter a password, and download a zip-archive (since all Windows versions since XP handles zip-archives like compressed folders, this should fall into the realm of what a computer user should be able to handle).

Something like Apache’s htpasswd stuff. And I wanted to do it with nginx, because I really want to get better at using and working with it.

The first task, obviously, was to check if nginx had that capability at all (it has), and if so, how it works.

This post showed me that it was possible, and how to do it.

A note here though: I first tried to set a password containing Swedish characters (åäö) and this didn’t work at all.

ticket

I have been wrestling with the question of how I would manage to create a database which individual users can read from and write to, but which they shouldn’t be able to remove from the filesystem (I know, a DROP or DELETE command can be just as devastating, so I must continue thinking about this).

alamar at StackOverflow solved this for me. The solution is to let the file be read and writeable, but have the parent directory not be writable.

This however makes it impossible to add new files to the directory. But since I am working with the idea that there should be a “ticket” user with a corresponding “ticket” group, and that every individual who should have access to the tracker will be in that ticket-group, the directory could disallow writing for group and other, leaving the ticket-user free to create more databases…

Although I now realize that this would make it easy for anyone in the ticket-group to screw around with any ticket database (insert, update, delete).

This clearly needs more design thought put behind it.

ArchLinux and MySQL client binaries

I needed to interact with a MySQL database on another server, but MySQL (the server) wasn’t installed on my desktop, and I didn’t really want to have to install the entire server just to get hold of the mysql client binary so that I could interact with the remote server.

Turns out that in ArchLinux, themysql binaries are split into a clients and a server package, perfect for when you wish to interact with MySQL databases, but not have the entire frakking server installed on your machine.

Accessibility, HTML and myConf

Since FSCONS is striving to be accessible, and the little “myConf” technology demonstrator I wrote the other week was intended for FSCONS, I have been trying to figure out how to make that as accessible as it can be (first of all, I have no idea what so ever, if a screen reader even parses javascript, and as the myConf demonstrator is mostly implemented in jQuery that might present itself a showstopper).

But given the assumption that a screen reader can parse javascript, and will output that big ‘ol table which is created, how do I make an html table accessible? Since a screen reader makes use of the html code, and even a sighted person could get tripped up trying to parse the markup of a table, this looks like a worthwhile venture.

Sadly, like all documents from w3.org, they just leave me more confused and without any questions answered than when I began, but luckily, there seems to be other resources more knowledgeable, and with more understandable wording/examples, although I haven’t had the time to read through them all yet (I’m mostly just dumping them here so that I’ll be able to find the pages again once I again have the time to look into it):

Ed Weissman has taken his most insightful comments from Hacker News and compiled it into a book, which he then graciously made available for free.

Now, I have to admit, until this week, I’d never heard of Ed, and I have rarely read stuff on Hacker News, but from what I’ve read so far of his book, I might have to change this.

Optimizing Vim usage

A fellow… hmmm, a fellow Fellow made me realize just how long it is going to take me to fully grok Vim. I have been using ggVGd to:

  1. Go to the first line (“gg”)
  2. Enter visual mode (spanning entire lines) (“V”)
  3. Go to the last line (“G”)
  4. And finally delete the selection (the entire contents of the file) (“d”)

Or one could just do :%d as the fellow showed me… And I have been using the pattern :%s/foo/bar/ for quite some time, understanding perfectly that “%” in this context means “for every line do…”

I just never made the connection that it could be applied to something simpler than a sed substitution.

Links

Lack of (American) geeks is a national security risk according to DoD. Funny, anyone else who thinkgs that if they just stop prosecuting every kid who is playing around with security systems, or dowload music, or build (more or less dangerous) stuff from schematics they found online, this problem might just go away on its own?

2011w24

Sunday, June 19th, 2011

Vim

I have begun to use {c,d}f<character> to change or delete from the cursor up until (including) <character>.

It has made me a little bit faster in some few edge cases of text-editing, but today (Monday) I found myself in need of doing a couple of manipulations on text up until (NOT including) <character>.

SuperUser.com helped me find {c,d}t<character>.

Very nice :)

MediaWiki sortable tables

In preparation for FSCONS one of my duties as team leader for the Hardware team is to keep track of all the hardware available to FSCONS (i.e. hardware owned by FFKP) and Jonas felt it would be a good idea to have that list available on a wiki.

When I was done adding the laptops and cameras it kindof bugged me that I’d added the laptops in the “wrong” order (i.e. the serial number column wasn’t ordered).

Luckily this was an easy fix, as one can add class="wikitable sortable" to the table header in the wiki-syntax and it will automagically add the necessary javascript and buttons to make each column sortable.

FreedomBox

The “Bump” Challenge aimed at creating a simple(r) way of exchanging public keys and establishing trust, possibly (probably?) using smartphones which are able to sync with the FreedomBox, seems like a rather nice idea.

Personal Wikis

A wiki can be a great tool, and for a while I was maintaining a personal mediawiki installation, just adding stuff I needed from time to time, but never often enough that I could learn it.

Then I stumbled over Zim, which became collateral damage as I got into my “replace as much as possible with a command-line alternative”-phase (this phase hasn’t abated yet ;)) which left me migrating to VimWiki.

I am not likely to replace VimWiki, it works well for me, but sometimes it might not be the right tool for the job. Which is why I am always on the lookout for new stuff.

I already knew about ikiWiki, but at the time I discovered it I didn’t have the time to look further into it. I guess I should change that.

And today I found TiddlyWiki, a wiki self-contained within an html file. Which people have extended for other uses.

SQLite Triggers

SQLite has support for triggers, how cool is that?! And these triggers can be triggered by other triggers! :D

Links

Vim Casts is a Vim screencast resource for learning / improving your knowledge in Vim (thank you for the tip hook).

Tahoe-LAFS (Least Authority File System) is a decentralized fault-tolerant peer-to-peer file system. I can’t really speak about its security, but it looks pretty good, at least on paper.

ZRTP seems to be a pretty cool VoIP encryption protocol, and there seems to be an implementation for Android devices as well.

“Towards a Lifelong Content Management System” is a rather nice, well thought-through blog post on how we might want to change the way we think about content management systems (thanks @mlinksva).

:wq

2011w23

Sunday, June 12th, 2011

myConf

This is a technology demonstrator of the FSCONS myConf concept that doesn’t rely on any server-side programming.

It also became my first project under git versioning.

myConf is a concept we’ve (FSCONS) been thinking about implementing since, IIRC, 2009.

Basically it should allow a participant to tailor a personalized conference schedule, instead of having to mark it up in a dead-tree version.

Or so is at least my understanding of the myConf concept.

In short it is a Javascript (jQuery) / JSON-powered site, from which I have now learnt two things:

  • It is as important (if not more so actually) to have a good JSON structure as it is to have a good database design, otherwise it WILL come back and bite you, hard
  • It is actually quite fascinating what one can do with Javascript (at least when a library is used so that you don’t need to even think about platform irregularities)

Expect a public release shortly.

vim foldsearch plugin

I was editing my sudoers file (I still haven’t gotten myself off sudo) and started wondering if there perchance wasn’t a way in vim to hide lines according to some pattern.

The default archlinux sudoers file is full of comments, to the point that it is almost hard to see the uncommented lines.

:g/pattern and :v/pattern only takes you so far, i.e. it shows you the lines, but immediately disappears when trying to edit or move or anything except just looking at it.

Luckily for me other people had already asked the same question, and yet other people had answered it.

Which lead me to the vim foldsearch plugin. Best of all, it is easy to use.

Search for something, i.e.:

/my pattern here

and then use <Leader>fs (I have mapped <Leader> to \ in my config, so for me that would be \fs) and voilà, all the lines not matching the search are folded away.

renameutils

I am sure I have already written about renameutils, or more likely about qmv, but it is worth repeating. qmv rocks!

wallpaper-switcher.sh

wmii is my window-manager, although I am probably running version 3.6 or something (i.e. not 3.9) so this might not be usable for people other than wmii 3.6 users.

Anyway, last Friday I got the idea to write a little script to switch wallpapers for me. Today I sat down and hacked it together:

#!/bin/bash
 
tmpList="$(ls -l ${HOME}/wallpapers/*.jpg | awk '{ print $NF }')"
tmpList=($tmpList)
 
randomWallpaper="${tmpList[$(($RANDOM % ${#tmpList[@]}))]}"
 
ln -fs "$randomWallpaper" "${HOME}/wallpaper.jpg"
exit 0

Links

shunit2 Unit-testing for (Bash) shell scripts, this is so cool :D
Akka for a simple way of writing concurrent applications in Java
Protolol jokes for nerds

2011w21

Sunday, May 29th, 2011

timetrack

I have come up with a way to achieve the changes I want, but without introducing sqlite3 as a dependency, and a big part of the solution is to use bash arrays.

Furthermore, I have been thinking about how to, if possible, get timetrack to automagically start a new session when a file in the project is opened.

This won’t help anyone to start the timetracker when thinking about the project, but at least when physically transferring code from brain to hard drive, and the lead I am working off of is inotify.

ticket

During this weeks FSCONS meeting jonaso jokingly suggested that I’d try to write an issue tracker in bash. (damn you! ;))

Of course my mind started wandering and although there is no code to back it up, I have a couple of rather interesting ideas about how to pull it off.

For this project, sqlite is the way to go, but I was somewhat worried about concurrent access which I probably shouldn’t be.

My tests indicate (oh yeah, so there exist code, just not any actual issue tracking code) that the sqlite3 library is intelligent enough to lock the file, and thus doesn’t allow concurrent access.

I’ll still need to devise a way of detecting these locks, and have the second script stand in line and try again later, but that should be trivial.

Links

Turning Vim into a modern Python IDE

Learning styles
From what I can gather, I am an assimilator. resistance is futile!

Cheat sheets!

The 9 secret burdens of being a Linux user

Big businesses acting out like this might very well get me to start boycotting them again…

String manipulation in bash

Seemingly nice way of doing HTTP requests in Python

Vim and adding licenses to code

Thursday, March 31st, 2011

A while back @psquid gave me a new perspective on things.

I can’t remember what the discussion was about, but it left me with the realization that my current system (of having file type templates in vim coming with predefined licenses (GPL v3)) was flawed.

The thing I believe he got out of the discussion was that one could use snipMate to define ones own shortcuts for inserting licences into source code.

I couldn’t tell you why I hesitated so long before trying it, since the idea seemed sound. But when I did try it I came to two conclusions:

(1) It wouldn’t work the way I wanted it to , or (2) at least not without duplication.

Since I on occasion program both Python, Java, PHP, Bash and, infrequently, Erlang, in order to have licensing snippets (think GPL3, BSD, and the odd CC By-SA) I’d need to put these license-blurbs into each snippet file that should support it (since Python don’t do C-style comments, and Erlang-style comments are completely different as well)

So what I wanted was some way to call a Vim command (say NERD Commenter ( ,,cs )) once a certain snippet (the license blurb) had been expanded.

I am pretty sure this can’t be done in an easy way, so I gave that idea up. Mapping a key, say F3, to a user defined command in my .vimrc, however,  would be much easier.

Something along the lines of:

function! GPL3()
    r~/static/templates/gpl3
    :.,$call NERDComment(0, 'sexy')
endfunction
nmap  :call GPL3()

I am not well-versed at all with scripting vim, so I have probably made some embarrassing mistakes (for one, I should probably read up on what the heck that exclamation mark at the beginning of the function does. Please do point out any mistakes.)

All in all I am pretty content with this solution, but if someone know of a way to trigger a command after a snipMate expansion (and only on specific expansions, and only on the specific expanded lines) I am all ears.

(This since there is a _.snippet which seem to be included in all instances regardless of file type, which means I could still have the licenses in one place, defined once, but used with different comments anyway, which would be awesome) :)

:wq

Vim + snipMate

Sunday, March 14th, 2010

As I sat down in front of the computer today and started reading the identi.ca backlog I came across this gem, which lead here, about how to turn Vim into a Python IDE. The blogpost itself contained many useful tips/tricks (the code folding script being on the top of that list), but as is often the case, the really cool stuff gets unearthed in the comments, like this one about snipMate. Also, excellent video presentation is excellent!

That post also lead me to another post on that blog which inspired me to finally start looking into ctags, which is a two step installation, one being installing the package exuberant-ctags from the repository, and the other fetching this script.

All I need to do now is try to learn the key mappings M^e, f, M^f, and TT/F4 ;D oh, and to tab a lot ;D

PyRoom

Saturday, February 20th, 2010

From what I can gather it all started with the OSX application WriteRoom, a seemingly (I’ve never tried it) excellent “distraction free” text editor. When I first heard of it I liked the idea, realized it was an OSX app, and moved on.

A while later I came across Dark Room, a WriteRoom clone for Win32. Still a bit annoyed over the lack of such an application for GNU/Linux I again moved on.

And then a couple of weeks ago, almost the same day, I heard about PyRoom from two different sources (I still maintain that the universe has a flaw in its random number generator ;)), and tried it out.

And I have to say, albeit the very spartan interface, and almost none of the power I find in Vim, PyRoom is perfect for its purpose. It is a distraction-free full-screen text editor, no more, no less.

I would never think of doing heavy text manipulation in PyRoom, Vim excels at that and enters the stage the second PyRoom has played its part, but for pure text creation, i.e. from in-head ideas to on-file text, PyRoom has no opposition.

For aptitude-enabled people

$ sudo aptitude install pyroom

will do the trick.

Remote editing using vim

Saturday, January 23rd, 2010

Through identi.ca and the user @jargon I found a nifty tip (sadly pasted into a temporary paste-bin which is why I document it for myself and others here) on how to edit remote files in (g)vim.

You could of course do it the old fashioned way of first logging on to the remote server using ssh and then open up vim there (which assumes that vim has been installed on that remote location)

The other way of doing it involves scp:

$ vim scp://example.com//path/to/remote/file

This also works fine through gvim.

The goodness didn’t stop there though, as the same scp magic can be used with vimdiff to compare a remote and a local file:

$ vimdiff scp://example.com//path/to/remote/file /path/to/local/file

It’s things like this that make me really love (g)vim.