Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Tuesday, May 4, 2010

Install Vim-outliner on K/Ubuntu

I spoke of vim-outliner a few years ago and was recently reminded of it again while listening to the mintcast podcast regarding orgmode for emacs.

Orgmode seems to be fairly feature rich, but I never liked the whole key combination thing with emacs. To this day, I can't figured out how to close an emacs session. Vim just seems easier. It's a preference.

Vim-outliner doesn't seems to have all the features of orgmode on the great emacs OS, but it is good at what it does...outline. It seems to follow the Unix philosophy of doing one thing and doing it well, instead of the emacs philosophy of cram as much as possible into an app. So I attempted to install it on my Kubuntu 9.10 machine and it's not as simple as an aptitude install. So, here is how to get vim-outliner installed and set up on a current version of K/Ubuntu.

$ aptitude install vim-vimoutliner

Make sure you have vim-addon-manager installed. If not install it. Then,

$ sudo vim-addons -w install vimoutliner

Finally, make sure you have the following in your ~/.vimrc file, if you don't already,

filetype plugin indent on

To start vim-outliner, simply open vim with any file with the extention .otl, such as:

vim file.otl

and you're good to go. Please visit my prior post on vim-outliner for a quick tutorial or use vim's help to access the documentation by typing ":help vo" in an open vim session.

Tuesday, April 13, 2010

Vim - Cut and Paste a Block of Text Between 2 Files

Vim is my editor of choice, but I would never consider myself an expert. So when I wanted to copy text from one text file to another in vim, I was challenged. Although I was frustrated for a brief moment, I remembered uncle google and he helped me with my conundrum. So here is how you cut and paste a section of text from one text file to another using vim.

First open your first text file in vim. Scroll down to the first line of the block of text you wish to copy and press "ma" (that is m followed by a, without the quotation marks). "m" marks the beginning of your block. The "a" makes the assignment of copying the text to buffer "a".

Now scroll to the end of the block of text you wish to copy and press "y'a" (again without the quotes). The "y" yanks the text block. The single quote in the middle, I guess designates the end of the block and "a" again identifies the buffer being used.

