Tuesday, Jan. 17, 2017

The Best Vim Configurations For Writers From My .vimrc

Written By:


December 9, 2016


Posted In:

The Best Vim Configurations For Writers From My .vimrc

I am a writer who uses Vim because of it’s unsurpassed text-editing efficiency [this statement to be justified . . . ]. But it is nevertheless a text editor tailored towards coders and needs some configuration to make it a highly efficient, comfortable and un-distracting writing environment like Microsoft Word, but still with all the power of Vim. This is why I started modifying my .vimrc, but seeing the huge productivity gains, I kept tweaking and adding to it until I now have Vim dotfiles totalling:

  • ~80 plugins
  • Over 1500 lines of code

It is a maximalist Vim configuration for writing in Pandoc Markdown. It was made for gVim on Windows and is pure vimscript. I expect that 99% of it at least will work on another OS like Linux or MacOSX.

(It should be noted that a lot of the code in this Vim config was borrowed from elsewhere. The most common place being Stack Exchange.)

I recently released my vim-writers-max-dotfiles on Github. These contain all the configurations that I will explain in this article, but the reaction of some members of the Reddit community was that it is more useful to write an article explaining things rather than expect people to sift through your code. So this is that article . . .

Why Vim For Writing?

For programming, Emacs may well pack more features (I have heard but don’t really know from experience), but for writing, Vim is the ultimate in my experience. It is faster—in performance and in its system of keyboard shortcuts.

I originally used Spacemacs for a few months but it hit a brick wall with the length of the lines in prose. Emacs’ performance just grinds to a halt when handling long lines, hence making it unusable on my machine for writing.

It has also been suggested before that Vim is an appropriate text-editor for writing because it’s command system follows a language with nouns, verbs and etc. This is fun to think about when you’re writing . . .

The Best Parts Of My Vim Configuration For Writing In Pandoc Markdown

Normal And Visual Mode Alt- Keys Mapped To Custom Commands

Alt-Arrow Keys Shift Text Up/Down/Left/Right

For shifting lines up and down with , , look no further than the plugin vim-move.

To complement vim-move, I mapped and to indent and de-indent respectively:

"Indent using arrow keys
    nnoremap <A-left> <<
    nnoremap <A-right> >>
    vnoremap <A-left> <gv
    vnoremap <A-right> >gv

I also have and mapped to shifting single characters. This uses vim-exchange:

"Shift horizontally
    nmap <A-h> cxlh.
    nmap <A-l> cxll.

Line Editing Commands

There are a lot of mappings that perform an action on the line above/below or on the current line but in an up/down direction. This is one of the most useful-on-a-daily-basis parts of my .vimrc:

"Line editing
    "Duplicate line
            nnoremap <A-d> "9yy"9p
            nnoremap <A-u> "9yy"9P
    "New line (without leaving normal mode)
            nnoremap <A-f> :normal o<CR>
            nnoremap <A-b> :normal O<CR>
    "Join lines
        "With above
            nnoremap K k0J
    "Split lines
            nnoremap <A-j> i<cr><esc>
        "Up (depends on Vim Exchange)
            nmap <A-k> a<CR><Esc>cxxk.
            imap <S-cr> <CR><Esc>cxxk.i

        "Delete line above (without leaving current line)
                nnoremap <A-BS> :normal! kdd<CR>
                nnoremap <A-Del> :normal! jdd<CR>
    "Repeat on line above/below
            nnoremap <A-s> <down>.
            nnoremap <A-w> <up>.

Make Paste Leave Cursor At The End Of The Pasted Text After Pasting

"Make paste go to end automatically
    nnoremap p p`]
    nnoremap P P`]

Select Last Pasted Text

An equivalent to gv (select last visual selection):

"Select last pasted text
    nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'

Switch To Buffer By Number, Delete Buffer By Number And Open A Most Recent Buffer By Number

E.g. You are in buffer 3 but want to switch to buffer 6: 6.

