Publishing a Blog in Vim with Vimpress

February 29, 2008 at 5:12 pm (Linux)

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 http://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.

Permalink 10 Comments

Ad-Blocker Not Required – Hosts File

February 28, 2008 at 4:35 pm (Gentoo, Linux)

Ad-Blocker Not Required - Hosts FileOne of the most used and handy features about Firefox is it Ad-blocker extension. As people and companies recklessly graffiti our Internet like a NASCAR Ford, it can be a strain on the eye as well as some pretty long download times. Ad-blocker does a good job but one can also use the hosts file.

Linux, Windows and Macs all have support for a hosts file. A hosts file is a list of resolved DNS addresses (IPs). By substituting the local loopback IP (127.0.0.1) to known spammers addresses the hosts file can be used to filter out said domains.

Luckily for us, we don’t have to enter lists of spammers addresses (there are a few) but that a group of users are already involved doing it. The hosts files project have created a list of known spammer and advertising IP’s to enter into the hosts file. For Linux users the process is very simple to add these IP’s to the hosts file. Look to the end of the page to the section “When is the file updated“. Here is a Linux script that can update the hosts file automagically. The dos2unix application will need to be installed to convert the text properly. After running the scipt, putting the script in /etc/cron.weekly does pretty well for me.

Support the project is encouraged. Put new IP of spammers in the hosts file and upload the hosts files to the project.

A Couple Important Notes: Keep in mind that if the computer being used is pretty quick not a lot of difference is going to be seen blocking advertising. Also keep in mind that some our favorite sites need support from advertising.

Come back tomorrow I’ll talk more about Vim and the plugin I use to post to the blog.

Permalink 5 Comments

Vim Setup – Tuning Vim To The Environment

February 27, 2008 at 1:46 pm (Linux)

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 

Permalink 6 Comments

How I Learned to Stop Killing Myself and Learn Vim

February 26, 2008 at 10:29 pm (Linux)


When I first started Linux, I fired up “Text Editor” and almost collapsed. What the hell was that? I like many Windows and Mac users, hit this bird on the first flyover of Linux. Now I could have used Open Office but I’m an old dog, and if I’m gonna be taught new tricks they better be damn good ones.

So I needed to bold a word in gedit, and couldn’t find a bold button in the title bar. “I can’t even bold what the !@#$.” This was my first foray in real text editor.

Why Not Bold

Once I was forced to use gedit, and hence to transfer the document to another computer and another application, I began to love how simple it was. It just worked. There were a few bolds and underlines to put in and that was it. Having manually converted documents like AppleWorks previously, I didn’t mind doing this.

Vim is Alot of Talk

People on the forums talked alot using Vim, and I thought “that archaic editor”. I’ve heard of it in the early days of computing and just decided to stay away from vi(vim). As the more I got involved in Linux and needing to do more complex tasks, the more my searchs found people talking about it. So, I gave Vim a try thinking that this will be a ten minute exercise before I frustratingly jack hammered the keyboard. What has occurred is a love affair of sorts (don’t get excited) and I haven’t looked back much since.

How to Start

I began by the Gentoo Wiki which has a nice basic tutorial for Vim. There is, as well, vimtutor that is installed with Vim, which I didn’t know at the time – oh well. I learned the basics (and they can be learned in about an hour) then I became free to begin typing.

Customizing

Of all the details I’ve read of vim, the most I’ve read over is how people customize Vim to their particular needs. The Vim homepage contains thousands of scripts to vary and add to the uses of the editor.

Vim isn’t everything but it tells me whats most important about writing – letters. In fact I’m typing this post on Vim and even posting from it.

How I Learned to Stop Killing Myself and Learn Vim

Tomorrow, I’ll talk about customizing Vim and a few basic tips to setting it up.

Permalink 6 Comments

Gentoo xterm-256color off by default?

February 25, 2008 at 9:55 pm (Gentoo)

Gentoo xterm-256color off by default?Update: It is advisable not to perform this update. For compatibility purposes with other terminal emulators best to leave this setting to eight bit.

I had an intuition that some off the colors in the terminal seemed a bit off. I’m new to this terminal dealie, and aftering discovering that a lot of vim themes looked poor I found out vim was using 8 bit color. I found the vim setting to fix this but it turns out that x term has been set to 8 bit color all along!

Astounded! Flabergasted! Yes I was. This isn’t an Atari!

Anyways, I tracked down a well-read post in the forums that discussed this and now got it set to 256 colors. To fix this:

Test the terminals color bit depth:

tput colors

Now load the 256 palatte into xterm

export TERM=xterm-256color

To keep settings for 256 colors export the xterm 256 color to ~/.bashrc

Is this the Gentoo default? Am I missing anything here that can relate to concerns of bugs?

Permalink 4 Comments

Quick Tip – Gnome Color Chooser – Color Chart

