Publishing a Blog in Vim with Vimpress

Publishing a Blog in Vim with VimpressI like blogging. :)

I learned though that writing blogs is an art in organization and learning the tools used to make them. I reviewed blogging software before and said that I really liked Drivel. This week though may have changed all that. I decided to crash test Vimpress and test how she does. Now, I can say I’m really impressed. I am very possibly going to keep using it.

Vimpress is a plugin for Vim that allows editing and added posts to WordPress blogs. Vimpress also will list the posts written to easily go back and edit them. Blogging is as simple as BlogList, BlogNew, BlogOpen and BlogSend. Installation is easy enough, just put the blog and syntax file in their respective folders:

tar zxvf vimpress.tar.gz -C ~/.vim

Edit ~/.vim/plugin/blog.vim to point to WordPress php-file. Mine for example is https://linuxtidbits.wordpress.com/xmlrpc.php. And Vimpress will be ready. For more look at Vimpress’s homepage.

After I set it up, Typing in Vim and publishing in Vimpress does so without a hitch. Very nice. A couple things to keep in mind to help ease the transition…

Html markup will have to be learned. Only the basic tags need to be learned though (a href, img, pre…) not too bad. Also I find that the closetag plugin is a good idea. The closetag plugin maps ctrl-_ to close the tag. A few lines will need to be added to the ~/.vimrc for it to be active:

" Automatic tag closing for html and xml (closetag plugin)
autocmd Filetype html,xhtml,xml,xsl source ~/.vim/scripts/closetag.vim
let g:closetag_html_style=1
source ~/.vim/scripts/closetag.vim

Vimpress comes with a syntax file that highlights the BlogList and header, if html syntaxing is desired its easy enough to set:

:setfiletype html

I was hoping to find a way to nest html in the syntax file but haven’t just yet found out how.

Publishing a Blog in Vim with Vimpress

Anyways, I’ve really liking using Vim and Vimpress so far. As I’ve said previously the learning scale is a bit more but well worth it. I need to learn some more about cutting and pasting in Vim (to and from the Xserver) to really be effective but I’m getting there.

Vim Setup – Tuning Vim To The Environment

Vim is best used when it is configured for the users needs. Vim has a slew of configurations to develop the type of environment the user requires to do numerous different tasks from spell checking to color syntaxing. There are thousands of scripts and color themes available on the Vim website that can add even more abilities.

I talked yesterday of learning Vim and perhaps just as important is tailoring one’s own configuration file (~/.vimrc). The best place to start is finding a person’s ~/.vimrc who is already experienced in Vim. Some distro’s may install a custom ~/.vimrc already so it’s best to take a look. I personally use Brians Carpers ~/.vimrc which does a good job for me. There are literally thousands out there and people like to share them, so pick the right one for whatever Vim needs to do.

Aesthetics

Setting up the terminal and Vim correctly are important parts for long periods in front of the terminal. To help ease reading and prevent eye strain a couple things that can help are choosing a lower-contrast colorscheme and properly sizing the width of the terminal

Colorscheme:

To pick a colorscheme that is comfortable for viewing for long periods go ahead and start up Vim – /etc/X11/xorg.conf can provide a good example. Now type:

colorscheme 

follow by a space. Now press “tab” for tab-completion – pressing tab will cycle through the available color schemes. For example, this one is called pyte:

72 Section "InputDevice"
73     Identifier "Generic Keyboard"
74     Driver     "kbd"
75     Option     "CoreKeyboard"
76 #   Option      "XkbRules"      "pc104"    
77     Option     "XkbLayout"        "us"
78     Option      "XkbLayout"     "en_US"
79     Option     "XkbModel"     "macintosh" 
80 #   Option      "XkbVariant"    "apple"
81 EndSection
82
83 Section "InputDevice"
84     Identifier "Configured Mouse"
85     Driver     "mouse"
86     Option     "CorePointer"
87     Option     "Device"       "/dev/input/mice"
88     Option     "Protocol"     "auto"
89     Option     "ZAxisMapping" "4 5"
90 EndSection

For xterm users (gnome-terminal, stjerm, tilda?, others?…) it’s likely that the terminal is set to eight bit color for compatibility reasons (see my post from a couple days ago). Vim though can display in 256 colors and will need to for alot of these colorschemes to work. To set Vim to 256 colors, add the setting to the ~/.vimrc

set t_Co_256

