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

Sunday, January 23, 2011

Its That Of Vim Buffer Foliding Command Trick

:bn - goto next buffer
:bp - goto previous buffer
-PgUp - goto next buffer
-PgDn - goto next buffer

:tabe - open a tab before this one.
:tabc - close current tab
:tabo - close other tabs
gt - switches to next tab
gT - switch to previous tab

za - toggle current fold closed or open
zr - open one folding level
zm - close one folding level
zM - close all folds
zO - open all folds


zo

Thursday, January 20, 2011

Replacing Vim Special Characters

I wrote my first LaTeX macro today which makes some things much easier and prettier. As I was cleaning up my files I needed to substitue a string with the command \spath{}. Well vim did not put the "\" since its an special charater for the substitue function.
Five minutes of searching and I learned that to escape these special chars use the \\. So typing

%s#original-string#\\\spath{}#g

Made the change. Thank you internet machine!

Monday, December 27, 2010

An Old Vim Buffer Trick

When switching between buffers I usually forget that instead of typing :nextbuffer I can simply do :b where is the number of the next buffer. Or even better yet;

<CTRL>-^ to switch to the next buffer

To open the buffer in a new window in a new window <CTRL>-w followed by <CTRL>-^

With all those short cuts why remap the keys as Gmikeus shows us. butin matters of workflow there is no disputation. I do like Gmikeus' article which contains a lot of cool info.

I still find it easier to type :b in command mode. Well if I ever forget again I will look at either the buffer FAQ or vtk.org's useful commands list.

Hopefully now that I've written this the vim short cuts will ne'er be forgot.

Tuesday, December 21, 2010

A Flac to Mp3 Conversion Shell Script

I've had to do it enough times that I wrote a script yesterday to automate the conversions for me. There is a related one for converting aac files to mp3. Eventually I will just build one app that will convert any audio format to mp3.

#!/bin/bash 

numOfArgs=$#

DIR_NOT_FOUND=12
DIR_FOUND=0

FLAC_FILE_UNREADABLE=7
HELP_DISPLAY_VAL=5

NUM_OF_TAGS=6

#Audio File Metadata Tags
artist=""
track_num=""
song_title=""
genre=""
album=""
year=""

trash="/home/griot/.local/share/Trash/files"
log_file="flac_conversion.log"

declare -a tagList # Store the tags in this array

#=== FUNCTION ================================================================
# NAME: DisplayUsage
# DESCRIPTION: Prints help information and exits
# PARAMETERS:
# RETURNS: HELP_DISPLAY_VAL
#===============================================================================
DisplayUsage()
{
echo -e
echo -e "usage: $0 [directory]"
echo -e "Options:"
echo -e " -h or --help or displays options for $0"
exit $HELP_DISPLAY_VAL
}

# Statements dealing with calling the help function.
# If no args are given to fix_permisions then call DisplayUsage.
if [[ "$numOfArgs" -lt 1 ]]; then
DisplayUsage
fi

# If first arg is -h or --help call DisplayUsage.
if [[ "$1" == "-h" || "$1" == "--help" ]] ; then
DisplayUsage
fi

flacDirectory="$1"