February 25, 2008 at 1:38 pm (Gnome, Linux)

Gnome Color Chooser - Color ChartI wrote about configuring the Gnome Color Chooser last week and got my fixing eyes and fingers more into it. The degree to how customizable the Gnome desktop is really incredible if not a bit overbearing. So, I’ve made a reference chart too help me in the future to quicken the process.

For customizing, I use freakcode’s Si Pack here – customizations may vary depending on the theme used.

gnome-color-chooser-color-chart.png

Matched Colors

To carry the theme, these are the colors I matched.

In the Normal section:

I matched the hover fg to Entry hover fg.

In the Entry Fields section:

I matched selected bg to Normal selected fg, selected fg and alt.
selected fg to Normal hover bg.

The alt selected bg matches Normal hover fg.

And the disabled bg also matches the Normal disabled bg.

Sidenote

I’m testing vimpress to write and publish this post. I’ve been studying
this week on vim and this is all very very interesting.

Permalink Leave a Comment

Links Saturday

February 23, 2008 at 1:50 pm (Linux)

Links SaturdayLinks Saturday

A couple Internet parkways I found interesting this week:

Added:

I’ve been looking for a good alarm clock application since using Linux and just decided to use cron. I just discovered “Alarm Clock” – a well done python application that includes display notifications. I’ve added it the the Alarm Clock Page.

Permalink Leave a Comment

Command Line to Clipboard

February 22, 2008 at 12:18 pm (Linux)

HeaderIt’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 alot 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 to/from the xorg server clipboard from the terminal. Here’s a couple commands that can do it and a couple bash scripts that make it easier.

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’ or ‘Edit > Copy’ command, 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 serperate register that records this text, then clicking the mouse button three (usually 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

Xclip I prefer to xsel because I have found that xsel can have problems pasting to java apps.

You can use xclip in a variety of ways. 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 third mouse button, but isn’t necessary as this is the default for xclip.

echo "hello" | xclip

To direct a file to xclip you use the ‘-in’ or ‘-out’ options:

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 ‘cp2clip’ and ‘clippaste’ and can be used like a standard command:

cp2clip <filename>
clippaste <filename>

cp2clip

#!/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
xclip -in -selection c < "$filename"
echo -e "$pass ${txtund}"${filename##*/}"${txtrst} copied to clipboard"

clippaste

#!/bin/bash
# clippaste - Paste contents of clipboard to file in terminal.

# 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] )  xclip -out -selection clipboard >> $filename
            echo -e "$pass File ${txtund}$filename${txtrst} appended with clipboard contents"
            ;;
    [oO] )  xclip -out -selection clipboard > $filename
            echo -e "$pass File ${txtund}$filename${txtrst} overwrote with clipboard contents"
            ;;
    * )     exit
    esac; else
    xclip -out -selection clipboard >> $filename
    echo -e "$pass File ${txtund}"$filename"${txtrst} created with clipboard contents"
fi

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

Permalink 8 Comments

Obligations – Kernel Upgrade

February 21, 2008 at 12:47 pm (Linux)

Obligations - Kernel UpgradeI upgraded the kernel to version 2.6.24 yesterday which always causes me considerable grief. For those that haven’t been in earshot, a serious exploit in the kernels since 2.6.17 was discovered in the past week that all users should upgrade from. I’ve been so entirely happy with my last kernel that I haven’t saw the need to update for sometime… But as I was saying – this makes me nervous. You see, I’m without a BootCD and I never could get LiveUSB to work so if it screws up, I’m screwed – dead ibook. Thank goodness this wasn’t the case and the upgrade was flawless. 2.6.24 feels pretty light and I haven’t noticed any issues with it – so I’ll keep my fingers crossed. 

Permalink Leave a Comment

Purge Memory

February 20, 2008 at 7:20 pm (Linux)

Purge MemoryLinux 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.

Note: This tip is entirely safe but sed authour in not accountable if computer sees Pigs on a Wing.

In the terminal type free -m to see memory usage. Now flush the filesystem buffers and drop extra caches.

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

Look once more 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.

Original Tip: Howto: Clear filesystem memory cache 

Permalink 4 Comments

Post Updates – Epiphany History Limit

February 19, 2008 at 2:48 pm (Linux)

Post Update - Epiphany and NetworkManagerEpiphany is still my number one choice as a browser: light, sleek, and a damn good, not too complicated interface. The only Epiphany hitch was that large histories, and believe me I have a few, would bog down the location bar as it searched for matches. Not so big a deal when your SATA drive can chuck out I/O but blaaahhh on older drives. Epiphany doesn’t have any visible settings to control history but history entries can be limited – but, the big Captcha, it needs to be compiled from source. I >>’d it to the Epiphany post.

I also was able to update the NetworkManager info for all the good people out there… Thank You. 

Permalink Leave a Comment

Next page »