New colorschemes can be found in at the Vim website. To get a good idea what they look like before installed take a look at Vim Color Scheme Test. Color schemes need to be put in ~/.vim/colors and then a color scheme can be permanently added by putting them in the ~/.vimrc:

colorscheme blue

Terminal Width

The width of the terminal is also important. The human eye can only scan about 10 words before it loses focus (i.e. has difficulty scanning to the next line). Most text in Linux is written with a margin of 72 or 80 characters. Most editors also use a soft-returns (i.e. not a hard line break). Use whatever is best by resizing the window to fit this many characters. Vim cannot set a soft-return and rather uses the window width. This is unfortunate as some terminal apps (tilda, and yakuake) use the entire width of the screen – yes vim has settings like “textwidth” and “wrapmargin” but they create hard-returns, so having a wide terminal is not a good idea with Vim.

V Tips

A few tips I picked up along the line.

  • Vim has great help documentation. :help topic can be done on about anything.
  • Vim has tab-completion for entering commands and bash-completion for files (e.g. :w ~/Desktop/myblog.txt)
  • The mouse can be used in Vim for some functions, but it needs to be enabled. I use this setting as I find that moused in visual mode can be distractive.
  • set mouse=ni
  • To be able to select text with the mouse in this mode hold the shift key
  • I       Insert at beginning of line
    A       Append to end of line

  • Tab-mode rules:
    vim -p doc1 doc2
    gt      go through tabs
    :tabnew To open new tab

  • Append a file:
    :w >> ~/My-lousy-document
  • Check spelllinng:
    :setlocal spell spelllang=en_us
    :setlocal nospell
    ]s      next word
    [s      previous word
    z=      word suggestions
  • Spelling can be mapped to a key if used frequently enough, in my ~/.vimrc I mapped spelling the the F7 key:
    map <F7> <Esc>:setlocal spell spelllang=en_us
    map <S-F7> <Esc>:setlocal nospell
  • I like to alway have tabs so I put these in my ~/.bashrc to have tabs every time I open a file:
  • alias v="vim -p"
    alias sv="sudo vim -p"

My Terminal – Gush

Vim Setup - Tuning Vim To The Environment 

Command line to xclipboard

Update: Script has been updated to add pipe support. Thanks to Nathan who allowed me to use his improvements.

It’s really something to be learning Linux. The more I learn about Linux the more I learn it’s about manipulating letters and numbers (well, this is more programming than anything but Linux is a lot about that). Bash I’m discovering is great; I’m just getting into it and now have made things a good deal easier by learning how to copy and paste text from the command line via the Xorg server clipboard. Here is a couple commands that can do it with examples, following them are a couple bash scripts that make this easy as can beasy.

The Programs

xsel and xclip are command line programs that can redirect the contents of the Xorg server clipboard. The Xorg server has two clipboards: the common right-click > Copy, and one for the middle-mouse click. For those that don’t know of it yet, the middle-click clipboard allows quick copy and pasting without having to enter a menu or using Ctrl + v. Anytime you select text on the Xorg server there is a separate register that records this text, then clicking the middle-mouse button (sometimes called the mouse button three [usually done by clicking down the scroll wheel] will paste the text. The Xorg server defines the the middle-click clipboard as primary and the right-click clipboard as secondary.

xclip

Here are the basics of using xclip. xclip, I prefer over xsel because I have found that xsel can have problems pasting to java apps.

xclip can be used in a variety of ways. First, for example, it can be piped to:

echo "hi" | xclip -selection clipboard

This will copy to the standard clipboard. For abbreviation, you can use c instead of clipboard. You can specify primary or p here too to copy to the middle-mouse button, but isn’t necessary as this is the default for xclip.

echo "hello" | xclip

To direct a file to xclip the -in or -out options are needed:

xclip -in -selection c <filename>
xclip -out -selection c <filename>

Which will respectively put a file into the clipboard, and write to a file from the clipboard contents.

To make the process quicker, I’ve created a couple scripts to automate the tasks called cb-in and cb-out and can be used like a standard command:

cb-in pack 
 File pack copied to the clipboard

cb-in

cb-out

xsel

To copy to the context-menu clipboard:

xsel --clipboard < /etc/fstab

To copy a text to the middle mouse button clipboard:

xsel < /etc/fstab

xsel can be piped too:

echo "a-bit-of-text" | xsel -b
cat /etc/make.conf | xsel -b

To output directly to the terminal:

xsel --clipboard

And to redirect and append to a file:

xsel --clipboard > Baada-Boom.txt
xsel --clipboard >> ~/.Baada-Boom

cp2clip (xsel)

#!/bin/bash
# cp2clip - copy to the clipboard the contents of a file

# Program name from it's filename
prog=${0##*/}

# Text color variables
bldblu='\e[1;34m'         # blue
bldred='\e[1;31m'         # red
bldwht='\e[1;37m'         # white
txtbld=$(tput bold)       # bold
txtund=$(tput sgr 0 1)    # underline
txtrst='\e[0m'            # text reset
info=${bldwht}*${txtrst}
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}

filename=$@

# Display usage if full argument isn't given
if [[ -z $filename ]]; then
    echo " $prog <filename> - copy a file to the clipboard"
    exit
fi

# Check that file exists
if [[ ! -f $filename ]]; then
  echo -e "$warn File ${txtund}$filename${txtrst} doesn't exist"
  exit
fi

# Check user is not root (root doesn't have access to user Xorg server)
if [[ $(whoami) == root ]]; then
  echo -e "$warn Must be regular user to copy a file to the clipboard"
  exit
fi

# Copy file to clipboard, give feedback
xsel --clipboard < "$filename"
echo -e "$pass ${txtund}"${filename##*/}"${txtrst} copied to clipboard"

clippaste (xsel)

#!/bin/bash
# clippaste - Paste contents of clipboard to file in terminal.
# use 'xclip -out -selection primary' for middle click clipboard

# Program name from it's filename
prog=${0##*/}

# Text color variables
bldblu='\e[1;34m'         # blue
bldred='\e[1;31m'         # red
bldwht='\e[1;37m'         # white
txtbld=$(tput bold)       # bold
txtund=$(tput sgr 0 1)    # underline
txtrst='\e[0m'            # text reset
info=${bldwht}*${txtrst}
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}

filename=$@
pasteinfo="clipboard contents"

# usage if argument isn't given
if [[ -z $filename ]]; then
  echo "clippaste <filename> - paste contents of context-menu clipboard to file"
  exit
fi

# check if file exists, prompt to append or override, else create new
if [[ -f $filename ]]; then
  echo -en "$warn File ${txtund}$filename${txtrst} already exists - (${txtbld}e${txtrst})xit, (${txtbld}a${txtrst})ppend, (${txtbld}o${txtrst})verwrite: "
  read edit
  case "$edit" in
    [aA] )  xsel --clipboard >> $filename
            echo -e "$pass File ${txtund}$filename${txtrst} appended with clipboard contents"
            ;;
    [oO] )  xsel --clipboard > $filename
            echo -e "$pass File ${txtund}$filename${txtrst} overwrote with clipboard contents"
            ;;
    * )     exit
    esac; else
    xsel --clipboard >> $filename
    echo -e "$pass File ${txtund}"$filename"${txtrst} created with clipboard contents"
