Code.RogerHub » vim https://rogerhub.com/~r/code.rogerhub The programming blog at RogerHub Fri, 27 Mar 2015 23:04:04 +0000 en-US hourly 1 http://wordpress.org/?v=4.2.2 Writing essays in VIM and Latex https://rogerhub.com/~r/code.rogerhub/infrastructure/562/writing-essays-in-vim-and-latex/ https://rogerhub.com/~r/code.rogerhub/infrastructure/562/writing-essays-in-vim-and-latex/#comments Fri, 27 Mar 2015 23:03:45 +0000 https://rogerhub.com/~r/code.rogerhub/?p=562 I’m only taking one humanities course this semester, so I don’t have that many essays to write. But for the few assignments in that course, I’m planning to use VIM and Latex to write my essays. I have Pages.app installed on my laptop, and I already use Google Docs for stuff, but I’m still more comfortable writing in VIM, even if I’m not writing code.

Smart quotes

Latex handles smart quotes like you’d expect it to. If there are single-quotes or double-quotes in the text section of your document, they’ll get turned into left and right quotes in the final PDF.

Spell checking

I just use VIM’s built-in spell-checking feature. Make sure you use it with MacVIm/GVIM, or else it looks terrible. Apparently there’s a way to bring up the correction suggestions list too, if you look for it.

Rich formatting

You can do bold and italics and lists in Latex. I like it even better than the WYSIWYG editors, since you can do line manipulation and fancy macro stuff in VIM too.

Instant feedback

You can mix inotify-tools and your Latex compiler to get you basically instant feedback. Every time you save the file, you can get it to re-compile your Latex and Preview.app will reload it. I’m just sharing my home folder through VirtualBox shared folders (configured in Vagrant), so I can work with files directly on the VM.

]]>
https://rogerhub.com/~r/code.rogerhub/infrastructure/562/writing-essays-in-vim-and-latex/feed/ 1
Comma mode for vim https://rogerhub.com/~r/code.rogerhub/vim/555/comma-mode-for-vim/ https://rogerhub.com/~r/code.rogerhub/vim/555/comma-mode-for-vim/#comments Sun, 05 Oct 2014 09:45:48 +0000 https://rogerhub.com/~r/code.rogerhub/?p=555 Most keyboards have a Control and Meta key. Macs also have the Command key. Even with all the combinations of Control and Meta and Command with the letters and numbers, it’s sometimes hard to have enough space for keyboard shortcuts that don’t conflict and override each other. This is especially important in vim, where keyboard shortcuts are everything. Most of the good ones are taken already.

My keybindings

I adapted an idea from tinymode.vim and created another key modifier: the comma. Here are some of the keybindings I’ve set:

  • ,v creates a vertical split
  • ,t opens a new tab
  • ,1 toggles line wrapping
  • ,2 opens NERDTree
  • ,0 enables spellcheck and textwidth
  • ,q quits the current buffer
  • ,b opens CtrlP in buffer mode
  • ,c opens the cd prompt
  • ,f opens the filetype prompt
  • ,U toggles line numbers

The comma works just like Control or Meta. You can hold it down and press multiple keyboard shortcuts. For example, multiple q’s can be chained to close multiple buffers in succession. Or t and v can be chained to create a new 2-pane tab.

Configuration

These six lines form the core of comma mode:

nmap , :set timeoutlen=86400000<CR><SID>ldr
vmap , :set timeoutlen=86400000<CR><SID>ldr
nn <script> <SID>ldr, <SID>ldr
vn <script> <SID>ldr, <SID>ldr
nmap <SID>ldr :set timeoutlen=1000<CR>
vmap <SID>ldr :set timeoutlen=1000<CR>

Pressing the comma key will 1) set the key combination delay to an absurdly long time, and 2) set up the <SID>ldr keyword for the following comma command. Vim provides <SID> as a script-local unique identifier to help you avoid naming conflicts.

Chainable commands

Once comma mode is set up, you can add chainable commands. These commands can be chained together with other comma commands in succession.

nn <script> <SID>ldr1 :set wrap!<CR><SID>ldr
vn <script> <SID>ldr1 :set wrap!<CR><SID>ldr

Everything after the first <SID>ldr is the comma keybinding. In this case, just the number 1. An arbitrary command is run, and then the line ends with <SID>ldr to set up chaining for the next command.

Non-chainable commands

You can also add non-chainable commands. These are useful for comma shortcuts that open prompts, which you would never use with other comma shortcuts.

nn <script> <SID>ldrc :set timeoutlen=1000<CR>:cd 
vn <script> <SID>ldrc :set timeoutlen=1000<CR>:cd

There’s an invisible space at the end of these two lines, so the prompt is ready to accept a path. Non-chainable commands reset the timeoutlen to a default 1000. This is the same behavior as the null binding (the last two lines of the Configuration section), which runs when you run a non-existent comma command, or press ESC in comma mode.

Conclusion

Comma mode has been the #1 most productivity-boosting featured I’ve added to vim. Mapping semicolon to colon is a start, but it only takes :q from 4 keystrokes to 3 keystrokes (including the Enter key). With comma mode, this is now just 2 keystrokes — just the way keyboard shortcuts should be.

]]>
https://rogerhub.com/~r/code.rogerhub/vim/555/comma-mode-for-vim/feed/ 2