Difference between pages "Package:Vim" and "Package:Irssi"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
(Add details about paste mode, instead of disabling auto-indent.)
 
 
Line 1: Line 1:
{{Ebuild
{{Ebuild
|Summary=Vim is an improved, vi-style text editor with many features.
|Summary=A modular textUI IRC client with IPv6 support.
|CatPkg=app-editors/vim
|CatPkg=net-irc/irssi
|Maintainer=
|Maintainer=
|Repository=Gentoo Portage Tree
|Homepage=http://www.irssi.org/
}}
}}
== Introduction ==


So you thought you could get by with gedit? Not when you must configure an application on your server in a data center two states away! When it comes to remote system administration, all roads lead back to Vim. Not a Vim expert? No problem, you just need a handful of commands to do everything you need to do.
=== Description ===
irssi is a small command line IRC client based on ncurses. It's a great thing to use when you SSH into a server, or just simply for your main IRC client.  


Entire books have been written about Vim, and they still fail to capture all of its functionality. But the core command set is all you really need if you're just making a few changes to a few files over SSH. You might not do it as efficiently as a Vim expert, but it's good enough to get the job done. In fact, if you're working with Vim (the pre-eminent vi-clone) on a server, there's a good chance it's "vim-tiny," a stripped-down Vim that offers the traditional vi functionality but not the full set of Vim features.
=== Installation ===
The install of irssi is pretty straight forward. There are not many USE flags, but one that is worth looking at is the {{c|SSL}} flag. This enables you to use SSL when connecting to servers.
{{console|body=
###i## echo "net-irc/irssi ssl" >> /etc/portage/package.use
###i## emerge irssi
}}
=== Using irssi ===
Using irssi initially can be a little intimidating if you're not used to command line programs. To first start irssi, you just simply run:
{{console|body=
$ ##i##irssi
}}
There are flags you can pass to the command line while starting irssi, such as:
{{console|body=
$ ##i##irssi -n mynick -c irc.freenode.org
}}
This would connect you to Freenode with the nick 'mynick'. Or alternatively you can just run the {{c|irssi}} command and connect via SSL if you need to:
{{file|body=
/connect -ssl irc.freenode.org
}}
This will automatically connect you over port 6697.  


==Insert Mode==
When you have connected to the server of your choice, you can join a channel simply by:
The first thing you must grok is that Vim has several modes -- command mode, insert mode, and last-line mode (also known as ex mode). When you start Vim, you'll be in command mode. Here, all of the keys are used to perform commands, not input text. To switch to input mode, hit <span style="color:green">i</span>, and you're able start editing the file, adding text, using Backspace, etc.
{{file|body=
To return to command mode, hit <span style="color:green">Esc</span>. To enter last-line or Ex mode, use :, and then input the command you wish to enter.
/j #funtoo
}}
If you want to leave any channel you've entered you can use the {{c|part}} command:
{{file|body=
/part #funtoo reasons...
}}
There are a few ways of navigating through your channels, you can use {{c|alt+<nowiki>{1-9}{q-p}</nowiki>}}, or alternatively you can use the {{c|window}} command that is in irssi:
{{file|body=
/window 1
/window 2
/window 3
}}
For as many channels you are apart of.  


==Vim Command Mode==
When you're ready to leave, you can simply type in:
I could go on for days about the commands needed in command mode, but we're just here for the basics, so let's look at movement. Movement is based on the standard alphabetic keys:
{{file|body=
/exit
}}
Which will close out connections to the IRC networks you've joined, and take you back to your console window.
=== Themes and scripts ===
==== Scripts ====
There are a few things you can do to make irssi look a little bit better and add some cool features. There are a few plugins that are pretty useful, such as {{c|fnotify.pl}} which is a script that utilizes {{f|libnotify}} to send you popup notifications for when your nick is pinged or you are sent a private message.  