Or you want to delete it: d6.

    "Switch to buffer by number
        nnoremap 1<tab> :1b<CR>
        nnoremap 2<tab> :2b<CR>
        nnoremap 3<tab> :3b<CR>
        nnoremap 4<tab> :4b<CR>
        nnoremap 5<tab> :5b<CR>
        nnoremap 6<tab> :6b<CR>
        nnoremap 7<tab> :7b<CR>
        nnoremap 8<tab> :8b<CR>
        nnoremap 9<tab> :9b<CR>
        nnoremap 10<tab> :10b<CR>
        nnoremap 11<tab> :11b<CR>
        nnoremap 12<tab> :12b<CR>
        nnoremap 13<tab> :13b<CR>
        nnoremap 14<tab> :14b<CR>
        nnoremap 15<tab> :15b<CR>
        nnoremap 16<tab> :16b<CR>
        nnoremap 17<tab> :17b<CR>
        nnoremap 18<tab> :18b<CR>
        nnoremap 19<tab> :19b<CR>
        nnoremap 20<tab> :20b<CR>
        nnoremap 21<tab> :21b<CR>
        nnoremap 22<tab> :22b<CR>
        nnoremap 23<tab> :23b<CR>
        nnoremap 24<tab> :24b<CR>
        nnoremap 25<tab> :25b<CR>
        nnoremap 26<tab> :26b<CR>
        nnoremap 27<tab> :27b<CR>
        nnoremap 28<tab> :28b<CR>
        nnoremap 29<tab> :29b<CR>
        nnoremap 30<tab> :30b<CR>
    "Delete buffer by number
        nnoremap d1<tab> :bd1<CR>
        nnoremap d2<tab> :bd2<CR>
        nnoremap d3<tab> :bd3<CR>
        nnoremap d4<tab> :bd4<CR>
        nnoremap d5<tab> :bd5<CR>
        nnoremap d6<tab> :bd6<CR>
        nnoremap d7<tab> :bd7<CR>
        nnoremap d8<tab> :bd8<CR>
        nnoremap d9<tab> :bd9<CR>
        nnoremap d10<tab> :bd10<CR>
        nnoremap d11<tab> :bd11<CR>
        nnoremap d12<tab> :bd12<CR>
        nnoremap d13<tab> :bd13<CR>
        nnoremap d14<tab> :bd14<CR>
        nnoremap d15<tab> :bd15<CR>
        nnoremap d16<tab> :bd16<CR>
        nnoremap d17<tab> :bd17<CR>
        nnoremap d18<tab> :bd18<CR>
        nnoremap d19<tab> :bd19<CR>
        nnoremap d20<tab> :bd20<CR>
        nnoremap d21<tab> :bd21<CR>
        nnoremap d22<tab> :bd22<CR>
        nnoremap d23<tab> :bd23<CR>
        nnoremap d24<tab> :bd24<CR>
        nnoremap d25<tab> :bd25<CR>
        nnoremap d26<tab> :bd26<CR>
        nnoremap d27<tab> :bd27<CR>
        nnoremap d28<tab> :bd28<CR>
        nnoremap d29<tab> :bd29<CR>
        nnoremap d30<tab> :bd30<CR>
    "Open MRU by number
        nnoremap <leader>0 :e#0<CR>
        vnoremap <leader>0 :e#0<CR>
        nnoremap <leader>1 :e#1<CR>
        vnoremap <leader>1 :e#1<CR>
        nnoremap <leader>2 :e#2<CR>
        vnoremap <leader>2 :e#2<CR>
        nnoremap <leader>3 :e#3<CR>
        vnoremap <leader>3 :e#3<CR>
        nnoremap <leader>4 :e#4<CR>
        vnoremap <leader>4 :e#4<CR>
        nnoremap <leader>5 :e#5<CR>
        vnoremap <leader>5 :e#5<CR>
        nnoremap <leader>6 :e#6<CR>
        vnoremap <leader>6 :e#6<CR>
        nnoremap <leader>7 :e#7<CR>
        vnoremap <leader>7 :e#7<CR>
        nnoremap <leader>8 :e#8<CR>
        vnoremap <leader>8 :e#8<CR>
        nnoremap <leader>9 :e#9<CR>
        vnoremap <leader>9 :e#9<CR>

Shuffle Lines Psuedo-randomly

Shuffle selected lines using an algorithm that uses date-times to simulate randomness. Great for writing SEO tags:

