guest@dotshare [~/groups/vim/rc] $ ls Basic-word-processor-in-Vim/ | cat

Basic word processor in Vim (raw, dl)

rabbit386 Mar 01, 2021 (vim/rc)
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"    // / /Rabbit386's
"   // /         
"  // / //\/\ /\ /
" <>\/ // / //   \ <><><>  v.0.0.2

"Default stuff from Fedora Vim package (vim-minimal, maybe?)
set ignorecase
set smartcase
if has('mouse')
	set mouse=a
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"   // // //        /                     /   
"  // // //        /                      
" // // // /\ /\/\/  /\ /\/\ / // /\ /\ //\/\/
" \/  \/   \//  \/  /\//  \/ \ \ \\ \\ // /\/ <><><>
"                  /                      \/
" This is a function that gives Vim the features of a word processor-- 
" smart wordwrap, some movement remapping to make the wrapping more bearable
" in long paragraphs and adds spell hilighting, then calls an outliner that
" detects markdown section headers. When combined with a markdown-HTML
" converter and a script which concatenates headers and footers on to the
" output, plus CSS and whatever else, this can actually be a very usable 
" word processor for web stuff or even general document writing. Normally
" I wouldn't go to such extremes but there are literally no word processors
" with vi keybindings that still work--abiword hasn't offered the feature in
" a long time and I don't think the plugin for libreoffice does it either. 
" Plus, I much prefer text editors. On my old hardware word processors can 
" lag behind my typing speed.  
" I don't remember who I got the basics of this from but I made some tweaks
" and incorporated the voom outliner plugin and markdown hilighting. Really,
" this is a very simple piece of configuration and not original in the
" slightest, but it's pretty huge for me since I write formatted text all the
" time and vim has a great workflow.

:command Q :qall  " makes q quit everything, while "quit" quits just one individual window. Makes voom play nice
cabbrev q Q 

func! WordProcessor()
  " movement changes
  map j gj
  map k gk
  " formatting text
  setlocal formatoptions=1
  setlocal noexpandtab
  setlocal wrap
  setlocal linebreak
  " spelling and thesaurus--toggle spelling on off.
  setlocal spell spelllang=en_us
  set thesaurus+=/home/faust/.vim/spell/thesaurus.txt
  " make autocompletion search the thesaurus
  set complete+=s
  " show markdown hiliting--if your terminal doesn't have a good italic font
  " set this will look like sh;t. I have URXVT with fixed as the main and
  " Source Code Pro for italics. It was the first passable combo I came up
  " with.
  set syntax=markdown
  Voom markdown
endfu
com! WP call WordProcessor()

" A little thing to turn off spellcheck in WP mode 
func! Off()
  setlocal spell&
endfu
com! Off call Off()

"Turn on markdown hiliting
func! MD()
  setlocal syntax=markdown
endfu
com! MD call MD()

"Turn off markdown hiliting
func! MO()
  setlocal syntax=
endfu
com! MO call MO()

" This is the same function as WP minus spell and syntax hilighting and the outliner.
" I think of this as being kind of like 'wordpad' to WP's 'microsoft word'
" so I call it 'RT' for 'rich text.'

func! RTProcessor()
  " movement changes
  map j gj
  map k gk
  " formatting text
  setlocal formatoptions=1
  setlocal noexpandtab
  setlocal wrap
  setlocal linebreak
  " Thesaurus. I need to find a better plain text thesaurus file. The one I'm
  " using doesn't have a lot of words. But when editing a large English file
  " it will give you autocomplete from words within the file as well. If your
  " file is more than about one or two thousand words this will be
  " surprisingly helpful.
  set thesaurus+=~/.vim/spell/thesaurus.txt 
  " complete+=s makes autocompletion search the thesaurus
  set complete+=s
endfu
com! RT call RTProcessor()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"     // /
"    // /     /   /   //
"   // /     /       /
"  //\ /// //\ //\/\///\/\/ /\
" //  \\/\//\/// /\/// /\/\\ 
"       \/             \/ 
" Next a little binding to dehilight search results when pressing enter in
" command mode
nnoremap <silent><CR> :nohlsearch<CR><CR>
" Add qq (nonexistent in english) as a keybinding for "Escape" to get out of
" insert mode more easily. Some people use jj... actually, I'm starting to use 
" ^[ more---the same way I've started actually using ^H for backspace etc. It
" strikes me as profoundly odd that we're still using enhanced emulations of
" an ancient text terminal made by a company that no longer exists, but as
" long as these shortcuts are here, might as well use them, right?
imap qq <Esc>
"an earlier version of this file had me actually trying to invent keybindings
"to use ^h/^j/^k/^l to move around _in insert mode_. I didn't get vim I guess
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"     //=====            // /
"    //                 // //
"   //              /  // /
"  //--        /\/\/  // ///\/\ /\/
" //========= / /\/, <>\/// / //  \

CLICK TO VIEW

x

Notes

Rabbit’s .vimrc

This is a very simple .vimrc for the purposes of using the word-processing abilities of vim to their full potential. Vim might never be a WYSIWYG text editor, but with its builtin spellcheck and intelligent word-wrapping, it can work together with an “invisible” markup language like markdown incredibly well.

It requires the Voom plugin for showing an outline of the document’s sections in a separate pane, and as written it highlights markdown (incl. italicizing anything between underscores) and tells Voom to look for markdown headings to build its dynamic outline, but you could easily change it to a different markup style.

I hate most of the other minimalist markup languages but I suppose someone with some fortitude could use LaTeX for this purpose. Or you may have less of a problem with restructured text than I do.

My actual production vimrc has some other stuff in it that is only relevant to my personal workflow. I have my documents for word processing in individual folders with special stub HTML files, such that I can have a script to generate an HTML fragment from the source document (using either pandoc or discount, can’t remember which), which is plugged in between a header and footer file to form a complete HTML document. Furthermore I have a special alias set up that lets me open both the markdown source and the associated CSS sheet in separate tabs with one command, letting me access the formatting transparently in the same instamce of Vim.

Within Vim itself I have macros to invoke the script that builds the HTML document, and to open said document with Firefox as a background process. If you want to imitate this workflow, you should find these simple enough to implement, but drop me a line for any pointers.

Sorry if my ascii art looks like ass. It was drafted in “fixed” at 8 point size. I know, I’m trash.

Also some little keybindings for killing search highlighting when it needs to go away (will reappear when you need it) and for getting out of insert/replace mode without stretching your pinky (my variation on an old classic.)

BUGS:

  • On your system, when the terminal tries to render italics it may look like ass.
  • TMUX is technically its own terminal emulator, just one that runs inside another terminal, and it does not by default support changing fonts in the way that the host terminal needs to display italics
  • Looks like ass, but gets the job done (isn’t that the unspoken second part of *Nix philosophy?)

TODO:

  • draft nicer-looking syntax files for markdown I guess. Has someone already done this?