vimgolf: Simple, Practical, and Common

Start file

*temp var1 0
*temp var2 "hi"
*temp var3 -1
*temp var4 42
*temp var5 "asdf"
*temp var6 0

Simple things we do all the time should be able to be done with very few keystrokes, but sometimes I find something I need to do makes me go, "There MUST be a better way."

This challenge is just a simple movement and entering text at a certain place.

End file

*temp var1 0
*temp var2 "hi"
*temp var3 -1
*temp var4 42
*temp var5 "asdf"
*temp var6 0
*temp var7 11

Simple things we do all the time should be able to be done with very few keystrokes, but sometimes I find something I need to do makes me go, "There MUST be a better way."

New text.

This challenge is just a simple movement and entering text at a certain place.


6GYp<C-A>w11<C-A>GONew t<C-N><C-N>.<CR><Esc>ZZ

Moving down

moving down to line var6
Go to line 6

Copying and pasting

yank line and put

Increase count

increase 6 to 7
move to next word
increase by count [count], in this case count = 11

Move to end

Go to end and Open a line above

Start typing

New t<C-N><C-N>.<CR>
this has the interesting effect of searching forward for the words beginning with t.

org-mode image location

I did not like the limited options offered by the orgmode plugin that came with nikola. It suggests using img-url: link which does not allow me to add ATTR_HTML or a CAPTION that comes nicely with org-export.

Let's add an image here:

cat/spider image

Figure 1: Image from cannon.js

This was added as

#+CAPTION: Image from cannon.js
#+ATTR_HTML: :alt cat/spider image :title Action! :align center :width 200

Now, we also create a symbolic link to files/images in order to point the final location of the images/ directory that should be added to files/ directory. The images/ final output location will be at / which is located two back references from the posts directory.

Adding a symbolic link in the source branch allows one to visit the link in org-mode, while at the same time point to the correct output directory.

cd $nikola_root
mkdir -p files/images/org-mode
# move cannon_js.png into this directory
ln -s $(pwd)/files/images ../images

git head and branches

origin is a local alias to a remote repository

  1. git push [origin|<URL>] <branch> pushes changes to a particular remote repository
  2. git remote
  3. git remote -v find out information about remote
  4. git remote show origin shows the origin
  5. git remote add origin <URL> sets an origin
  6. git remote rename origin <new_name> renames the origin

HEAD @ is a pointer to a branch

  1. Difference between carot and tilde

Image from paulboxley.

  1. The @ at-sign without leading branch/reference is the same as HEAD.


  1. git branch <branch name> create a branch
  2. git checkout <branch name> move HEAD to that branch
  3. git checkout -b <branch name> create branch and move HEAD to it
  4. git checkout master return to the master branch
  5. git merge <branch name> merges checked out branch (typically master) with another branch
  6. git branch -d <branch name> removes a branch
  7. git mergetool optional tool to visually merge
  8. git branch -a show all branches
  9. git branch -v see last commit
  10. git branch -vv see tracking information
  11. git branch --no-merged see the branches that have not merged with checked out branch (typically master)
  12. git diff origin/master..master show differences between local master and origin's master

Working with remote references

  1. git ls-remote
  2. git ls-remote origin master
  3. git fetch origin
  4. git remote add <remote_name>
  5. git fetch <remote_name>
  6. git push origin <branch_name> shortcut for git push origin <bn>:<bn>
  7. git merge origin/<bn> merges current working branch
  8. git checkout -b <bn> origin/<bn> create local branch <bn> based off origin/<bn>
  9. git checkout --track origin/<bn> shorthand for the above
  10. git checkout <bn> shorthand for the above if <bn> exists on origin
  11. git push origin --delete <bn> delete a remote branch


  1. git checkout -b <myworkingbranch> --track origin/master create a local branch
  2. ~git config –global alias.nb "!git checkout –track $(git config branch.$(git rev-parge –abbrev-ref HEAD).remote)/$(git rev-parse –abrev-ref HEAD) -b"~
  3. git nb foobar
  4. hub


  1. Set an alias for an alias command
git config --global alias.alias "config --get-regexp ^alias\."
  1. git alias : use the alias command
  2. Set an alias for alog
git config --global alias.alog "log --graph --oneline --all --decorate"


  1. Suppose you did the following git add -A, i.e. added all modifications
  2. git reset HEAD <file> you can unstage them individually
  3. git reset or unstage all the modifications

Undoing things

  1. fix human errors
  2. ~git commit -m "some typo"~ want to undo this commit
  3. git reset HEAD~ unstages your commit
  4. make corrections
  5. git add ... stage them
  6. git commit -c ORIG_HEAD allows you to edit the old commit message ORIG_HEAD is the original head
  7. git revert HEAD undoes a public commit
  8. nice read
  9. another stackoverflow

vimgolf: One number per line

Start file

- One number per line -

End file


Deleting the first two lines

  1. dj : d{motion} delete, j moves down one line
  2. 2D : D delete the character under the cursor until the end of line and [count]-1 more lines

Joining the lines

  1. JxJx : Join and delete the extra character twice
  2. 3J : Joins three lines together
  3. JJ : Joins two lines together
  4. 3gJ : Same as 2, but doesn't remove indent or spaces


  1. :s/,/\r/g : sed like replacement
  2. :s/,/<C-V><CR>/g<CR> : same as above but inserts a control character
  3. 0qqwr<CR>q9@q : goes to first char in line record typed characters into register 'q' wr: macro does a word movement and a char replacement 9@q : execute the contents of 'q' 9 times
  4. Iwr<CR><Esc>u9@. : similar to the one above but goes to current register
  5. V"=[<C-R><C-A>]<CR>p : V : visual line "= expression register [ ] list <C-R> cursor moves to the command-line <C-A> this normally adds to the number at the cursor, not sure what this C-A does p : put command <C-R><C-A> seems to get the word at the cursor of the selected text

Comments in vimgolf:

jdupont655: @chunleng: <C-R><C-A> is one of several ways to automatically insert some text on the command line, when this text is already under the cursor in the buffer.

Depending on type of text, you can hit different mappings:

  • <C-R><C-W> for a word,
  • <C-R><C-A> for a WORD,
  • <C-R><C-F> for a filepath,
  • <C-R><C-P> for an expanded filepath.

Here, when you hit <C-R><C-A>, your cursor is on one of the digits, so the WORD under the cursor is ——…2,…,29,. Besides, the number of minus signs in front of the number 2 is even (24; 1 at the end of the first line, then 23 on the second one). So, -—…2 evaluates to the positive number 2. Finally, you replace the line by putting the evaluation of an expression given through the expression register ("={expr}p). Here, the expression is a list ([2, …, 29]), and when you ask to put a list, Vim puts each of its item on a separate line.