fi

Purge memory trick

Purge Memory

Linux does a good job when it comes to memory allocation. If memory isn’t being used or hasn’t been used for awhile it gets put into a cache where it can readily pulled. At times though this cache can become pretty big (especially for a program that has a memory leak). If a good number of programs are being used or if memory is limited then Linux will begin using hard disk swap which can really bog down performance. In these instances, it may help to purge the memory.

In the terminal type free -m to see memory usage. Flushing the filesystem buffers and to drop extra caches can be done by doing:

sudo sync
sudo echo 3 | sudo tee /proc/sys/vm/drop_caches

Look once more at free -m and memory usage should be improved. Freeing memory is most effective by shutting down whatever programs can be. To be really effective shutdown X server first.

This can be put in a script if you need to regularly do this:

Low processor gaming

Having a computer several years old doesn’t stop you from being able to play a good game on Linux. In fact, having an older computer is perfect with Linux – there are tons and tons of games! These games I’m running are on an iBook 300MHz processor and they all perform worthy.

Every several weeks I like to try a new game, lately I’ve got a chance to try three and I can say these are all excellent games.

Kobo Deluxe

Kobo Deluxe is a top down 2D shooter where we have to dodge enemy ships, evade bullets, and destroy space platforms. Kobo is a basic game but when dozens of bullets are flying your way and enemy pilots buzzing around you it is quite a challenge. Kobo Deluxe has 50 levels, only of which 24 have I got through after a good amount of play. There is quite a bit of braggart around for those who are able to finish it.

