Browse files

Differentiate between full and partial writing mode. Add write_auto.

  • Loading branch information...
1 parent 831d12b commit ef7d23db1129d45872913c233416b26497b5d7fa @Soares committed Oct 4, 2012
Showing with 104 additions and 23 deletions.
  1. +28 −6 autoload/write.vim
  2. +56 −14 doc/write.txt
  3. +20 −3 plugin/write.vim
@@ -5,9 +5,16 @@ let g:write#autoloaded = 1
" Sets the buffer as writer-friendly.
-function! write#On()
- let b:writing=1
- setlocal spell wrap linebreak display+=lastline nonu nornu nolist
+" Args:
+" {string} bang Whether or not to force full writing mode.
+function! write#On(bang)
+ setlocal spell wrap display+=lastline nolist linebreak
+ if a:bang != '' || &tw == 0
+ setlocal tw=0 nonu nornu
+ let b:writing=2
+ else
+ let b:writing=1
+ endif
noremap <buffer> <silent> k gk
noremap <buffer> <silent> j gj
@@ -16,19 +23,34 @@ endfunction
" Unsets the buffer as writer-friendly.
" Will only undo changes that write.vim made.
function! write#Off()
+ if b:writing == 2
+ setlocal tw< nonu< nornu<
+ endif
+ setlocal spell< wrap< display< list< linebreak<
let b:writing=0
- setlocal spell< wrap< linebreak< display< nu< rnu< list<
silent! unmap <buffer> k
silent! unmap <buffer> j
" Toggles write mode.
-function! write#Toggle()
+" Args:
+" {string} bang Whether or not to force full writing mode.
+function! write#Toggle(bang)
if exists('b:writing') && b:writing > 0
call write#Off()
- call write#On()
+ call write#On(bang)
+ endif
+" Toggles writing mode only if writing has never been set for this buffer
+" Args:
+" {string} bang Whether or not to force full writing mode.
+function! write#Reenter(bang)
+ if !exists('b:writing')
+ call write#On(a:bang)
@@ -1,45 +1,87 @@
*write.txt* Get your author on.
+*write* *write.vim*
Author: Nate Soares <>
License: Same terms as Vim itself (see |license|)
+CONTENTS *write-contents*
+ 1. Introduction................................|write-intro|
+ 2. Configuration...............................|write-config|
+ 3. Commands....................................|write-commands|
+ 4. Extras......................................|write-extras|
+ 5. About.......................................|write-about|
Vim writing mode, for writing non-code text (books, novels, etc.).
+CONFIGURATION *write-commands*
+ *g:write_auto*
+A list of filetypes that should automatically go into write mode. If the
+filetype string ends with a '!', that filetype will automatically go into full
+write mode. For example: >
+ let g:write_auto=['markdown', 'help', 'text!']
+Will set up autocommands on markdown, help, and text files to put them into
+write mode, and text files will be forced into full write mode regardless of
+|textwidth| settings.
COMMANDS *write-commands*
- *:WriteOn*
-Turn writing mode on. This does the following:
-- soft wrap lines
-- make j & k navigate screenwise, not linewise
-- turn spelling on
-- turn line numbers off
-As well as a few other tweaks that make writing easier.
+ *:WriteOn[!]*
+Turn writing mode on. There are two writing mode styles: full and partial.
+Partial writing mode turns on spell checking and a number of enhancements that
+make writing mode more comfortable (line wrapping, intuitive cursor movement
+over long lines, some display tweaks for long paragraphs, etc.).
+Full writing mode sets all of the same enhancements as partial mode and also
+turns off line numbers and hard text wrapping.
+Write.vim tries to autodetect your writing style by checking the |textwidth|
+setting. If you |textwidth| is nonzero then Write.vim assumes that you want to
+hard wrap your lines and goes into partial writing mode. To force full writing
+mode, use >
+ :WriteOn!
+If you want |textwidth| automatically managed by filetype, check out the
+|longlines| plugin at <>.
-Turn writing mode off. Resets all values changed by :WriteOn (which are
-changed locally) to the global values.
+Turn writing mode off. Resets all values changed by :WriteOn.
- *:Write*
-Toggles writing mode.
+NOTE: Writing mode makes all setting changes locally. When turning writing
+mode off, settings will be reset to their global values. If you have local
+settings that interfere with writer (i.e. you have ':set nospell' and
+':setlocal spell') then write mode will clobber those local settings.
+ *:Write[!]*
+Toggles writing mode. The bang, if given, will be passed to |:WriteOn|
EXTRAS *write-extras*
- *write#Writing*
-True if writing mode is on. Useful for statusline flags. We recommend adding
-something like >
+Status Line *write#Writing*
+ *write-statusline*
+Returns non-zero if writing mode is on. Useful for statusline flags. We
+recommend adding something like >
set statusline+=%#ModeMsg#
set statusline+=%{write#Writing()?'[W]':''}
set statusline+=%*
to your statusline.
+Mappings *write-mappings*
+Write.vim does not provide mappings for you. You'll have to set them yourself.
+We suggest something along the lines of: >
+ noremap <leader>W :Write<CR>
ABOUT *write-about*
@@ -5,11 +5,28 @@
" License: The same as vim itself. (See |license|)
" GetLatestVimScripts: 4249 1 :AutoInstall:
-if exists("g:loaded_write") || &cp || v:version < 700
+if exists('g:loaded_write') || &cp || v:version < 700
let g:loaded_write = 1
-command! WriteOn call write#On()
+command! -bang WriteOn call write#On('<bang>')
command! WriteOff call write#Off()
-command! Write call write#Toggle()
+command! -bang Write call write#Toggle('<bang>')
+if !exists('g:write_auto')
+ let g:write_auto = []
+if len(g:write_auto) > 0
+ augroup write
+ autocmd!
+ for s:ft in g:write_auto
+ let s:bang = s:ft =~# '!$' ? "'!'" : "''"
+ let s:ft = substitute(s:ft, '!$', '', '')
+ exe 'autocmd FileType '.s:ft.' call write#Reenter('.s:bang.')'
+ endfor
+ augroup end

0 comments on commit ef7d23d

Please sign in to comment.