#=== FUNCTION ================================================================
# NAME: FillsTagList
# DESCRIPTION: Fills the taglist array with a flac file's metadata
# PARAMETERS: Gets passed a flac file
# RETURNS: Should return an error if there is problem (not done yet)
#===============================================================================
FillsTagList ()
{
local ftc_flacFile="$1"
local count=0

    # Create a tmp file where the flac metadata is stored.
touch flac_tags.tmp
metaflac --export-tags-to=- "$ftc_flacFile" > flac_tags.tmp

BACKIFS=$IFS
IFS=$'\n'

exec 0<flac_tags.tmp

for line in $(cat flac_tags.tmp) ; do
tagList[$count]=${line##*=}
((count++))
done

    # Now that we are done delete the tmp file.
rm flac_tags.tmp
unset count
} # ---------- end of function FillsTagList ----------


#=== FUNCTION ================================================================
# NAME: GetSongMetadata
# DESCRIPTION: The data that we got from FillsTag is put into the tag
# variables.
# PARAMETERS: Uses global variables
# RETURNS: Later on will make it throw an error code if there are
# problems.
#===============================================================================
GetSongMetadata ()
{
local fileName="$1"
FillsTagList "$fileName"

artist=${tagList[0]}
song_title=${tagList[1]}
album=${tagList[2]}
year=${tagList[3]}
track_num=${tagList[4]}
genre=${tagList[5]}

} # ---------- end of function GetSongMetaData ----------


#=== FUNCTION ================================================================
# NAME: ConvertsToMp3
# DESCRIPTION: Sends a flac file to functions that get its metadata.
# When the metadata is acquired then convert the flac to an
# mp3 using a bitrate of 256.
# PARAMETERS: a flac file.
# RETURNS: FLAC_FILE_UNREADABLE
#===============================================================================
ConvertsToMp3 ()
{
local flacFile="$1"

    # We only want to convert files that are not copyprotected (DRM free).
if [ ! -r "$flacFile" ] ; then
echo -en "$flacFile is unreadable. ConvertsToMp3 error code "
echo -e "$FLAC_FILE_UNREADABLE, (copyprotected flac file)."
return $FLAC_FILE_UNREADABLE
else
        # Next call GetSongMetadata to fill the IDv3 tags.
GetSongMetadata "$flacFile"

flac -dc "$flacFile" | lame -b 192 -h --ta "$artist" --tn "$track_num"\
--tt "$song_title" --tl "$album" --tg "$genre" --ty "$year" \
--add-id3v2 - "${flacFile%*.flac}.mp3" &>>$log_file
fi

mv "$flacFile" "$trash"

} # ---------- end of function ConvertsToMp3 ----------


#=== FUNCTION ================================================================
# NAME: VerifyDirectory
# DESCRIPTION: Tests if the directory given as arg to script exists.
# PARAMETERS: $1 (directory to search for text files.)
# RETURNS: either DIR_FOUND or DIR_NOT_FOUND
#===============================================================================
VerifyDirectory ()
{
local targetDir="$1"
echo -e "$targetDir in VerifyDirectory"

if [ -e "$targetDir" ] ; then
return $DIR_FOUND
else
echo -e "$targetDir not found sending $DIR_NOT_FOUND back"
return $DIR_NOT_FOUND
fi
} # ---------- end of function VerifyDirectory ----------


VerifyDirectory "$flacDirectory"
dirTestResut=$?
#echo "$dirTestResut was the result of calling VerifyDirectory"

if [[ "$dirTestResut" -eq "$DIR_NOT_FOUND" ]] ; then
echo -e "Cannot find $flacDirectory"
exit $DIR_NOT_FOUND
else
cd "$flacDirectory"

for file in ./* ; do
       
       if [[ ${file##*.} = "flac" ]] ; then
           ConvertsToMp3 "$file"
       fi

   done
fi


Also I am finding out that the bashsupport plugin for vim is very cool.

Monday, April 6, 2009

LaTeX For Lazy People

When it comes to putting figures, equations, tables into Microsoft Word documents or OpenOffice Writer I find it to be a major pain in my head and ass. My head because I have to deal with equation editors, cutting and pasting, alignments and other formatting issues. Two weeks ago I was creating an exam for one of my data comm classes and getting very frustrated with the way that OpenOffice does numbering so I decided to try LaTeX since it seemed to not require any the use of menus, GUIs or other things that I am slowly having less and less patience for.

At first I used Lyx but that was limited in a number of ways, but by studying the source code it generated I started to get the hang of LaTeX
scripting. So in about a week I was just creating my tex documents in vim then converting them to postscript files. Now that I getting comfortable with LaTeX I wonder why I put off learning it for so many years.

It really does make writing easier for me, once I finish my typing lessons the only thing that will keep me from being more productive in my writing will be the time and effort it takes to express an idea well. And as usual that is the hardest part that only practiced discipline can bring.