"Shuffle lines psuedo-randomly
        vnoremap <leader>gr :s/^/\=reltimestr(reltime())[-2:] . " "<cr> gv :sor n <cr> gv :s/^\S* // <cr>:noh<cr>

More Undo Points In Insert Mode

"Finer undo control. More undo point creation
    "Before deleting text
        function! s:start_delete(key)
            let l:result = a:key
            if !s:deleting
                let l:result = "\<C-G>u".l:result
            let s:deleting = 1
            return l:result

        function! s:check_undo_break(char)
            if s:deleting
                let s:deleting = 0
                call feedkeys("\<BS>\<C-G>u".a:char, 'n')

        augroup smartundo
            autocmd InsertEnter * let s:deleting = 0
            autocmd InsertCharPre * call s:check_undo_break(v:char)
        augroup END

        inoremap <expr> <BS> <SID>start_delete("\<BS>")
        inoremap <expr> <C-W> <SID>start_delete("\<C-W>")
        inoremap <expr> <C-U> <SID>start_delete("\<C-U>")

    "Around punctuation and other characters
        inoremap . .<c-g>u
        inoremap ! !<c-g>u
        inoremap ? ?<c-g>u
        inoremap , ,<c-g>u
        inoremap ; ;<c-g>u
        inoremap : :<c-g>u
        inoremap \| \|<c-g>u
        inoremap <CR> <C-G>u<CR>

Make The Tilde (~) Cycle Through Title Case As Well As Lowercase And Uppercase

