As anyone following this blog knows, I am an avid vi/vim user to the point of freakishness.
(I use ratpoison/wmii on ubuntu if anyone knows these tiled window managers)
The one thing that was missing in my repository was using vi commands to control word and outlook.
A couple of weeks ago that missing piece from the vi jigsaw seems to have been resolved:
http://www.viemu.com
Another high from my vi addiction....
If I could only use vi commands within the opera browser...I know there is something called vimperator for firefox, but I am a long time opera user and when I tried firefox there were too many features that I missed. Maybe one could get equivalent functionality using extensions, but ....
Friday, December 07, 2007
cyg-apt: apt for Cygwin
If you are a fan of debian distros, you must be a fan of apt-get ( I think fedora uses something called yum).
Many a times we would like the same functionality on cygwin, and this is served by the very useful utility cyg-apt!
You can download the utility from
http://download.linuxaudio.org/lilypond/binaries/cygwin/cyg-apt-gub
or
from http://www.lilypond.org/~janneke/software/cyg-apt
Save this as cyg-apt in your /bin directory or whereever. You might have to manually modify the official mirror in the file to some other cygwin directory if you have issues with the default mirror (I had).
Another mirror you might want to use is
http://mirror.mcs.anl.gov/cygwin
Once you have this installed, you can type
cyg-apt install XXX
similar to apt-get!
cyg-apt setup will bring up the default cygwin setup GUI
cyg-apt upddate will update the repos.
You have to make the cyg-apt file executable for all this to work of course!
Many a times we would like the same functionality on cygwin, and this is served by the very useful utility cyg-apt!
You can download the utility from
http://download.linuxaudio.org/lilypond/binaries/cygwin/cyg-apt-gub
or
from http://www.lilypond.org/~janneke/software/cyg-apt
Save this as cyg-apt in your /bin directory or whereever. You might have to manually modify the official mirror in the file to some other cygwin directory if you have issues with the default mirror (I had).
Another mirror you might want to use is
http://mirror.mcs.anl.gov/cygwin
Once you have this installed, you can type
cyg-apt install XXX
similar to apt-get!
cyg-apt setup will bring up the default cygwin setup GUI
cyg-apt upddate will update the repos.
You have to make the cyg-apt file executable for all this to work of course!
Monday, August 06, 2007
Split windows leaving you in splits?
Vim supports opening multiple files as split windows. You invoke that using :sp filename
However, sometimes one needs to keep multiple files open, and yet see enough number of lines for the current buffer. One has to press Ctrl-W 10+ or something along these lines to increase the height of the current window. Of course, you can use tabs, but I am yet to make that jump and have not seen a compelling need for it yet.
Instead of this, you can set an option in vim or in your .vimrc file like
set winheight=20
This will ensure that the minimum window height for the buffer you are currently viewing is 20 lines.
However, sometimes one needs to keep multiple files open, and yet see enough number of lines for the current buffer. One has to press Ctrl-W 10+ or something along these lines to increase the height of the current window. Of course, you can use tabs, but I am yet to make that jump and have not seen a compelling need for it yet.
Instead of this, you can set an option in vim or in your .vimrc file like
set winheight=20
This will ensure that the minimum window height for the buffer you are currently viewing is 20 lines.
Friday, July 13, 2007
File manager for the vi man - vifm
Vi rocks! I use ratpoison/wmii as my window manager, screen as my terminal manager, and vim as my editor (surprise!)
One problem is that, sometimes, I want to see a directory listing as in a conventional file manager and I am stuck with a bloated gui (ubuntu comes with nautilus as default)
Well, there is a solution - vifm.
Install it using:
apt-get install vifm
It is present in the ubuntu/debian repos.
The cool thing is you can manipulate stuff using vi commands.
Type
:help to see an overview of commands after bringing up vifm
There is also a vifmrc file inside ~/.vifm directory which can be manipulated - for example, use opera browser to deal with all html files.
vifm was inspired by midnight commander, another console based, and, more powerful file manager.
Though since vi is burnt into my synapses, I prefer vifm!
Home page of vifm: http://vifm.sourceforge.net/
Now, I can manipulate files using vi commands :D
One problem is that, sometimes, I want to see a directory listing as in a conventional file manager and I am stuck with a bloated gui (ubuntu comes with nautilus as default)
Well, there is a solution - vifm.
Install it using:
apt-get install vifm
It is present in the ubuntu/debian repos.
The cool thing is you can manipulate stuff using vi commands.
Type
:help to see an overview of commands after bringing up vifm
There is also a vifmrc file inside ~/.vifm directory which can be manipulated - for example, use opera browser to deal with all html files.
vifm was inspired by midnight commander, another console based, and, more powerful file manager.
Though since vi is burnt into my synapses, I prefer vifm!
Home page of vifm: http://vifm.sourceforge.net/
Now, I can manipulate files using vi commands :D
Thursday, June 28, 2007
Xpdf Keyboard shortcuts
Xpdf is an alternative to Adobe's Acrobat Reader in Linux. It is fast and easy and simple to use.
However, it is also powerful. There are a whole slew of keyboard shortcuts that can be used in xpdf to enhance your productivity and xpdf experience. I have compiled a few of them below
g : Go to page
p : Go to previous page
n : Go to next page
b : Go to next page
w: Fit width
z: Fit page
f: Find in page
q: Close and quit
o: Open document
r: Refresh/Reload document
However, it is also powerful. There are a whole slew of keyboard shortcuts that can be used in xpdf to enhance your productivity and xpdf experience. I have compiled a few of them below
g
p : Go to previous page
n : Go to next page
b : Go to next page
w: Fit width
z: Fit page
f: Find in page
q: Close and quit
o: Open document
r: Refresh/Reload document
Tuesday, June 12, 2007
Limit SSH Access
For added security, one may want to limit access to a machine through SSH from certain machines only.
You need to edit your /etc/hosts.allow and /etc/hosts.deny files for this
Edit your /etc/hosts.allow file and add your trusted machines/IPs:
sshd: 101.212.332.444, 523.326.447.129
sshd: 1.2.3.
The first two match exact IP addresses, the third will allow any IP beginning with "1.2.3.".
Next edit your /etc/hosts.deny file and add the following line:
sshd: all
This will deny all logins from IPs not explicitly allowed in the hosts.allow file.
Caution: Make sure that the IP addresses entered are correct, otherwise you risk locking yourself out of the server
You need to edit your /etc/hosts.allow and /etc/hosts.deny files for this
Edit your /etc/hosts.allow file and add your trusted machines/IPs:
sshd: 101.212.332.444, 523.326.447.129
sshd: 1.2.3.
The first two match exact IP addresses, the third will allow any IP beginning with "1.2.3.".
Next edit your /etc/hosts.deny file and add the following line:
sshd: all
This will deny all logins from IPs not explicitly allowed in the hosts.allow file.
Caution: Make sure that the IP addresses entered are correct, otherwise you risk locking yourself out of the server
Monday, June 11, 2007
Command line interface for the web - this is cool
If you are like most *nix users, you would rather prefer using the keyboard and the command line to do most of your daily chores.
However, the web browsing part of it is pretty much GUI (allowing for the elinks, lynx community out there).
Now, there is another website called YubNub which seeks to brind the CLI to the web....
For example type "am david allen" to do a search on david allen at amazon
Other examples include "wp turing" to look at the wikipedia entry on turing
However, the web browsing part of it is pretty much GUI (allowing for the elinks, lynx community out there).
Now, there is another website called YubNub which seeks to brind the CLI to the web....
For example type "am david allen" to do a search on david allen at amazon
Other examples include "wp turing" to look at the wikipedia entry on turing
Friday, June 08, 2007
Kill a defunct process
Many a time, when I do a "ps" or a "top", I see some processes tagged with "" meaning they are dead but they are still there :(
Killing them using -9 and process ID won't work either.
The problem is that these processes are tthose that were corrupted such that they cannot communicate (hence signalling would not work) with their parent or child process.
So, you will have to kill the parent or child process.
To find this, you can use the foll. command in linux:
$ps -ef --forest | less
Search for the word "defunct" to find the offending process and its parent. Use the parent's process ID to kill it, thereby killing the offending process also.
Killing them using -9 and process ID won't work either.
The problem is that these processes are tthose that were corrupted such that they cannot communicate (hence signalling would not work) with their parent or child process.
So, you will have to kill the parent or child process.
To find this, you can use the foll. command in linux:
$ps -ef --forest | less
Search for the word "defunct" to find the offending process and its parent. Use the parent's process ID to kill it, thereby killing the offending process also.
Wednesday, May 09, 2007
Converting jpg files to pdf
Utilities for most conversions are fairly obvious in linux - ps2ps, ps2pdf, ps2eps, etc.
However converting jpg to pdf is not obvious, because it uses the command 'convert' that comes along with imagemagick (which is a display tool invoked by the command 'display')
Thus for converting a file x.jpg to x.pdf, run
$ convert x.jpg x.pdf
To do this in an automated fashion for all files in bash, type
$ for FILE in *.jpg; do convert "${FILE}" "${FILE/.jpg/.pdf}"; done
However converting jpg to pdf is not obvious, because it uses the command 'convert' that comes along with imagemagick (which is a display tool invoked by the command 'display')
Thus for converting a file x.jpg to x.pdf, run
$ convert x.jpg x.pdf
To do this in an automated fashion for all files in bash, type
$ for FILE in *.jpg; do convert "${FILE}" "${FILE/.jpg/.pdf}"; done
Wednesday, March 28, 2007
Ctags not enough? Try Cscope
If you don't know what ctags is, you should read this.
If you are using ctags and are comfortable with it, but looking for something a bit more refined and powerful, you should be using cscope. It is very similar to ctags, except the ctrl-[ button is now replaced with ctrl-\ with many options to go to variable declarations, definitions, etc.
An excellent, but simple tutorial can be found here.
If you are using ctags and are comfortable with it, but looking for something a bit more refined and powerful, you should be using cscope. It is very similar to ctags, except the ctrl-[ button is now replaced with ctrl-\ with many options to go to variable declarations, definitions, etc.
An excellent, but simple tutorial can be found here.
Tuesday, March 27, 2007
Quick Intro to Crontab
This is another *nix power tool that is a must use. Scheduling jobs with crontab is so trivially easy.
Type
crontab -e
on your command prompt
This should bring up a window looking like this:
# m h dom mon dow command
Its stands for m-minute, h-hour of day (24 hr fmt), day of month, month, day of week, command.
Thus if my crontab looks like
# m h dom mon dow command
30 3 * * * rm -rf *
It tells it to run "rm -rf * " (Jeez! I am kidding, DON'T PUT THIS in your crontab) at 3.30 AM every day...
If I wanted to run the job say twice every day, I would put in
30 3,13 * * * rm -rf *
which will run the job at 330 AM and 130 PM.
That's it!
Type
crontab -e
on your command prompt
This should bring up a window looking like this:
# m h dom mon dow command
Its stands for m-minute, h-hour of day (24 hr fmt), day of month, month, day of week, command.
Thus if my crontab looks like
# m h dom mon dow command
30 3 * * * rm -rf *
It tells it to run "rm -rf * " (Jeez! I am kidding, DON'T PUT THIS in your crontab) at 3.30 AM every day...
If I wanted to run the job say twice every day, I would put in
30 3,13 * * * rm -rf *
which will run the job at 330 AM and 130 PM.
That's it!
Monday, March 26, 2007
Execute across all windows in gnu screen
screen is one of the coolest underrated unix utility. If you have not heard of it, or don't know enough about it, check out the excellent intro here. The tutorial is meant for Gentoo Linux, but is general enough for all *nix distro.
One of the things missing in the tutorial is, if after working in screen for a while, if you want to send a command to all windows, say a new export DISPLAY command, how to go about it.
Simple:
Press Ctrl-A :
The screen command window should be highlighted at the bottom.
At the ":" prompt, type
at "#" stuff "export DISPLAY=localhost:0.0\015"
That is all! The \015 is used if you don't want to go through the pain of pressing enter at each of the windows...if you would rather press enter manually, just take that off. If you look at the command, you see that "#" can be pretty much replaced with window numbers to execute commands at only certain windows. You will have to dig into manuals for more info....
One of the things missing in the tutorial is, if after working in screen for a while, if you want to send a command to all windows, say a new export DISPLAY command, how to go about it.
Simple:
Press Ctrl-A :
The screen command window should be highlighted at the bottom.
At the ":" prompt, type
at "#" stuff "export DISPLAY=localhost:0.0\015"
That is all! The \015 is used if you don't want to go through the pain of pressing enter at each of the windows...if you would rather press enter manually, just take that off. If you look at the command, you see that "#" can be pretty much replaced with window numbers to execute commands at only certain windows. You will have to dig into manuals for more info....
Left handed mouse without getting left-handed compliments?
How do you get your mouse pointers reversed in *nix?
The solution - type
xmodmap -e "pointer 3 2 1"
to reverse your mouse. That's all. Getting errors like the following?
xmodmap: commandline:1: bad number of buttons, must have 9 instead of 3
xmodmap: 1 error encountered, aborting.
Change your command to:
xmodmap -e "pointer 3 2 1 4 5 6 7 8 9"
If it expects 5 buttons, just write "3 2 1 4 5" after pointer....
The solution - type
xmodmap -e "pointer 3 2 1"
to reverse your mouse. That's all. Getting errors like the following?
xmodmap: commandline:1: bad number of buttons, must have 9 instead of 3
xmodmap: 1 error encountered, aborting.
Change your command to:
xmodmap -e "pointer 3 2 1 4 5 6 7 8 9"
If it expects 5 buttons, just write "3 2 1 4 5" after pointer....
Thursday, February 22, 2007
A more targeted kill
A few posts ago, we learnt how to kill by name (killall "name"). We also know how "xargs" works. (See previous posts if you don't know to use either)
While this works for a number of cases, we will often have the case where the actual command might be the same, but what matters is the path it is invoked from or some such stuff.
For example, I have the command "test" in two directories:
/home/me/scripts/test
/home/me/tools/test
I want to kill only those "test" commands which are from the "tools" directory. A little bit of awking is required. My command in this case will be:
ps aux | grep 'tools/test' | gawk '{print $2}' | xargs kill -9
However, if you want to run this remotely (in another machine), you may have to invoke
bash -c " ps aux | grep 'ssh' | gawk \"{print \"\\\$2\"}\" " within your ssh command (it will lead to a case of painful backslashitis if I included the full command here, so am taking the easy way out).
While this works for a number of cases, we will often have the case where the actual command might be the same, but what matters is the path it is invoked from or some such stuff.
For example, I have the command "test" in two directories:
/home/me/scripts/test
/home/me/tools/test
I want to kill only those "test" commands which are from the "tools" directory. A little bit of awking is required. My command in this case will be:
ps aux | grep 'tools/test' | gawk '{print $2}' | xargs kill -9
However, if you want to run this remotely (in another machine), you may have to invoke
bash -c " ps aux | grep 'ssh' | gawk \"{print \"\\\$2\"}\" " within your ssh command (it will lead to a case of painful backslashitis if I included the full command here, so am taking the easy way out).
Friday, February 16, 2007
The pipe smokes
While this is not a tutorial on unix pipes , aka "|", one who uses this will notice that it does not work when dealing with output streamed to stderr...
i.e.
$cmd | cmd2
will work only on o/p of cmd that is streamed to stdout. This is a fundamental property of pipes - it will work on only one channel
A workaround to this is:
$cmd 2>&1 | cmd2
i.e. redirecting stderr to stdout, so that the pipe can read this.
i.e.
$cmd | cmd2
will work only on o/p of cmd that is streamed to stdout. This is a fundamental property of pipes - it will work on only one channel
A workaround to this is:
$cmd 2>&1 | cmd2
i.e. redirecting stderr to stdout, so that the pipe can read this.
Split it exactly into two "equal" halves???
Alright, you know to use the vim :sp command, and noticed that halves are supposed to be equal.
But, did you know that you can resize the splits within vim very easily?
As a start, if you are editing one file and want to open another, but not give it more than 10 lines, you would type
:10 sp file2
What if, now you are in the file2 split and want to increase its size a tad? Type
Ctrl-w +
If you now want to split the windows equally, you can typle Ctrl-w =
If you want to increase the size by 15 lines, you would type Ctrl-w 15+
Substitute the "+" for "-" if you want to decrease the size of the split you are viewing.
But, did you know that you can resize the splits within vim very easily?
As a start, if you are editing one file and want to open another, but not give it more than 10 lines, you would type
:10 sp file2
What if, now you are in the file2 split and want to increase its size a tad? Type
Ctrl-w +
If you now want to split the windows equally, you can typle Ctrl-w =
If you want to increase the size by 15 lines, you would type Ctrl-w 15+
Substitute the "+" for "-" if you want to decrease the size of the split you are viewing.
Wednesday, February 14, 2007
Indentation fix using vim
I know, I know, you are supposed to indent every line religiously, and use "cindent" or "autoindent" within vim to make your job easier.
But, (there's always a but), sometimes you are hacking something together, and you don't care...
Sometimes you are hacking OPC (other people's code.....similar to OPM other people's money), and its ugly....
You don't want to indent every line. What do you do?
In command mode within vim type "gg=G", and see how magic is made.....(It is "gg=G", not ":gg=G")...
But, (there's always a but), sometimes you are hacking something together, and you don't care...
Sometimes you are hacking OPC (other people's code.....similar to OPM other people's money), and its ugly....
You don't want to indent every line. What do you do?
In command mode within vim type "gg=G", and see how magic is made.....(It is "gg=G", not ":gg=G")...
Oh, I like those highlights!
When you are searching for a pattern in vim, it helps to enforce "search as you type " with highlighting. For this include the following in your .vimrc:
set incsearch
set hlsearch
It also helps while using s//, if you are trying to replace (especiallyto check for mistakes in the pattern matching), to have the search pattern highlighted. Assuming the above two lines are added in your .vimrc,
First, search for the pattern you want to replace , e.g. XXX
/XXX
This will have highlighting and incsearch on for you to see whether there are any matches, etc.
Now, type in the pattern you want to replace XXX with (e.g. YYY)
:%s//YYY
This will remember the "XXX" search, and replace instances of XXX with "YYY"
set incsearch
set hlsearch
It also helps while using s//, if you are trying to replace (especiallyto check for mistakes in the pattern matching), to have the search pattern highlighted. Assuming the above two lines are added in your .vimrc,
First, search for the pattern you want to replace , e.g. XXX
/XXX
This will have highlighting and incsearch on for you to see whether there are any matches, etc.
Now, type in the pattern you want to replace XXX with (e.g. YYY)
:%s//YYY
This will remember the "XXX" search, and replace instances of XXX with "YYY"
Subscribe to:
Posts (Atom)