---
title: 'Writing WordPress posts in Vim'
url: 'https://stevenjaycohen.com/journal/writing-wordpress-posts-in-vim'
markdown: 'https://stevenjaycohen.com/journal/writing-wordpress-posts-in-vim.md'
date: '2023-02-18'
description: 'Because I have been keeping a journal electronically for so long, I standardized on plain text files. After all, just about everything can read plain text (txt) files. At one of my first programming jobs, I was then required to use Vim, and once I got the hang of it, it became my prefered way to de…'
taxonomy:
  category:
    - Journal
  tag:
    - design
    - PostADay
    - software
    - thoughts
    - vim
    - writing
---

# Writing WordPress posts in Vim

## [Writing WordPress posts in Vim](https://stevenjaycohen.com/journal/writing-wordpress-posts-in-vim)

    18th Feb 2023   [design](https://stevenjaycohen.com/tag:design#body-wrapper) [PostADay](https://stevenjaycohen.com/tag:PostADay#body-wrapper) [software](https://stevenjaycohen.com/tag:software#body-wrapper) [thoughts](https://stevenjaycohen.com/tag:thoughts#body-wrapper) [vim](https://stevenjaycohen.com/tag:vim#body-wrapper) [writing](https://stevenjaycohen.com/tag:writing#body-wrapper)  

Because I have been keeping a journal electronically for so long, I standardized on plain text files. After all, just about everything can read plain text (txt) files.

At one of my first programming jobs, I was then required to use [Vim](https://www.vim.org/), and once I got the hang of it, it became my prefered way to deal with plain text whenever I could. And, once I found [VimWiki](https://vimwiki.github.io/), and moved my text based journal over to that, I have been using it ever since.

Recently, I found out that the company that hosts some websites for me has [WP-CLI](https://wp-cli.org/) (the WordPress Command Line Interface) installed by default. And, that started me wondering if there were a simple way to go from a local journal entry that I quite liked, to a draft of a post in WordPress while avoiding the usual copy/paste route. This is what I figured out…

## The Code

First, I added this to my .vimrc file

```
"Make new WordPress draft from VimWiki entry

function! PublishPost()
   :terminal ++close scp -Cpr % yoursite.com:www/new-post.txt
   :terminal ++close wget -qO- https://yoursite.com/vim.php?wp
endfunction

map <silent><leader>P <esc>:call PublishPost()<cr> 
```

```

The function PublishPost() uses [SCP (Secure Copy Protocol)](https://en.wikipedia.org/wiki/Secure_copy_protocol) to copy the currently open file (using Vim notation, the % symbol) and copy it to the server as new-post.txt.

Once that completes successfully, a php file on the server is pinged with a $\_GET variable named wp.

This function is called when I hit LEADER+SHIFT+P (for Publish Post).

Now, onto the vim.php file…

```

```
```
<?php if (isset($_GET['wp'])) {
    $out = shell_exec('wp post create ./new-post.txt');
    $del = shell_exec('rm new-post.txt');
  }
??>
```
```

This checks if $\_GET has a variable named “wp” set (Yes, you should set it to a specific value to increase security 🙂 ).

It then runs WP-CLI with a simple post create command without any other modifiers.

Finally, it deletes the new-post.txt file from the server.

Was this worth the trouble?
---------------------------

At first, I wondered that too. After all, this is just replacing the following workflow:

1. Select All in a Journal Entry
2. Copy Journal Entry
3. Open WordPress
4. Open New Post
5. Paste Journal Entry
6. Save Draft of Entry
7. Close WordPress

But, what I am finding, is that having a single command to issue when I feel that I have written something worth sharing, that creates the draft, hidden in the background, ready for me to deal with the next time that I log into the website, seems to short circuit my inner critic.

This way, I have divided the work of creation (which happens distraction-free within Vim) and the work of editing (which happens later on within WordPress). The two thought processes are quite different from each other. And, I find that dividing the two the best I can, helps me to do both of them better.

```

 [ Previous Post](https://stevenjaycohen.com/journal/tasting-the-words) [Next Post ](https://stevenjaycohen.com/journal/approaching-an-ai-inflection-point)

---

## Navigation

- Parent: [My Journal](https://stevenjaycohen.com/journal.md)
- Previous: [Approaching an AI Inflection Point](https://stevenjaycohen.com/journal/approaching-an-ai-inflection-point.md)
- Next: [tasting the words](https://stevenjaycohen.com/journal/tasting-the-words.md)