"Twiddle case
    function! TwiddleCase(str)
        if a:str ==# toupper(a:str)
            let result = tolower(a:str)
        elseif a:str ==# tolower(a:str)
            let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
            let result = toupper(a:str)
            return result
    vnoremap ~ y:call setreg('', TwiddleCase(@"), getregtype(''))<CR>gv""Pgv

Ex-Commands For Deleting Leading And Trailing Whitespace

"Delete whitespace commands
    "Trailing whitespace
    command Deltrail :let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>
        "Leading whitespace
    command Dellead %le
        "Reduce multiple blank lines in a row into singular ones
    command Onelines :10,20g/^/ mo 10

Mappings That Act On The Entire Buffer

The key is the first in several key sequences that operate on entire buffers or windows.

I use ‘yank entire’ buffer multiple times a day.

        "Backspace leader
            "Buffer + window
                nnoremap <BS><BS> :bd<cr>
            "All buffers + windows
                nnoremap <BS>a :%bd<cr>
            "All other buffers
                nnoremap <BS>o :Bonly<cr>
                nnoremap <BS>O :BOnly<cr>
            "Delete file in buffer
                nnoremap <BS>df :! call "C:\Users\Benjamin Glitsos\Box Sync\Vim\Other\external programs\deleteJS.bat" "%:p"
                nnoremap <BS>DF :call delete(expand('%')) \| bdelete!
            "Current window
                nnoremap <BS>c <C-w>c
            "All windows but the current
                nnoremap <BS>O <C-w>o
            "Close tab
                nnoremap <BS>T :tabclose<cr>
            "Select all
                nmap <BS>= ggVG
                vmap <BS>= ggVG
            "Yank all
                nmap <BS>- ggVGy
                vmap <BS>- ggVGy
            "Delete all
                nmap <BS>dd ggVGd
                vmap <BS>dd ggVGd
            "Cut all
                nmap <BS>0 ggVG0
                vmap <BS>0 ggVG0
            "Substitute all with paste
                nmap <BS>s ggVGgs
                vmap <BS>s ggVGgs

Uses the vim-bbye plugin to delete buffers but not windows:

        "Buffer, not window
            nnoremap <BS>d :Bdelete<CR>
        "All buffers, no windows
            nnoremap <BS>D :bufdo :Bdelete<CR>

Cycle Through Buffers And Windows Easily

"Cycle through buffers
    nnoremap <Tab> :bnext<CR>
    nnoremap <S-Tab> :bprevious<CR>

"Cycle through windows
    nnoremap <C-Tab> <C-w>w

One of the key differences between Vim defaults and Microsoft Word is that Vim navigates through actual lines (one paragraph = one line) whereas Word navigates through display lines (one paragraph = several ‘lines’ if it wraps). Prose lines are much longer than lines of code, hence the difference in functionality.

In my Vim configuration, I have mapped hjkl and the arrow keys to do different things in different modes so that you can have both of these alternatives:

  • Normal/Visual mode:
  • hjkl: display line navigation
  • Arrow keys: actual line navigation
  • Insert mode:
  • Arrow keys: actual line navigation

Here’s the code:

" Actual vs display line navigation
    set whichwrap+=<,>,h,l,[,]

    " hjkl
        nnoremap j gj
        nnoremap k gk
        vnoremap j gj
        vnoremap k gk

    " Arrow
        inoremap <Up> <C-o>gk
        inoremap <Down> <C-o>gj

    " S-Arrow
        inoremap <S-Up> <C-o><Up>
        inoremap <S-Down> <C-o><Down>

    " Home/End
        nnoremap  <S-Home> g<Home>
        nnoremap  <S-End>  g<End>
        vnoremap  <S-Home> g<Home>
        vnoremap  <S-End>  g<End>
        inoremap <S-Home> <C-o>g<Home>
        inoremap <S-End>  <C-o>g<End>

Function Keys

These are mapped to use your left hand to give your hands a break from typing from time-to-time. I know as a writer that typing continuously can make your hands weary:

    noremap <F1> <PageDown>zz
    inoremap <F1> <PageDown>zz
    vnoremap <F1> <PageDown>zz
    noremap <F2> <PageUp>zz
    inoremap <F2> <PageUp>zz
    vnoremap <F2> <PageUp>zz

"Spell check
    nnoremap <F3> [s
    vnoremap <F3> [s
    inoremap <F3> <Esc>[s
    nnoremap <F4> ]s
    vnoremap <F4> ]s
    inoremap <F4> <Esc>]s

PageUp, PageDown With Your Left

Indenting & De-Indenting Takes Only A Single Keypress Of >, <

I don’t know why this isn’t the default . . .

"Indent simplification
    nnoremap > >>
    nnoremap < <<
    vnoremap > >gv
    vnoremap < <gv

Convert Filetype With Pandoc Mappings

These mappings call Pandoc from the Windows command line and specify which filetype to convert to and other options. They can’t possibly include every option, they’re just my most used presets.

They’re under s like a ‘save as’ menu:

"Windows command line
        nmap <leader>sh :! pandoc "%:t" -s -o "%:r.html"<CR>
        nmap <leader>sH :! pandoc "%:t" -s -t html5 -o "%:r_html5.html"<CR>
        nmap <leader>sd :! pandoc "%:t" -s -o "%:r.docx"<CR>
        nmap <leader>smm :! pandoc "%:t" -s -t markdown+abbreviations -o "%:r.md"<CR>
        nmap <leader>sms :! pandoc "%:t" -s -t markdown_strict -o "%:r_mdStrict.md"<CR>
        nmap <leader>smh :! pandoc "%:t" -s -f markdown+abbreviations -o "%:r.html"<CR>
        nmap <leader>st :! pandoc "%:t" -s -o "%:r.txt"<CR>
        nmap <leader>sp :! pandoc "%:t" -s -o "%:r.pdf"<CR>
        nmap <leader>sl :! pandoc "%:t" -s -o "%:r.tex"<CR>
        nmap <leader>se :! pandoc "%:t" -s -o "%:r.epub"<CR>
        nmap <leader>sE :! pandoc "%:t" -s -t epub3 -o "%:r_epub3.epub"<CR>
        nmap <leader>so :! pandoc "%:t" -s -o "%:r.odt"<CR>
        nmap <leader>sr :! pandoc "%:t" -s -o "%:r.rtf"<CR>
        nmap <leader>sid :! pandoc "%:t" -s -t dzslides -o "%:r.html"<CR>
        nmap <leader>sir :! pandoc "%:t" -s -t revealjs -o "%:r.html"<CR>
        nmap <leader>sib :! pandoc "%:t" -s -t beamer -o "%:r.pdf"<CR>

Unite Most Recent Files, Directories, Bookmarks And New File/Directory Is Very Accessible

My ‘main’ Unite menu (Unite is an infinitely useful plugin) is the one that stores the files that I want to open quickly. It is mapped to (because my leader is mapped to `):

nnoremap <leader><Space> :silent <C-u>Unite -buffer-name=UniteMain -direction=botright file_mru directory_mru bookmark file/new directory/new<cr><C-l>
vnoremap <leader><Space> :silent <C-u>Unite -buffer-name=UniteMain -direction=botright file_mru bookmark directory_mru bookmark file/new directory/new<cr><C-l>

It also opens at startup. This is a way to eliminate having to use vim-startify:

"Unite start screen
    autocmd VimEnter * silent Unite -buffer-name=UniteMain -no-split -direction=botright buffer file_mru bookmark directory_mru bookmark file/new directory/new

Unconditional Paste With Non-Obnoxious Mappings

UnconditionalPaste is a plugin that lets you decide which kind of paste you want to do: linewise, blockwise, characterwise, indented, even deliminated and several other powerful options. Each kind of paste of which there are numerous is mapped to a different key. It is one of the plugin that I use the most out of them all.

However . . . the default mappings are all over the shop. They map under c, b and countless more. So instead, I put them all under p and p to keep it contained:

"Unconditional Paste
        nmap <Leader>p'b <Plug>UnconditionalPasteCommaSingleQuoteBefore
        nmap <Leader>p'a <Plug>UnconditionalPasteCommaSingleQuoteAfter
        nmap <Leader>P" <Plug>UnconditionalPasteCommaDoubleQuoteBefore
        nmap <Leader>p" <Plug>UnconditionalPasteCommaDoubleQuoteAfter

        nmap <leader>pc <Plug>UnconditionalPasteCharAfter
        nmap <leader>pC <Plug>UnconditionalPasteCharBefore
        nmap <leader>pl <Plug>UnconditionalPasteLineAfter
        nmap <leader>pL <Plug>UnconditionalPasteLineBefore
        nmap <leader>pb <Plug>UnconditionalPasteBlockAfter
        nmap <leader>pB <Plug>UnconditionalPasteBlockBefore
        nmap <Leader>pI <Plug>UnconditionalPasteIndentedBefore
        nmap <Leader>pi <Plug>UnconditionalPasteIndentedAfter
        nmap <Leader>pb; <Plug>UnconditionalPasteCommentedBefore
        nmap <Leader>p; <Plug>UnconditionalPasteCommentedAfter
        nmap <Leader>P<Space> <Plug>UnconditionalPasteSpacedBefore
        nmap <Leader>p<Space> <Plug>UnconditionalPasteSpacedAfter
        nmap <Leader>pD <Plug>UnconditionalPasteDelimitedBefore
        nmap <Leader>pd <Plug>UnconditionalPasteDelimitedAfter
        nmap <Leader>pQ <Plug>UnconditionalPasteQueriedBefore
        nmap <Leader>pq <Plug>UnconditionalPasteQueriedAfter
        nmap <Leader>prD <Plug>UnconditionalPasteRecallDelimitedBefore
        nmap <Leader>prD <Plug>UnconditionalPasteRecallDelimitedAfter
        nmap <Leader>prQ <Plug>UnconditionalPasteRecallQueriedBefore
        nmap <Leader>prQ <Plug>UnconditionalPasteRecallQueriedAfter
        nmap <Leader>pk, <Plug>UnconditionalPasteCommaAfter
        nmap <Leader>p, <Plug>UnconditionalPasteCommaBefore
        nmap <leader>pk> <Plug>UnconditionalPasteMoreIndentBefore
        nmap <leader>p> <Plug>UnconditionalPasteMoreIndentAfter
        nmap <leader>pk< <Plug>UnconditionalPasteLessIndentBefore
        nmap <leader>p< <Plug>UnconditionalPasteLessIndentAfter
        nmap <leader>pks <Plug>UnconditionalPasteShiftedBefore
        nmap <leader>ps <Plug>UnconditionalPasteShiftedAfter
        nmap <leader>pkj <Plug>UnconditionalPasteJaggedBefore
        nmap <leader>pj <Plug>UnconditionalPasteJaggedAfter
        nmap <Leader>Pku <Plug>UnconditionalPasteUnjoinBefore
        nmap <Leader>pu <Plug>UnconditionalPasteUnjoinAfter
        nmap <Leader>Prbu <Plug>UnconditionalPasteRecallUnjoinBefore
        nmap <Leader>pru <Plug>UnconditionalPasteRecallUnjoinAfter
        nmap <leader>pk+ <plug>UnconditionalPastePlusBefore
        nmap <leader>p+ <plug>UnconditionalPastePlusAfter
        nmap <Leader>pbg+ <Plug>UnconditionalPasteGPlusBefore
        nmap <Leader>pg+ <Plug>UnconditionalPasteGPlusAfter

        imap <C-G>pc <Plug>UnconditionalPasteChar
        imap <C-G>p, <Plug>UnconditionalPasteComma
        imap <C-G>pq <Plug>UnconditionalPasteQueried
        imap <C-G>prq <Plug>UnconditionalPasteRecallQueried
        imap <C-G>pu <Plug>UnconditionalPasteUnjoin
        imap <C-G>pru <Plug>UnconditionalPasteRecallUnjoin

        cmap <C-G>pc <Plug>UnconditionalPasteChar
        cmap <C-G>p, <Plug>UnconditionalPasteComma
        cmap <C-G>pq <Plug>UnconditionalPasteQueried
        cmap <C-G>prq <Plug>UnconditionalPasteRecallQueried
        cmap <C-G>pu <Plug>UnconditionalPasteUnjoin
        cmap <C-G>pru <Plug>UnconditionalPasteRecallUnjoin

My Plugins

I decided that after spamming you with this much code already, that it wouldn’t be worse if I just showed you all my plugins. There’s a lot of these, like 70+, but believe-it-or-not I’m actually quite conservative with which plugins I install. All of these are used frequently:

Plug 'altercation/vim-colors-solarized'
Plug 'easymotion/vim-easymotion'
    Plug 'haya14busa/vim-easyoperator-phrase'
    Plug 'haya14busa/vim-easyoperator-line'
Plug 'haya14busa/incsearch.vim'
    Plug 'osyo-manga/vim-anzu'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'junegunn/limelight.vim'
Plug 'kana/vim-textobj-user'
    Plug 'reedes/vim-textobj-quote'
    Plug 'reedes/vim-textobj-sentence'
    Plug 'jceb/vim-textobj-uri'
    Plug 'kana/vim-textobj-entire'
    Plug 'kana/vim-textobj-datetime'
    Plug 'kana/vim-textobj-line'
    Plug 'saaguero/vim-textobj-pastedtext'
    Plug 'paulhybryant/vim-textobj-path'
    Plug 'jceb/vim-textobj-uri'
    Plug 'Julian/vim-textobj-variable-segment'
    Plug 'tkhren/vim-textobj-numeral'
    Plug 'kana/vim-textobj-indent'
    Plug 'glts/vim-textobj-indblock'
    Plug 'coderifous/textobj-word-column.vim'
    Plug 'machakann/vim-textobj-delimited'
    Plug 'glts/vim-textobj-comment'
    Plug 'whatyouhide/vim-textobj-xmlattr'
    Plug 'kana/vim-textobj-lastpat'
Plug 'Shougo/unite.vim'
    Plug 'kopischke/unite-spell-suggest'
    Plug 'Shougo/neomru.vim'
    Plug 'Shougo/unite-outline'
    Plug 'tsukkee/unite-tag'
Plug 'vim-scripts/DrawIt'
Plug 'othree/html5.vim'
Plug 'JulesWang/css.vim'
Plug 'junegunn/goyo.vim'
Plug 'mbbill/undotree'
Plug 'ervandew/supertab'
Plug 'svermeulen/vim-easyclip'
Plug 'matze/vim-move'
Plug 'vim-scripts/UnconditionalPaste'
Plug 'tpope/vim-speeddating'
Plug 'tpope/vim-abolish'
Plug 'arecarn/selection.vim'
    Plug 'arecarn/crunch.vim'
Plug 'terryma/vim-expand-region'
Plug 'kshenoy/vim-signature'
Plug 'justinmk/vim-sneak'
Plug 'MarcWeber/vim-addon-mw-utils'
    Plug 'tomtom/tlib_vim'
    Plug 'garbas/vim-snipmate'
        Plug 'honza/vim-snippets'
Plug 'xolox/vim-misc'
    Plug 'xolox/vim-session'
    Plug 'xolox/vim-shell'
    Plug 'xolox/vim-easytags'
Plug 'vim-scripts/tinymode.vim'
Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'bling/vim-bufferline'
Plug 'jdelkins/vim-correction'
Plug 'tommcdo/vim-exchange'
Plug 'ReekenX/vim-rename2'
Plug 'chrisbra/NrrwRgn'
Plug 'chrisbra/unicode.vim'
Plug 'tpope/vim-capslock'
Plug 'vim-pandoc/vim-pandoc'
    Plug 'vim-pandoc/vim-pandoc-syntax'
    Plug 'vim-pandoc/vim-pandoc-after'
        Plug 'dhruvasagar/vim-table-mode'
Plug 'KabbAmine/lazyList.vim'
Plug 'gregsexton/MatchTag'
Plug 'tpope/vim-commentary'
Plug 'schickling/vim-bufonly'
Plug 'BohrShaw/vim-url-shortener'
Plug 'moll/vim-bbye'
Plug 'jaxbot/selective-undo.vim'
Plug 'vim-scripts/SyntaxMotion.vim'
Plug 'jeetsukumaran/vim-indentwise'

Insert Mode Alt- Normal Mappings

In insert mode in gVim, Alt is mapped to various special characters that are somewhat convenient but they can be inserted with the digraph key anyway. I found it more useful to map insert mode Alt modified keys to their normal mode equivalents.

E.g. → undo

This may be the normal functionality undo other (non-gVim) Vim GUIs.

Here is the file of insert mode mappings (it’s quite long): imapAltMapping.vim.

Automatic Inserting Of Apostrophes For English Language Contractions

For ‘contrations’ like ‘isn’t’, it is a common oversight to forget the apostrophe. Microsoft Word inserts them automatically, but Vim doesn’t because it is tailored towards coders. Hence I created this file to add this feature to Vim. It uses vim-abolish and it’s list of contractions is very comprehensive:


Automatic Non-Breaking Space Character After Titles/Honorifics

This file of code automatically inserts a non-breaking space after each ‘honorific’ you type e.g. ‘Mr’, ‘Mrs’. Likewise it is very comprehensive and fail-safe.

To use this code, put this in your .vimrc, then source the file:

"Abbreviations without space afterwards
    func Eatchar(pat)
        let c = nr2char(getchar(0))
        return (c =~ a:pat) ? '' : c


Keys To Insert Formatting Into Pandoc Markdown And HTML

Markdown And HTML Headings

I find that the most efficient mappings to insert headings are [number]`:

" Add headings
    " nmap
        nmap <localleader>1 <plug>Addboln#<Space><Esc>
        nmap <localleader>2 <plug>Addboln##<Space><Esc>
        nmap <localleader>3 <plug>Addboln###<Space><Esc>
        nmap <localleader>4 <plug>Addboln####<Space><Esc>
        nmap <localleader>5 <plug>Addboln#####<Space><Esc>
        nmap <localleader>6 <plug>Addboln######<Space><Esc>
        nmap <localleader>7 <plug>Addboln#######<Space><Esc>
        nmap <localleader>8 <plug>Addboln########<Space><Esc>
        nmap <localleader>9 <plug>Addboln#########<Space><Esc>
    " vmap
        vmap <localleader>1 <plug>Addbolv#<Space><Esc>
        vmap <localleader>2 <plug>Addbolv##<Space><Esc>
        vmap <localleader>3 <plug>Addbolv###<Space><Esc>
        vmap <localleader>4 <plug>Addbolv####<Space><Esc>
        vmap <localleader>5 <plug>Addbolv#####<Space><Esc>
        vmap <localleader>6 <plug>Addbolv######<Space><Esc>
        vmap <localleader>7 <plug>Addbolv#######<Space><Esc>
        vmap <localleader>8 <plug>Addbolv########<Space><Esc>
        vmap <localleader>9 <plug>Addbolv#########<Space><Esc>
    nmap <localleader>1 yss<h1>
    vmap <localleader>1 S<h1>
    nmap <localleader>2 yss<h2>
    vmap <localleader>2 S<h2>
    nmap <localleader>3 yss<h3>
    vmap <localleader>3 S<h3>
    nmap <localleader>4 yss<h4>
    vmap <localleader>4 S<h4>
    nmap <localleader>5 yss<h5>
    vmap <localleader>5 S<h5>
    nmap <localleader>6 yss<h6>
    vmap <localleader>6 S<h6>
    nmap <localleader>7 yss<h7>
    vmap <localleader>7 S<h7>
    nmap <localleader>8 yss<h8>
    vmap <localleader>8 S<h8>
    nmap <localleader>9 yss<h9>
    vmap <localleader>9 S<h9>

Other Formatting

Pandoc Markdown
"Pandoc remap
    nmap <buffer> <localleader>~ <Plug>(pandoc-keyboard-toggle-strikeout)
    vmap <buffer> <localleader>~ <Plug>(pandoc-keyboard-toggle-strikeout)

"Add hyperlink
    nmap <localleader>k ysiw]%a()<Esc>h
    xmap <localleader>k Hi[<Esc>La]()<Esc>
    vmap <localleader>k S]%a()<Esc>h

"Add image
    nmap <localleader>m ysiw]i!<Esc>%a()<Esc>h
    xmap <localleader>m Hi![<Esc>La]()<Esc>
    vmap <localleader>m S]i!<Esc>l%a()<Esc>h