* '''h''' Move the cursor to the left one character.
{{file|name=fnotify.pl|lang=perl|desc=fnotify.pl|body=
* '''l''' Move the cursor to the right one character.
# todo: grap topic changes
* '''j''' Move the cursor down one line.
* '''k''' Move the cursor up one line.


You can move faster by using <span style="color:green">b</span> and  <span style="color:green">w</span> to move backward and forward by one "word" at a time, respectively. Vim looks at "words" as a string of alphanumeric characters. So "eix" is a word, but "eix-sync" is multi-word because it's broken up by a non-alphanumeric character.
use strict;
use vars qw($VERSION %IRSSI);


Deleting is done with  <span style="color:green">d</span> or  <span style="color:green">x</span>. To delete a single character, move the cursor over that character and use <span style="color:green">x</span>. Using <span style="color:green">dw</span> will delete the word the cursor is over, and <span style="color:green">db</span> will delete the previous word.
use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
authors    => 'Thorsten Leemhuis',
contact    => 'fedora@leemhuis.info',
name        => 'fnotify',
description => 'Write a notification to a file that shows who is talking to you in which channel.',
url        => 'http://www.leemhuis.info/files/fnotify/',
license    => 'GNU General Public License',
changed    => '$Date: 2007-01-13 12:00:00 +0100 (Sat, 13 Jan 2007) $'
);


To delete an entire line, use <span style="color:green">dd</span>. To delete from the cursor to the end of the line, use <span style="color:green">d$</span>. To delete from the cursor to the beginning of the line, use <span style="color:green">d0</span>. The $ is shorthand for "end of the line," and 0 is shorthand for beginning of the line. You can also use ^.
#--------------------------------------------------------------------
# In parts based on knotify.pl 0.1.1 by Hugo Haas
# http://larve.net/people/hugo/2005/01/knotify.pl
# which is based on osd.pl 0.3.3 by Jeroen Coekaerts, Koenraad Heijlen
# http://www.irssi.org/scripts/scripts/osd.pl
#
# Other parts based on notify.pl from Luke Macken
# http://fedora.feedjack.org/user/918/
#
#--------------------------------------------------------------------


==Copying and Pasting in Vim==
#--------------------------------------------------------------------
Let's look at copying and pasting real quick. To highlight text to copy, use the <span style="color:green">v</span>, <span style="color:green">V</span> and <span style="color:green">Ctrl-V</span> commands. You might have guessed by now that Vim commands are case-sensitive, So v and V are different things.
# Private message parsing
#--------------------------------------------------------------------


The <span style="color:green">v</span> command simply allows you to highlight changes character by character using the movement (hljk and others) or arrow keys. The <span style="color:green">v</span> command highlights entire lines. And the <span style="color:green">Ctrl-v</span> command highlights blocks of text -- very useful for highlighting and copying columns of text.
sub priv_msg {
my ($server,$msg,$nick,$address,$target) = @_;
filewrite($nick." " .$msg );
}


Once you've highlighted the text you want to copy, hit <span style="color:green">y</span> to "yank" the text into the buffer.
#--------------------------------------------------------------------
# Printing hilight's
#--------------------------------------------------------------------


To paste the text, use <span style="color:green">p</span> or <span style="color:green">P</span> to paste. The p command will paste after the cursor, and P pastes before the cursor.
sub hilight {
==Search and Replace==
    my ($dest, $text, $stripped) = @_;
To search through the document, use the / key to initiate a forward search, or ? to initiate a backward search.
    if ($dest->{level} & MSGLEVEL_HILIGHT) {
filewrite($dest->{target}. " " .$stripped );
    }
}


To search and replace, use <span style="color:green">:s</span> with the range of lines and search terms. Like so:
#--------------------------------------------------------------------
<pre>
# The actual printing
:%s/old/new/
#--------------------------------------------------------------------
</pre>


The % means "global," but you can replace that with a range of lines, like this:
sub filewrite {
my ($text) = @_;
# FIXME: there is probably a better way to get the irssi-dir...
        open(FILE,">>$ENV{HOME}/.irssi/fnotify");
print FILE $text . "\n";
        close (FILE);
}


<pre>
Irssi::signal_add_last("message private", "priv_msg");
:1,15s/old/new/
Irssi::signal_add_last("print text", "hilight");
</pre>
Another example of search/replace functions
<pre>Command        Outcome
:s/xxx/yyy/    Replace xxx with yyy at the first occurence
:s/xxx/yyy/g  Replace xxx with yyy first occurrence, global (whole sentence)
:s/xxx/yyy/gc  Replace xxx with yyy global with confirm
:%s/xxx/yyy/g  Replace xxx with yyy global in the whole file</pre>
I prefer to use the <span style="color:green">c</span> (confirm) and <span style="color:green">g</span> (global) options too, so when searching it will search the entire line and not just the first occurrence of a string.


A usual search would look something like :%s/old/new/gc, and when you hit Enter you'll be prompted before you make changes. I recommend using confirm; otherwise you can wind up with unexpected results.
#- end
}}
Another very useful script is for colored nicks, to better tell people apart. Which can be found at [http://scripts.irssi.org irssi scripts] called {{f|nickcolor.pl}}.


==Undo==
When you have the scripts you would like you would put them into {{f|~/.irssi/scripts}} and set a link to {{f|~/.irssi/scripts/autorun}}.
What if you've made an edit you didn't want to make? Easy, use the undo <span style="color:green">u</span> command. If you didn't mean to undo what you did -- and it's easy to accidentally hit u -- use <span style="color:green">Ctrl-r</span> to redo the last change.
{{console|body=
Quick note: If Vim is in vi-compatibility mode, it will have only one "level" of undo. In normal Vim mode, you can undo many, many changes. But vi undoes only the most recent change.
$ ##i##wget -O ~/.irssi/scripts/nickcolor.pl http://scripts.irssi.org/scripts/nickcolor.pl
 
$ ##i##cd ~/.irssi/scripts/autorun
==Saving, Quitting and More ...==
$ ##i##ln -s ~/.irssi/scripts/nickcolor.pl .
One of the things that's severely non-obvious while working with Vim the first time is how do I get the heck out of here? You can quit Vim in a number of ways, but I'll show the most usual ones.
$ ##i##ln -s ~/.irssi/scripts/fnotify.pl .
 
}}
First, if you want to save your changes before exiting Vim, use  <span style="color:green">:w</span> or save and exit in one action with <span style="color:green">:wq</span>.
You can do this for as many scripts as you've chosen to use. They will automatically load when you start irssi. You can also manually load scripts:
Don't want to save your changes? It happens. No problem, just use <span style="color:green">:q!</span> if you realize that you've made some edits that you don't want to save, and they are too complex to easily undo before exiting. Note that you can also write changes to a different filename by using :w newfile.
{{file|body=
 
/load ~/.irssi/scripts/fnotify.pl
This is just a short and sweet intro to Vim for emergencies or minimal usage. You could do much, much more with Vim if you wanted. Be sure to read through the Vim tutorial by running vimtutor, and look through Vim's documentation by running :help. But in a pinch, this list of commands should get you through.
Irssi: Loaded script fnotify
 
== Good Starter Vimrc ==
 
The following file makes a very good starter <tt>.vimrc</tt> file. Place it in your home directory, and you will get true tabs (displayed indented 4 spaces) and you will be able to see all the whitespace in your document, which is handy when editing critical files:
 
{{file|name=~/.vimrc|desc=A good starter .vimrc file|body=
set noexpandtab
set shiftwidth=4
set tabstop=4
set listchars=eol:%,tab:>-,trail:~,extends:>,precedes:<
set list
filetype indent off
filetype plugin off
}}
}}
 
Whichever works best for you is what you should do.
By default, copying and pasting into a vim window will cause things to horribly auto-indent. To fix this, add the following to your <tt>.vimrc</tt> file:
==== Themes ====
 
You can choose from many themes on the [http://irssi.org/themes irssi themes] page if you don't like the default look of it. Once you've chosen the them you like, you can simply put it in your {{f|~/.irssi/}} directory and when you run just run:
{{file|name=~/.vimrc|desc=fix pasting auto-indentation|body=
{{file|body=
set noai
/set theme mycooltheme
}}
}}
And there you have it, the theme you have chosen is now there.
=== Conclusion ===
irssi is a great IRC client, and really helpful if you spend a lot of time in a terminal emulator or on a server.


Alternatively, you can temporarily switch to "paste mode" before pasting with <span style="color:green">:set paste</span>. You will see <tt>-- INSERT (paste) --</tt> in the status bar when you are in insert mode. Don't forget to disable paste mode with <span style="color:green">:set nopaste</span> after pasting. You can also use bang to switch between "paste" and "nopaste" so that you just have to recall the last command : <span style="color:green">:set paste!</span>. ([http://vim.wikia.com/wiki/Toggle_auto-indenting_for_code_paste See also])
== External Resources ==
[http://www.irssi.org/documentation Further documentation]


{{EbuildFooter}}
{{EbuildFooter}}
[[Category:IRC]]

Revision as of 07:49, January 22, 2015

Irssi

   Tip

We welcome improvements to this page. To edit this page, Create a Funtoo account. Then log in and then click here to edit this page. See our editing guidelines to becoming a wiki-editing pro.


Description

irssi is a small command line IRC client based on ncurses. It's a great thing to use when you SSH into a server, or just simply for your main IRC client.

Installation

The install of irssi is pretty straight forward. There are not many USE flags, but one that is worth looking at is the SSL flag. This enables you to use SSL when connecting to servers.

root # echo "net-irc/irssi ssl" >> /etc/portage/package.use
root # emerge irssi

Using irssi

Using irssi initially can be a little intimidating if you're not used to command line programs. To first start irssi, you just simply run:

user $ irssi

There are flags you can pass to the command line while starting irssi, such as:

user $ irssi -n mynick -c irc.freenode.org

This would connect you to Freenode with the nick 'mynick'. Or alternatively you can just run the irssi command and connect via SSL if you need to:

   
/connect -ssl irc.freenode.org

This will automatically connect you over port 6697.

When you have connected to the server of your choice, you can join a channel simply by:

   
/j #funtoo

If you want to leave any channel you've entered you can use the part command:

   
/part #funtoo reasons...

There are a few ways of navigating through your channels, you can use alt+{1-9}{q-p}, or alternatively you can use the window command that is in irssi:

   
/window 1
/window 2
/window 3

For as many channels you are apart of.

When you're ready to leave, you can simply type in:

   
/exit

Which will close out connections to the IRC networks you've joined, and take you back to your console window.

Themes and scripts

Scripts

There are a few things you can do to make irssi look a little bit better and add some cool features. There are a few plugins that are pretty useful, such as fnotify.pl which is a script that utilizes libnotify to send you popup notifications for when your nick is pinged or you are sent a private message.

   fnotify.pl (perl source code) - fnotify.pl
# todo: grap topic changes

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
	authors     => 'Thorsten Leemhuis',
	contact     => 'fedora@leemhuis.info',
	name        => 'fnotify',
	description => 'Write a notification to a file that shows who is talking to you in which channel.',
	url         => 'http://www.leemhuis.info/files/fnotify/',
	license     => 'GNU General Public License',
	changed     => '$Date: 2007-01-13 12:00:00 +0100 (Sat, 13 Jan 2007) $'
);

#--------------------------------------------------------------------
# In parts based on knotify.pl 0.1.1 by Hugo Haas
# http://larve.net/people/hugo/2005/01/knotify.pl
# which is based on osd.pl 0.3.3 by Jeroen Coekaerts, Koenraad Heijlen
# http://www.irssi.org/scripts/scripts/osd.pl
#
# Other parts based on notify.pl from Luke Macken
# http://fedora.feedjack.org/user/918/
#
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# Private message parsing
#--------------------------------------------------------------------

sub priv_msg {
	my ($server,$msg,$nick,$address,$target) = @_;
	filewrite($nick." " .$msg );
}

#--------------------------------------------------------------------
# Printing hilight's
#--------------------------------------------------------------------

sub hilight {
    my ($dest, $text, $stripped) = @_;
    if ($dest->{level} & MSGLEVEL_HILIGHT) {
	filewrite($dest->{target}. " " .$stripped );
    }
}

#--------------------------------------------------------------------
# The actual printing
#--------------------------------------------------------------------

sub filewrite {
	my ($text) = @_;
	# FIXME: there is probably a better way to get the irssi-dir...
        open(FILE,">>$ENV{HOME}/.irssi/fnotify");
	print FILE $text . "\n";
        close (FILE);
}

Irssi::signal_add_last("message private", "priv_msg");
Irssi::signal_add_last("print text", "hilight");

#- end

Another very useful script is for colored nicks, to better tell people apart. Which can be found at irssi scripts called nickcolor.pl.

When you have the scripts you would like you would put them into ~/.irssi/scripts and set a link to ~/.irssi/scripts/autorun.

user $ wget -O ~/.irssi/scripts/nickcolor.pl http://scripts.irssi.org/scripts/nickcolor.pl
user $ cd ~/.irssi/scripts/autorun
user $ ln -s ~/.irssi/scripts/nickcolor.pl .
user $ ln -s ~/.irssi/scripts/fnotify.pl .

You can do this for as many scripts as you've chosen to use. They will automatically load when you start irssi. You can also manually load scripts:

   
/load ~/.irssi/scripts/fnotify.pl
Irssi: Loaded script fnotify

Whichever works best for you is what you should do.

Themes

You can choose from many themes on the irssi themes page if you don't like the default look of it. Once you've chosen the them you like, you can simply put it in your ~/.irssi/ directory and when you run just run:

   
/set theme mycooltheme

And there you have it, the theme you have chosen is now there.

Conclusion

irssi is a great IRC client, and really helpful if you spend a lot of time in a terminal emulator or on a server.

External Resources

Further documentation