Next open the second text file by typing ":split filename.txt" (Remember no quotes). This will open the second text file in a split vim session window. Scroll to the line where you would like the text pasted and press "p" (You should know, don't include the quotes). This will paste the block of text on the line below the current cursor position. Save and your done.

Please leave comments with other examples of cutting and pasting in vim.
Enjoy.

Tuesday, March 23, 2010

HTML Editors for Beginners

In about two weeks, I'll begin teaching an HTML class and I'll need a good HTML editor with syntax highlighting. I need something cross platform as I know that most students will be using Windows and at least one will be using a MAC. I, of course, will be using Linux. I prefer using vim.

Vim is great as I can run it at the command line, in a GUI (gvim) and on any OS you can think of. Within vim you can activate html syntax highlighting by simply typing:

:set syntax=html

That will add html syntax highlighting for only that session of vim. You will need to add "syntax on" in your .vimrc file for highlighting to be permanent.

Now as much as I love vim, I'm not going to have my students use it. This is an HTML class for the absolute beginner and introducing vim to the class is a hurdle I don't want to jump over. So, I'm leaning towards having my students use bluefish. Bluefish has several cool features including running on all three major platforms.

Any other suggestions for an HTML editor for beginners? What features do you like? What are your thoughts regarding bluefish?

Thursday, September 20, 2007

Get Organized with VIM....yes, VIM.

I've recently discovered and have become addicted to vim-outliner. If you've never used a note taker or outliner before then it's time to get organized. Outliners are great for organizing projects, planning events, meetings, presentations, talks, note taking and satisfying many other organizational needs. I wish I knew about vim-outliner when I was in college, it would have been the perfect tool for managing lecture note and class projects. I now use vim-outliner for organizing work tools and open source projects.

To install vim-outliner in Ubuntu is as easy as opening a terminal and typing:
sudo apt-get install vim-vimoutliner

Now you will need to edit the /etc/vim/vimoutlinerrc file to enable necessary features, so in a terminal type:
sudo vim /etc/vim/vimoutlinerrc

Press 'i' to enter insert mode then make sure the following 2 lines are uncommented:

let g:vo_modules_load = "checkbox:hoist"
and
let maplocalleader = ",,"

Also make sure that the following line ends with a zero, not a 1:

let g:use_space_colon=0

Now save the file by pressing the 'esc' key to exit insert mode and type:
:wq

Now, let's get outlining!
To open a vim-outliner file type:
vim filename.otl

You must have the '.otl' extension to your filename for vim to act as an outliner. To use the outline just start typing, remembering to press 'i' first to enter vim insert mode. Create categories and sub-categories by tabbing. Here is an example:

How to Back up Your Data

   CD-RW
      Storage
       Lifespan
   USB Drive
      Storage
      Lifespan
   Rsync


The above is an example of a 3 level outline, vim will automatically color code each level. To add text or notes to a category, start a new line under a heading and begin the new with a :(sp) (That's colon followed by a space). Here is an example:

How to Back up Your Data

   CD-RW
      Storage
         :  Make sure you store your CD's in fairly cool conditions
         :  Don't storage your CD's in direct sunlight
      Lifespan
Your text will automatically wrap as needed. Now comes the fun part....folding.
Exit vim's insert mode my pressing 'esc' and move your cursor to one of the newly
entered text lines and press the 'z' and 'a' keys (z-a) and you should get
something like the following:

How to Back up Your Data
   CD-RW
      Storage
         [TEXT] ------------------------- (2 lines)
      Lifespan
Pretty neat! There are some built-in keyboard shortcuts that unleashed the real
power of folding. Here are some of those handy commands:

Z-c


collapse a tree within command mode

Z-o


expand one level

z-O


expand all the way down

>>


Demote headline, collapse the tree to demote all children

<<

Promote headline, collapse the tree to promote all children

,#

Fold at level #, all set foldlevel=# (i.e. ,,3 will foldset at level 3)

,,-

Draw dashed line

,,f

Directory listing of the current directory

,,s

Sort sub-tree under cursor ascending

,,S

Sort sub-tree under cursor descending

,,t

Append timestamp (HH:MM:SS) to heading


There are several other commands. To learn more commands and other outliner
features you can access vim-outliner documentation while in vim, by typing:

:h vimoutliner

I know...... I know..... You are well impressed, but wait there's MORE!!!!!

You can add checkboxes and percentages of completion to each of your categories.
You do this by moving the cursor to the heading of choice and pressing the following
keys ",,c%" (that's "comma comma the letter 'c' and the percentage symbol")
This will create something like this:


[_] %How to Back up Your Data
[_] %CD-RW
[_] Storage
[TEXT] ------------------------- (2 lines)
[_] Lifespan

You can toggle a checkbox as checked or unchecked by pressing the following
keys ",,cx" (comma comma the letter 'c' and the letter 'x'). Here is a
screeenshot of a partially complete oultine with checkboxes and percentages:


Here is a list of checkbox commands:

,,cb

Insert a check box on the current line or each line


of the currently selected range (including lines in


selected but closed folds).

,,cx

Toggle check box state (percentage aware)

,,cd

Delete check boxes

,,c%

Create a check box with percentage placeholder

,,cp

Create a check box with % placeholder on all headings

,,cz

Compute % completion for the tree below the current heading.

Of course vim-outliner also has all the vim features and commands that
you've come to expect and love. So all vi controls and keyboard entries
work with outliner. You can find more information about vim-outliner at
http://www.vimoutliner.org.
At the vim-outliner site you'll find some neat scripts to convert .otl files
to .html and .sxi (OpenOffice.org Presentation format).


Now go get organized!

Wednesday, August 29, 2007

Word Processing (with Latex) in the Command Line

In my never-ending quest to prove that you can do anything in the CLI that you can do in a GUI, this is my attempt at word processing in the command line. There is no true word processor for the CLI, that I'm aware of, but the results of using the Latex typesetting language create a good enough end result. If your not familiar with Latex typesetting language, you can sort of compare it too html markup language. With Latex you use code to assign your document layout, font type, font size and other document characteristics. A skilled Latex artist can create absolutely beautiful, high quality and professional documents.

In the GUI, I'd recommend using Lyx a great WYSIWYG Latex editor, but we're in CLI land here so we'll be using vim-latexsuite a fantastic plug-in to a brillant text editor. In Ubuntu, just 'sudo apt-get install vim-latexsuite' and you are good as gold. The vim-latex-suite has a very in-depth guide built-in. You can access the guide once in vim by typing:
:h latex-suite

This blog will walk you through creating a simple document and serve as just an introduction to the vim-latex-suite. For more a more comprehensive explanation of the latex-suite please see the guide mentioned above.

Open a vim session by typing:
vim texdoc.tex

Now press the 'i' key to change vim to 'insert mode' and type or copy the following into vim:

\documentclass[12pt]{article}\title{My First \LaTeX{} Document!}
\author{Jared Bernard}
\date{December 25 2010}
\begin{document}
\maketitle Ubuntu is my favorite Linux distribution of all time! I can do anything in the CLI that you can do in a GUI plus more. So there..... (sticks tongue out at GUI).
\end{document}

Everything that starts with a '\' is what defines the format of the document. Here is a basic description of what we just created.

  • This document is an article, using a 12 pt font. (There are several types of document classes. 'report' is another common class.)
  • the Title of this document is 'My First Latex Document!'
  • Its author is Jared Bernard. (me)
  • It was written in December 25 2010.
  • Everything else is the content of the document

Now that we know what we created, press the 'esc' key to change to 'normal mode' in vim. Then type ':w' (w/o quotes) to save the document.

Now here comes the fun part, HOLD down the '\' key while pressing the 'l' (el) key twice. This is described in the vim-latex-suite guide (mentioned at the beginning of this blog) as \ll. This will compile the .tex document. If your typeset language has mistakes you will see an error message at the bottom of vim session. If this occurs verify that your typeset language is exactly as the example given and make the appropriate changes. Otherwise, if everything worked out well, you should see no evidence of anything happening :).

Now exit vim, by typing:
:wq

Now that you are at the command line type:
ls

You should now see some new files that where created, texdoc.aux, texdoc.dvi, texdoc.log and of course texdoc.tex. These are your data files for your new document. The .dvi file is your main latex file. There are several ways to view your newly created document, but first you must install some CLI .dvi viewers. Type 'sudo apt-get install dvi2tty dvifb dvipng fbi' to install the viewers which are discussed below.

The first way is using dvi2tty, so type:
dvi2tty texdoc.dvi

This is not my preferred way to view your document as the formatting isn't always accurately displayed, but is does give you a quick look at what you have just created without the typeset language.

A Better option to view your document is using dvifb. To view, type:
dvifb texdoc.dvi

Isn't that beautiful! :) If you copied the typeset exactly as I have it you will notice the word 'Latex' in the title and the unique format I designed for it. You can see the difference as it's displayed with dvi2tty compared to dvifb.

You can also convert your .dvi file to a png image, by typing:
dvipng texdoc.dvi

This will create a file named 'texdoc.png'. You can view this image using fbi by typing:
fbi texdoc.png

Now that's great, but what if I want to email my document to my gui-loving and windows-loving friends? How can they view my new beautiful document. They should have no problem viewing your newly created .dvi file using any pdf viewer like xpdf or Adobe's Acrobat Reader or viewing the .png file in any image viewer.
If you need to make changes to your document, just open the original .tex file and make the necessary changes, save the document, compile the document using the \ll command and you should be good to go.

Let me know what you think. If there is ANYTHING you thought couldn't be done on the Command Line that can be done on the GUI, let me know. I'll try to figure it out and blog about it.