Light Burden Gaming

Ivan – Iter Vehemens ad Necem

“Iter Vehemens ad Necem” is latin for Violent Road to Death. Eck! Yes, my latin was a bit rusty too. Ivan looks to be one of the cooler games to play, I’ve only just installed it but it reminds me of my Ultima IV trudge through dungeons marathons. IVAN is a roguelike game with a graphical interface. No attack gremlin with level 14+ electrical mace :) here so it doen’st have a large learning scale. IVAN can be dived into without needing to read a manual. The objective of IVAN is to get the character to travel to a far off island by means of an underground dungeon to deliver a very important message (oh, and there happens to be a few monsters along the way.) IVAN is unique in rogue-likes and includes a detailed body part system and physical property system. Be careful not to die in IVAN as no magical potion will save you. Death = polly parrot. Ivan is a fun game and though I just started I think I’ll be playing it quite a bit. Unfortunately, I’m bogged by the bug that creates a Segmentation Fault on some PCs. Is it possible to play IVAN all the way thorough without saving?

Ivan pic

FYI, several fans have created a new forum for IVAN and a nice wiki that can be helpful.

OpenTyrian

Loitering the Linux Game Tome a few days ago, I gold mined OpenTyrian – right away my eyebrows raised. Tyrian was a blast DOS game on one of my earlier PC’s. Tyrian is a fast paced scrolling shooter that includes upgrades and challenging bosses. The port of the original Tyrian uses C and SDL and is nice and responsive though sound at time crackles on me.

OpenTyrian

Not many repositories have this game yet so it will need to be compiled from source. The original data files (also at the site) will need to be put in a “data” folder where the executable is.

I created a .desktop for OpenTyrian to show under the Gnome menu, but unfortunately the desktop launcher must look at the files relatively and thus can’t find the data files this way. The only way I could find a way around it was to create a script that cd‘d to the opentyrian folder and executed tyrian from there.

vim /usr/bin/opentyrian

#!/bin/bash
cd /home/user/opentyrian
./tyrian

To create the .desktop file:

vim ~/.local/share/applications/opentyrian.desktop

[Desktop Entry]
Name=OpenTyrian
Type=Application
Comment=OpenTyrian is a port of the classic DOS game Tyrian to C using SDL
Exec=opentyrian
TryExec=opentyrian
Icon=opentyrian
Categories=Game;ArcadeGame;

Here’s a few icons I extracted from the game for the .desktop file:

24×24
ot-24

32×32
ot-32

Original
origianl-ty

Usually it’s easiest to put them in the pixmaps directory:
sudo cp ~/Desktop/opentyrian-*.png /usr/share/pixmaps/opentyrian.png

In a few weeks, I’ll review my favorite Linux game: Wesnoth.

Old School Gaming and a Gnome Thought

— Old School Gaming and a Gnome Thought — The iBook is not a powerhouse of computing so I’ve been trying some old school games ( A transition I’m beginning to like ). Last Sunday I discussed a couple such games, Cave Story and Nazghul/Haxima, this week I’ve tried several more.

Bible Dave

Bible Dave is a pious Pitfall game. Dave must locate the lost bibles after a plane crash. Playing this reminded me of how much I like the old pitfall game ( I still wonder if it ever had an ending ). Three of the games I tried used SDL. I wasn’t sure if using SDL would create a performance issue, but for the most part no. Bible Dave was the expection. A 300 MHz processor and a 4MB video card isn’t enough for this game. Processors above this should be able to handle Bible Dave fine. Tecnoballz in not part of Gentoo’s portage and will need to be compiled on it’s own.

bible dave screen

Technoballz

Technoballz is another SDL game, a modern breakout clone. Tecnoballz runs pretty smoothly and is alot of fun to play. It features tons and tons of powerups, and the ability to buy powerups as the game progresses. Tecnoballz also in not part of portage and will need to be compiled.

tecnoballz screen

A couple bits seemed missing during compiling that I had to fix in order for it to run. From the source directory:


mkdir ~/.tlkgames
cp tecnoballz.conf ~/.tlkgames/
cd src/TecnoballZ/
sudo cp levels-data.xml /usr/local/share/tecnoballz/
sudo cp -r texts /usr/local/share/tecnoballz/

I also created a .desktop entry for it.

