preservim / vim-pencil

Rethinking Vim as a tool for writing
Other
1.58k stars 39 forks source link

Possible plugin conflict preventing initial wrap in hard line mode? #29

Closed courtyardz closed 9 years ago

courtyardz commented 9 years ago

When toggling between hard/soft modes on a file with long lines (I've commented out any vim-pencil autocmds for the sake of debugging) :SoftPencil works as expected (setting wrap w/o cutting off words, remapping nav keys, etc.), while :HardPencil, though it sets nowrap and textwidth=80 correctly, does not create hard line breaks upon mode switch. The lines simply run off the screen until an edit is attempted, at which point the line is finally auto formatted to the appropriate textwidth.

I can't tell 100% from the documentation -- isn't vim-pencil supposed to create and undo hard line breaks upon mode switches? If so, what would be interfering with this initial wrap (my .vimrc and a list of plugins are below)? Note also that, after hard line breaks have been created via auto format on a given line, calling :SoftPencil does not rejoin these lines into the original line, now softly wrapped, it merely soft wraps the lines that have not yet been touched by autoformat.

If not, where would you recommend I insert this behavior into my vim-pencil version (just some execute "normal gggqG" commands, etc.)? I just thought this was the whole point of vim-pencil!

Hopefully this helps other users get set-up with vim-pencil, as I have spent some time trying to figure out where my setup might have gone wrong.

Current plugins

It is unlikely that conflicts are here... I leave the setting of formatoptions, etc. to vim-pencil, though in vim-pencil section below I have experimented (to no avail) with setting, e.g., textwidth to some non-zero value manually.

set nocompatible

let mapleader=" "

execute pathogen#infect()

"mappings ===============================================
"removes key functionality when learning new maps
":inoremap <esc> <nop>
":inoremap jk <esc>
:nnoremap <leader>ev :vsplit $MYVIMRC<cr>
:nnoremap <leader>sv :source $MYVIMRC<cr>
:nnoremap <leader>el :vsplit #<cr>
:nnoremap <leader>et :vsplit ~/Dropbox/Notes/todo.taskpaper<cr>
"quotes around word
":nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
"python specific commenting
":autocmd FileType python     nnoremap <buffer> <localleader>c I#<esc>
":autocmd FileType python     :iabbrev <buffer> iff if:<left>

"operator mappings
:onoremap p i(
:onoremap in( :<c-u>normal! f(vi(<cr>
:onoremap il( :<c-u>normal! F)vi(<cr>

"markdown mappings
"change header if marked with equal signs
":onoremap ih :<c-u>execute "normal! ?^==\\+$\r:nohlsearch\rkvg_"<cr>

"snippets
:iabbrev eml    sdfasdfddfsfd@gmail.com
:iabbrev zml    sadfasasdfds@gmail.com
"=============================================================

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

set history=1000    " keep 50 lines of command line history
set showcmd     " display incomplete commands
set incsearch       " do incremental searching
"set autochdir      " 

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

filetype plugin indent on

" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\   exe "normal! g`\"" |
\ endif

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
          \ | wincmd p | diffthis
endif

":set spell
":set spelllang=en,de

set backupdir=~/.vimbackups,/tmp

set pastetoggle=<F1>
:nnoremap <F5> "=strftime("%c")<CR>P
:inoremap <F5> <C-R>=strftime("%c")<CR>

"from theunixschool.com
map #2 :wq!

"prevents sync discrepancies by checking for changes to the files of
"open buffers
au CursorHold * checktime

let g:session_autosave = 'no'

"will auto wrap text 
"set formatoptions+=a 

"see for navigating by sentences etc.
":help text-objects

"VIM-PENCIL========================================================= 
"let g:pencil#wrapModeDefault = 'hard'   " default is 'hard'

"set number
"set nopaste
"set tw=80 
"set nowrap
"set fo+=tca

"let g:pencil#textwidth = 74

augroup pencil
    "autocmd!
    "autocmd FileType markdown,mkd,md call pencil#init({'wrap': 'hard'})
    "autocmd FileType text,txt  call
    "pencil#init({'wrap': 'hard'}) had to manually add a macro to correctly
    "hard wrap existing lines don't kno what's pencil's deal is autocmd
    "FileType text,txt,markdown,mkd,md :HardPencil
    "autocmd FileType markdown,mkd,md  execute "normal magggqG`a"
    "autocmd FileType text,txt,markdown,mkd,md  execute "normal magggqG`a"
    "autocmd BufWritePre text,txt,markdown,mkd,md :SoftPencil
    "autocmd BufWritePost text,txt,markdown,mkd,md :HardPencil
augroup END

"GOYO===============================================================

function! s:goyo_enter()
  "Setup to quit vim in GOYO
  let b:quitting = 0
  let b:quitting_bang = 0
  autocmd QuitPre <buffer> let b:quitting = 1
  cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
endfunction

function! s:goyo_leave()
  " Quit Vim if this is the only remaining buffer
  if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
    if b:quitting_bang
      qa!
    else
      qa
    endif
  endif
endfunction

"autocmd FileType markdown,mkd,md :Goyo
"autocmd FileType text,txt :Goyo
let g:goyo_margin_top=2
let g:goyo_margin_bottom=2
:set scrolloff=999

"autocmd User GoyoEnter call <SID>goyo_enter()
"autocmd User GoyoLeave call <SID>goyo_leave()
reedes commented 9 years ago

As seen in the demo, the Soft/HardPencil command doesn't change line endings. It's only through your explicit editing of text that will lead to breaks being inserted by Vim's formatting machinery. And of course you can gwip to format manually yourself.

This is by design, as forcing global document changes will be disruptive, especially with text you've carefully formatted.

Sorry if that wasn't clear in the docs.

courtyardz commented 9 years ago

I see. Thank you for clarifying so quickly. In that case I might have a feature request for you:

I had planned on using hard line wraps even for prose specifically because getting smooth scrolling with scrolloff=999 set (which keeps the cursor centered in the buffer) seems to require them. I know that this is probably impossible (see this SO Q&A), but if you could somehow get soft-mode vim-pencil to not only move but display "virtual line" by "virtual line," this would definitely enhance your plugin and seems very much in line with it's prose experience goals.

As it is now, if I want smooth scrolling during editing I'll have to, like you say, globally reformat at my own peril. But, of course, it only makes sense to store soft-wrapped files if I want to be able to easily read/edit on mobile, so I would also need some autocmd BufWritePre/Post commands that make sure I'm always only saving soft-wrapped versions, even as I edit hard-wrapped lines. Complicated! Looks like I'll just have to get used to jumpy scrolling...

reedes commented 9 years ago

I fear that the virtual scrolling jumpiness when wrap is enabled will only be solved with a low-level change to vim itself. (Or more likely neovim, given its recent momentum.)

If you end up using hard line breaks, you may want to check out my vim-wheel plugin as an alternative to scrolloff=999.

courtyardz commented 9 years ago

I'll check it out! Thanks for the tips and of course for vim-pencil