├── README.markdown ├── LICENSE.markdown ├── doc └── vimroom.txt └── plugin └── vimroom.vim /README.markdown: -------------------------------------------------------------------------------- 1 | Vimroom 2 | ======= 3 | 4 | Readme goes here. 5 | -------------------------------------------------------------------------------- /LICENSE.markdown: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Mike West, http://mikewest.org/ 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | Neither the name of the software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /doc/vimroom.txt: -------------------------------------------------------------------------------- 1 | *vimroom.txt* 2 | 3 | ============================================================================== 4 | TABLE OF CONTENTS *vimroom* *vimroom-toc* 5 | 6 | 1. About |vimroom-about| 7 | 2. Installation |vimroom-installation| 8 | 3. Configuration |vimroom-configuration| 9 | 10 | ============================================================================== 11 | ABOUT *vimroom-about* 12 | 13 | I do most of my writing in Vim, because I’m a big nerd. It does most of what 14 | I want a writing environment to do, but I miss some of the “distraction free" 15 | features of the quite exceptional WriteRoom. Fullscreening Vim means that text 16 | ends up flat up against the left side of my monitor, but I’d much prefer it to 17 | be centered. I’d also like a little of the visual clutter to fade away. Some 18 | of this is possible with MacVim, but I’d rather do as much as possible in 19 | a platform-independent way. So, command-line Vim it is. 20 | 21 | For more visit: 22 | http://projects.mikewest.org/vimroom/ 23 | https://github.com/mikewest/vimroom 24 | 25 | ============================================================================== 26 | INSTALLATION *vimroom-installation* 27 | 28 | I think the best way to install Vim plugins is via Tim Pope’s Pathogen. Using 29 | that plugin, you can simply clone the VimRoom repository into your bundles 30 | directory, and you’re done. 31 | 32 | Without Pathogen, installation is almost as trivial: simply copy 33 | ./plugins/vimroom.vim from the repository into your plugins directory. That’s 34 | it! 35 | 36 | ============================================================================== 37 | CONFIGURATION *vimroom-configuration* 38 | 39 | By default, VimRoom binds V to VimroomToggle, and sets up an 80 40 | column workspace with at least 5 columns of space on either side (it doesn’t 41 | help at all to have single-column sidebars, you see), and 3 lines of space 42 | above and below. It assumes a black background when hiding visual 43 | distractions. As of v0.4, VimRoom also sets up a :VimroomToggle command that 44 | has the same effect. 45 | 46 | Changing any of these assumptions is a simple matter of setting variables in 47 | your .vimrc. 48 | 49 | *g:vimroom_background* 50 | is the background color to be used for hiding elements. Set this to your 51 | terminal’s background color (“white”, “black”, etc.) 52 | 53 | *g:vimroom_min_sidebar_width* 54 | is the minimum sidebar width. This will automatically expand to take up all 55 | the free space left after setting the main workspace window to g:vimroom_width 56 | pcolumns. 57 | 58 | *g:vimroom_navigational_keys* 59 | determines whether Vimroom will map keys like , , j, and k to 60 | navigate over “display” lines, rather than “logical” lines. This defaults to 61 | p1 (on), if you’d prefer the mapping not take place, set it to 0 (off). 62 | 63 | *g:vimroom_scrolloff* 64 | specifies how many lines of text ought appear before and after the cursor. 65 | pThis defaults to 999, which centers the cursor on the screen. 66 | 67 | *g:vimroom_sidebar_height* 68 | sets the height of the upper and lower “sidebars.” If you don’t want vertical 69 | padding, set this to 0. 70 | 71 | *g:vimroom_width* 72 | is the width of your workspace. 73 | 74 | 75 | You can bind the VimroomToggle function to any key combination you like 76 | via the usual mechanisms. For example:: 77 | > 78 | nnoremap mz VimroomToggle 79 | <> 80 | 81 | Would bind the function to mz. Trivial, right? 82 | 83 | And that’s it! 84 | 85 | ============================================================================== 86 | vim:tw=78:ts=2:sw=2:expandtab:ft=help:norl: 87 | -------------------------------------------------------------------------------- /plugin/vimroom.vim: -------------------------------------------------------------------------------- 1 | "============================================================================== 2 | "File: vimroom.vim 3 | "Description: Vaguely emulates a writeroom-like environment in Vim by 4 | " splitting the current window in such a way as to center a column 5 | " of user-specified width, wrap the text, and break lines. 6 | "Maintainer: Mike West 7 | "Version: 0.7 8 | "Last Change: 2010-10-31 9 | "License: BSD <../LICENSE.markdown> 10 | "============================================================================== 11 | 12 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 13 | " Plugin Configuration 14 | " 15 | 16 | " The typical start to any vim plugin: If the plugin has already been loaded, 17 | " exit as quickly as possible. 18 | if exists( "g:loaded_vimroom_plugin" ) 19 | finish 20 | endif 21 | let g:loaded_vimroom_plugin = 1 22 | 23 | " The desired column width. Defaults to 80: 24 | if !exists( "g:vimroom_width" ) 25 | let g:vimroom_width = 80 26 | endif 27 | 28 | " The minimum sidebar size. Defaults to 5: 29 | if !exists( "g:vimroom_min_sidebar_width" ) 30 | let g:vimroom_min_sidebar_width = 5 31 | endif 32 | 33 | " The sidebar height. Defaults to 3: 34 | if !exists( "g:vimroom_sidebar_height" ) 35 | let g:vimroom_sidebar_height = 3 36 | endif 37 | 38 | " The GUI background color. Defaults to "black" 39 | if !exists( "g:vimroom_guibackground" ) 40 | let g:vimroom_guibackground = "black" 41 | endif 42 | 43 | " The cterm background color. Defaults to "bg" 44 | if !exists( "g:vimroom_ctermbackground" ) 45 | let g:vimroom_ctermbackground = "bg" 46 | endif 47 | 48 | " The "scrolloff" value: how many lines should be kept visible above and below 49 | " the cursor at all times? Defaults to 999 (which centers your cursor in the 50 | " active window). 51 | if !exists( "g:vimroom_scrolloff" ) 52 | let g:vimroom_scrolloff = 999 53 | endif 54 | 55 | " Should Vimroom map navigational keys (``, ``, `j`, `k`) to navigate 56 | " "display" lines instead of "logical" lines (which makes it much simpler to deal 57 | " with wrapped lines). Defaults to `1` (on). Set to `0` if you'd prefer not to 58 | " run the mappings. 59 | if !exists( "g:vimroom_navigation_keys" ) 60 | let g:vimroom_navigation_keys = 1 61 | endif 62 | 63 | " Should Vimroom clear line numbers from the Vimroomed buffer? Defaults to `1` 64 | " (on). Set to `0` if you'd prefer Vimroom to leave line numbers untouched. 65 | " (Note that setting this to `0` will not turn line numbers on if they aren't 66 | " on already). 67 | if !exists( "g:vimroom_clear_line_numbers" ) 68 | let g:vimroom_clear_line_numbers = 1 69 | endif 70 | 71 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 72 | " Plugin Code 73 | " 74 | 75 | " Given the desired column width, and minimum sidebar width, determine 76 | " the minimum window width necessary for splitting to make sense 77 | let s:minwidth = g:vimroom_width + ( g:vimroom_min_sidebar_width * 2 ) 78 | 79 | " Save the current color scheme for reset later 80 | let s:scheme = "" 81 | if exists( "g:colors_name" ) 82 | let s:scheme = g:colors_name 83 | endif 84 | if exists( "&t_mr" ) 85 | let s:save_t_mr = &t_mr 86 | end 87 | 88 | " Save the current scrolloff value for reset later 89 | let s:save_scrolloff = "" 90 | if exists( "&scrolloff" ) 91 | let s:save_scrolloff = &scrolloff 92 | end 93 | 94 | " Save the current `laststatus` value for reset later 95 | let s:save_laststatus = "" 96 | if exists( "&laststatus" ) 97 | let s:save_laststatus = &laststatus 98 | endif 99 | 100 | " Save the current `textwidth` value for reset later 101 | let s:save_textwidth = "" 102 | if exists( "&textwidth" ) 103 | let s:save_textwidth = &textwidth 104 | endif 105 | 106 | " Save the current `number` and `relativenumber` values for reset later 107 | let s:save_number = 0 108 | let s:save_relativenumber = 0 109 | if exists( "&number" ) 110 | let s:save_number = &number 111 | endif 112 | if exists ( "&relativenumber" ) 113 | let s:save_relativenumber = &relativenumber 114 | endif 115 | 116 | " We're currently in nonvimroomized state 117 | let s:active = 0 118 | 119 | function! s:is_the_screen_wide_enough() 120 | return winwidth( winnr() ) >= s:minwidth 121 | endfunction 122 | 123 | function! s:sidebar_size() 124 | return ( winwidth( winnr() ) - g:vimroom_width - 2 ) / 2 125 | endfunction 126 | 127 | function! VimroomToggle() 128 | if s:active == 1 129 | let s:active = 0 130 | " Close all other split windows 131 | if g:vimroom_sidebar_height 132 | wincmd j 133 | close 134 | wincmd k 135 | close 136 | endif 137 | if g:vimroom_min_sidebar_width 138 | wincmd l 139 | close 140 | wincmd h 141 | close 142 | endif 143 | " Reset color scheme (or clear new colors, if no scheme is set) 144 | if s:scheme != "" 145 | exec( "colorscheme " . s:scheme ) 146 | else 147 | hi clear 148 | endif 149 | if s:save_t_mr != "" 150 | exec( "set t_mr=" .s:save_t_mr ) 151 | endif 152 | " Reset `scrolloff` and `laststatus` 153 | if s:save_scrolloff != "" 154 | exec( "set scrolloff=" . s:save_scrolloff ) 155 | endif 156 | if s:save_laststatus != "" 157 | exec( "set laststatus=" . s:save_laststatus ) 158 | endif 159 | if s:save_textwidth != "" 160 | exec( "set textwidth=" . s:save_textwidth ) 161 | endif 162 | if s:save_number != 0 163 | set number 164 | endif 165 | if s:save_relativenumber != 0 166 | set relativenumber 167 | endif 168 | " Remove wrapping and linebreaks 169 | set nowrap 170 | set nolinebreak 171 | else 172 | if s:is_the_screen_wide_enough() 173 | let s:active = 1 174 | let s:sidebar = s:sidebar_size() 175 | " Turn off status bar 176 | if s:save_laststatus != "" 177 | setlocal laststatus=0 178 | endif 179 | if g:vimroom_min_sidebar_width 180 | " Create the left sidebar 181 | exec( "silent leftabove " . s:sidebar . "vsplit new" ) 182 | setlocal noma 183 | setlocal nocursorline 184 | setlocal nonumber 185 | silent! setlocal norelativenumber 186 | wincmd l 187 | " Create the right sidebar 188 | exec( "silent rightbelow " . s:sidebar . "vsplit new" ) 189 | setlocal noma 190 | setlocal nocursorline 191 | setlocal nonumber 192 | silent! setlocal norelativenumber 193 | wincmd h 194 | endif 195 | if g:vimroom_sidebar_height 196 | " Create the top sidebar 197 | exec( "silent leftabove " . g:vimroom_sidebar_height . "split new" ) 198 | setlocal noma 199 | setlocal nocursorline 200 | setlocal nonumber 201 | silent! setlocal norelativenumber 202 | wincmd j 203 | " Create the bottom sidebar 204 | exec( "silent rightbelow " . g:vimroom_sidebar_height . "split new" ) 205 | setlocal noma 206 | setlocal nocursorline 207 | setlocal nonumber 208 | silent! setlocal norelativenumber 209 | wincmd k 210 | endif 211 | " Setup wrapping, line breaking, and push the cursor down 212 | set wrap 213 | set linebreak 214 | if g:vimroom_clear_line_numbers 215 | set nonumber 216 | silent! set norelativenumber 217 | endif 218 | if s:save_textwidth != "" 219 | exec( "set textwidth=".g:vimroom_width ) 220 | endif 221 | if s:save_scrolloff != "" 222 | exec( "set scrolloff=".g:vimroom_scrolloff ) 223 | endif 224 | 225 | " Setup navigation over "display lines", not "logical lines" if 226 | " mappings for the navigation keys don't already exist. 227 | if g:vimroom_navigation_keys 228 | try 229 | noremap g 230 | noremap g 231 | noremap k gk 232 | noremap j gj 233 | inoremap g 234 | inoremap g 235 | catch /E227:/ 236 | echo "Navigational key mappings already exist." 237 | endtry 238 | endif 239 | 240 | " Hide distracting visual elements 241 | if has('gui_running') 242 | let l:highlightbgcolor = "guibg=" . g:vimroom_guibackground 243 | let l:highlightfgbgcolor = "guifg=" . g:vimroom_guibackground . " " . l:highlightbgcolor 244 | else 245 | let l:highlightbgcolor = "ctermbg=" . g:vimroom_ctermbackground 246 | let l:highlightfgbgcolor = "ctermfg=" . g:vimroom_ctermbackground . " " . l:highlightbgcolor 247 | endif 248 | exec( "hi Normal " . l:highlightbgcolor ) 249 | exec( "hi VertSplit " . l:highlightfgbgcolor ) 250 | exec( "hi NonText " . l:highlightfgbgcolor ) 251 | exec( "hi StatusLine " . l:highlightfgbgcolor ) 252 | exec( "hi StatusLineNC " . l:highlightfgbgcolor ) 253 | set t_mr="" 254 | set fillchars+=vert:\ 255 | endif 256 | endif 257 | endfunction 258 | 259 | " Create a mapping for the `VimroomToggle` function 260 | noremap VimroomToggle :call VimroomToggle() 261 | 262 | " Create a `VimroomToggle` command: 263 | command -nargs=0 VimroomToggle call VimroomToggle() 264 | 265 | " If no mapping exists, map it to `V`. 266 | if !hasmapto( 'VimroomToggle' ) 267 | nmap V VimroomToggle 268 | endif 269 | --------------------------------------------------------------------------------