[Desktop Entry]
Version=1.0
Name=TecnoballZ
Type=Application
Comment=An SDL Breakout clone.
Exec=/usr/local/games/tecnoballz
TryExec=/usr/local/games/tecnoballz
Icon=tecnoballz.png
Categories=Game;ArcadeGame;

tkgames

tkgames is a collection of nice basic puzzle games – solitaire, spider, hangman, and a few others. Not really the action games like above but fun none-the-less. I particularly like poly puzzle.

tksolitaire screen

tkgames is not in portage and requires tk and tcl to run.

My thought for an addition to Gnome, what do you think?

How about apps the are minimized become iconized:

minimized thoughts

Hmm?

Comparision of Notetaking Applications

— Comparision of Notetaking Apps — From an earlier post I noted that tomboy (my favorite notetaking app) fails to run on my iBook. On my MacBook it was a livesaver but since I ditched that rag, I’ve missed tomboy alot. Good news is, I finally got tomboy to work. By reverting back 0.6.3 and mono-1.2.2.1 it is functional again; the bad news it that it’s horribly unusable.

We all like apps that when we get an idea the pen and paper is right there. Thats the way a note taking application needs to be. The incredible number of links to other notes (I have a lot of them) creates a terrible amount of dependencies. I can wait 5 seconds when I click the tomboy icon just for the notes to show. The large notes have become almost impossible to edit on my iBook. For instance just copying the information on one note took minutes to do.

Seconds going by can mean the deterioration of an idea. So my “OMG this is taking a dam week”, with Tomboy reached such a pitch I began just thinking of using gedit as my new notetaker.

Enter the Players

I began research if any alternates were available besides just using gedit. And thankfully there were.

Xpad

Xpad is a very simple notetaking app. Basically it’s sticky notes with gtk support and ability for simple formating (Bold, Italic….).

It does support multiple notes and it extremly lightweight. I copied my largest notes onto an xpad window and it handled them without a problem.

Xpad I would gladly use. The only thing putting me off would be having to manually transfer and reformat all dozens and dozens of notes.

Xpad screen

NoteCase

Notecase is an interesting application. Originally I was expecting something similiar to xpad but it has more features (though I feel overcompicatedly so). Notecase support hierachical note taking, meaning notes can be nested within notes – a nice feature. Notecase keeps track of notes in a seperate pane. The setup, though a bit eccentric, (notes are called nodes) is very nice. Support for linking to other notes and to weblinks are a plus.

Notecase is written in C++ and feels like it. Almost instant loads times and responsiveness its what I was looking for in a note taking app.

Notecase Screen

Zim

Zim is the most unique of the group. Labeled a notepad wiki is may be a bit more extravagant than I was looking for.

Zim is written in Gtk2-Perl and proposes to me leaner on resources then tomboy. It has support for all types of formatting, linking to other notes and webpages, heirarchical notes views, and understands wiki formatting.

Zim felt pretty responsive – alot better than tomboy, but not close to Notecase. The best thing about Zim is there turned out to be a conversion script for tomboy notes! Unfortunately the conversion script is a bit dated and would fail on some notes – it would convert them but the conversion process would stop. So I had to manually grep through my 1dlasdfaXXXYYY.notes and discover the offending ones independently and move them. The entire process took about 15 minutes so I shouldn’t gripe, the script did pretty good including indenting, bulleted lists, formatting and all links.

zim screen

Zim installation did unfortunatly take over the file:/// mime type so all folders I tried to open did so through vim. This was easy to fix by right clicking a folder and in “Open With” reselecting Nautilus.

Some tips for Zim:

• Tip: If you have a lot of topics like me, a general topic can be made and then others dropped on it. The easiest way to do this is to go into the folder where the notes are and create their own folders for them.
• Tip: Zim’s performance can really be improved performance by turning off spelling on large notes.
• Tip: Left-click on the Zim notification icon will display the most recent notes.
• Tip: Use “space *” to create a bullted list.

Conclusion

Tomboy is the king of the pack. It’s indent features, automatic linking, and save positions are key features not seen in alot of note taking apps. But the bell tolled…

Bye bye tomboy. You are awesome, but with lots of notes (even on the MacBook)… responsiveness is important. Notecase is my favorite of the pack, but not my overall choice. Because of the tremendous amount of conversion time it would require to convert all the notes to Notecase, I went with Zim. A good deal lighter and nearly all the features of tommy make Zim a good choice.