"Add blockquotes
    nmap <localleader>q <plug>Addboln><Space><Esc>
    vmap <localleader>q <plug>Addbolv><Space><Esc>

"Jump between headings
    nnoremap <A-]> :normal ]]<CR>
    nnoremap <A-[> :normal [[<CR>


    nmap <localleader>k ysiw<a href="">
    vmap <localleader>k S<a href="">

Changing The Search Highlighting To A Something Less Obscuring And In-Your-Face

The default search highlighting is a garish yellow block that demands that you get rid of it immediately after using otherwise you will be driven insane. Here is an alternative that instead just turns the text yellow, not highlights its background (pictured at top):

"Search highlighting
    hi Search guibg=yellow guifg=#002b36

Pandoc Markdown Syntax Conceal Characters

I changed the default conceal characters in the vim-pandoc plugin (this is the plugin that this entire vim config is based on). Many of the default conceal characters were:

  • Not compatible with Source Code Pro. The font doesn’t contain the Unicode glyph.
  • Interfering. Some were latin letters, and this interferes with reading, so they were replaced. Also ones that were other characters that are too common.

Here’s the code:

"Pandoc Syntax
    let g:pandoc#syntax#conceal#cchar_overrides = {"image": "□" , "super" : "⁰" , "sub" : "₀" , "codelang" : "「" , "codeend" : "」" , "newline" : "↙" , "definition" : "≡" , "strike" : "¬"}

Automatic Bullet Points

Like in Microsoft Word, when you’re in a bullet point and you press Enter`, another one is created automatically. Putting this code in the after/plugin directory implements the same in Vim using its automatic commenting system. You can define any Unicode symbol you want as a bullet/comment.

    set comments-=b:#
    set comments+=n:*,n:>,n:\|,n:+,n:-,n:•,n:○,n:■,n:❖,n:➢,n:(@),n:#.,b:→,n:□,n:☐,n:✓,n:☑,n:☒,n:✔
    set formatoptions=tcroqln

Final Remarks

So that’s all the most interesting and unique parts of my comprehensive, quite maximalist Vim dotfiles. For the real McCoy, check out the vim-writers-max-dotfiles here. I hope that my hard work in creating these dotfiles makes you as productive and focussed in writing as it did me.

Share This Article

Related News

When ‘Evolution’ Is The Wrong Explanation (by a Darwinist)
70 Self-Improvement Points From How To Win Friends, The Art Of War And Others
The 4 Things That Google And Social Media Actually Should Censor

About Author

Leave A Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>