Changing a feature's functionality often involves tracking down where it is used throughout a program's source code. Or say you're trying to find a nasty bug that is generated by a rouge stored procedure and you want to find every location it is called. To search for text in files I often grep via the command line, look at the matches and then manually load up each file. Today I'll join the two methods together in a fairly eloquent way using vim.
Using it
| Command |
Description |
| :cd to\my\dir |
Change to the directory I want to look in |
| :lvimgrep 'discount' *.txt |
Search for the text discount in any .txt file in the current directory |
| :lnext |
Go to the next match |
| @: |
Repeat :lnext, go to the next match |
| @@ |
Keep looking through matches |
| :lopen |
Open the list of matches – looks very similar to grep output in the command line |
| jjj |
Move down the list to another match |
| <Enter> |
Moves to the match under the cursor |
| :lprevious |
Move to the previous match |
| :lnfile |
Move to the next file |
| :lfirst |
Go back to the very first match |
Worth mentioning is that ** (starstar) can be used to search down directories and help related to vimgrep is in quickfix.txt, so use that reference to discover more.
Here is a handy method that I recently adopted for password management. I'm guilty of using almost one password for every new site I sign up to. Today I finally decided to do something about it using a combination of Dropbox and KeePass.
The setup is simple and involves getting Dropbox installed and then KeePass installed into the Dropbox folder.
KeePass
KeePass is a free and open source password manager that works on all major OS platforms. The idea is to store all password and login information in it so that each website that needs user credentials has a unique password. Because KeePass remembers passwords instead of you, the passwords can be longer and more random for added security.
Step 1 – Get Dropbox Setup
Dropbox is an online service that allows files to be backed up and synchronised across other computers. The free option currently provides a generous 2GB. Using Dropbox we will able to:
- Keep the password database backed up in a secure offsite location.
- Access our passwords from multiple devices (home desktop, work laptop, phone etc.)
Create an account (https://www.dropbox.com/login#register) and download/install the software (https://www.dropbox.com/install).
Step 2 – Get KeePass
Download KeePass (http://keepass.info/download.html) 'Professional' portable version. The portable version will keep everything we need contained to make Dropbox integration easier. Don't worry about the 'Professional Edition' part; it's still 100% free. Note that if you are installing onto Linux or Mac OS then there is an additional step of installing Mono. Most windows users won't need to do anything.
Since Dropbox does not currently allow any arbitrary folder to be 'watched' the easiest way to tell Dropbox about KeePass is to create a folder in the Dropbox folder (such as KeePass) and store KeePass and the database file there. Dropbox acts just like any old folder so moving/renaming later is fine if you want to reorganise.
Install KeePass by extracting the downloaded zip file into the KeePass folder.
Quick Start Guide to KeePass
Run KeePass.exe and create a password database. Ctrl + N and choose a name and location. I created another folder called data under the KeePass folder and simply named the database 'pwd'. This will let KeePass remember where the database file is using a relative path so that on other computers the Dropbox and KeePass folder can be anywhere you like.
The next step is choosing a master password. I opted for just having a master password and not a combination of password and key file because it will be easier for me to migrate to this new way of using passwords.
Choosing a master password is a careful process because:
If you forget this master password, all your other passwords in the database are lost, too. There isn''t any backdoor or a key which can open all databases. There is no way of recovering your passwords (http://keepass.info/help/base/keys.html#password)
If the master password and database is stolen then all passwords are compromised. This is all about a trade-off between usability vs. security. Remember we're not trying to create the world's most secure system for logging into websites, but improve upon existing practices.
I also opted for a passphrase rather than a normal password. Passphrases are like passwords but are much, much longer for added security. The Wikipedia entry has some tips for selecting passphrases including the Diceware approach where the passphrase is essentially made up of randomly selected words. 80-bit strength is considered a good number to aim for.
Dropbox and KeePass
Keeping the whole KeePass program in Dropbox means that on subsequent computers all that needs to be done is install Dropbox and you automatically have access to KeePass.
Create an entry for Dropbox in KeePass and change Dropbox's password to try out the new password management for the first time.
