My Profile Photo

Personal Webpage of David Duggins


Well, I was born on a normal day in July, 1981 and have been creating chaos ever since. Born in North Carolina, but raised in the aftermath of the Soviet Union, Kazakhstan, I have been messing around with computers nearly my entire life. I wrote my first program in assembly when I was 11. In my early teens I ran a BBS connected to Fidonet and started building a website for my band. In 1999 I was introduced to Linux, and it was love at first compile. I started my career in IT in the early 2000's doing IT for a Car Dealership in Charlotte NC. I wrote my first major web app in Cold Fusion (an ecom app) at that time. In 2006 I left Charlotte and moved down to Columbia where starting working as a developer, freelancer and consultant. Currently I am working as a freelance developer and DevOps consultant!!


Creating a Vim Plugin

Hey everybody! So years ago I made a plugin for the Mac only text editor, TextMate, that incorporated the api for Hipster Ipsum to include some sweet artisinal filler text. I would like to make a vim plugin that does the same thing. I’ve never made a vim plugin before, so this is a good lesson on how it is done. The first thing that I am doing is getting this to work as a function using vimscript in the vim.rc file.

So starting out, I am making a function called Hipster(). It is important to note that functions in vimscript must start with a capital letter.

function Hipster()

endfunction

Next we are going to pull the filler into a variable using the system command curl.

let hipster = system("curl -s 'https://hipsum.co/~&sentences=3'")

If you look at the api and run the command on the command line, you see it puts the filler text into an array. The returned text is

["Wayfarers shoreditch subway tile hot chicken. Etsy green juice gochujang brunch farm-to-table selvage. Activated charcoal fingerstache lomo beard."]

So, I really do not need the [] on the ends of the filler, so I am going to remove them before I drop the filler into the buffer.

To do this, we use the substitute() function as well as :put to dump the filler into the buffer.

:put =substitute(hipster, '[^a-zA-Z0-9]', '', '')

Finally, we map the function to a key:

map h :echo Hipster()<cr>

All together now!

function Hipster()

    let hipster = system("curl -s 'https://hipsum.co/api/?type=hipster-centric&sentences=3'")

    :put =substitute(hipster,'[^a-zA-Z0-9]', '', '')
    endfunction
    map h :echo Hipster()<cr>

So now h will dump 3 lines of artisinal filler into the buffer! This let's me drop in text in my pages when I do not have anything to put in yet!

Next up I will take this function and turn it into a plugin that can big distributed.

© 2024 David Duggins. All rights reserved.