├── LICENSE.markdown ├── README.markdown ├── doc └── vimroom.txt └── plugin └── vimroom.vim /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 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | This is my fork of vimroom which includes following: 2 | 3 | * A special mode for editing Markdown and reStructuredText. It's highly inspired by [iA Writer](http://writer.pro/) 4 | * Optimizations for [my vimrc](https://github.com/amix/vimrc) 5 | 6 | Please read more here [ 7 | zenroom for Vim: Focusing only on the essential](http://amix.dk/blog/post/19744#zenroom-for-Vim-Focsuing-only-on-the-essential). 8 | 9 | **Important:** A new version is out that's based on Goyo.vim. It's not a fork 10 | of vimroom. Get it at [vim-zenroom2](https://github.com/amix/vim-zenroom2)! 11 | 12 | ## Usage 13 | 14 | Use the standard vimroom mapping `V` to toggle it. 15 | 16 | ## Editing code 17 | 18 | ![Screenshot 1](http://amix.dk/uploads/zenroom_code.jpg) 19 | 20 | ![Screenshot 2](http://amix.dk/uploads/zenroom_code_1.jpg) 21 | 22 | ## Updating documentation 23 | 24 | ![Screenshot 3](http://amix.dk/uploads/zenroom_documentation.jpg) 25 | 26 | ![Screenshot 4](http://amix.dk/uploads/zenroom_documentation_1.jpg) 27 | -------------------------------------------------------------------------------- /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 100: 24 | if !exists( "g:vimroom_width" ) 25 | let g:vimroom_width = 100 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 = 2 36 | endif 37 | 38 | " The GUI background color. Defaults to "black" 39 | if !exists( "g:vimroom_guibackground" ) 40 | let g:vimroom_guibackground = "#202020" 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 = 0 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 `background` value for reset later 101 | let s:save_background = "" 102 | if exists( "&background" ) 103 | let s:save_background = &background 104 | endif 105 | 106 | " Save the current `showtabline` value for reset later 107 | let s:save_showtabline = "" 108 | if exists( "&showtabline" ) 109 | let s:save_showtabline = &showtabline 110 | endif 111 | 112 | " Save the current `textwidth` value for reset later 113 | let s:save_textwidth = "" 114 | if exists( "&textwidth" ) 115 | let s:save_textwidth = &textwidth 116 | endif 117 | 118 | " Save the current `number` and `relativenumber` values for reset later 119 | let s:save_number = 0 120 | let s:save_relativenumber = 0 121 | if exists( "&number" ) 122 | let s:save_number = &number 123 | endif 124 | if exists ( "&relativenumber" ) 125 | let s:save_relativenumber = &relativenumber 126 | endif 127 | 128 | " We're currently in nonvimroomized state 129 | let s:active = 0 130 | 131 | function! s:is_the_screen_wide_enough() 132 | return winwidth( winnr() ) >= s:minwidth 133 | endfunction 134 | 135 | function! s:sidebar_size() 136 | return ( winwidth( winnr() ) - g:vimroom_width - 2 ) / 2 137 | endfunction 138 | 139 | function! s:markdown_room() 140 | set background=light 141 | set linespace=8 142 | set textwidth=80 143 | hi Normal guibg=gray95 144 | hi NonText guifg=gray95 145 | hi FoldColumn guibg=gray95 146 | hi CursorLine guibg=gray90 147 | hi Title gui=bold guifg=gray25 148 | hi MarkdownHeadingDelimiter gui=bold guifg=gray25 149 | hi htmlSpecialChar guifg=black 150 | hi markdownError guifg=black 151 | hi markdownBold gui=bold guifg=gray25 152 | hi markdownItalic guifg=gray25 gui=underline 153 | hi markdownUrl guifg=#2fb3a6 154 | hi markdownAutomaticLink guifg=#2fb3a6 155 | hi markdownLinkText guifg=#317849 156 | hi markdownUrlTitle guifg=#317849 157 | hi markdownBlockquote guifg=#317849 gui=bold 158 | hi markdownId guifg=#2fb3a6 159 | hi markdownIdDeclaration guifg=#317849 gui=bold 160 | hi markdownListMarker guifg=#317849 161 | hi Cursor guibg=#15abdd 162 | 163 | if has('gui_running') 164 | let l:highlightbgcolor = "guibg=#f2f2f2" 165 | let l:highlightfgbgcolor = "guifg=#f2f2f2" . " " . l:highlightbgcolor 166 | else 167 | let l:highlightbgcolor = "ctermbg=" . g:vimroom_ctermbackground 168 | let l:highlightfgbgcolor = "ctermfg=" . g:vimroom_ctermbackground . " " . l:highlightbgcolor 169 | endif 170 | 171 | exec( "hi Normal " . l:highlightbgcolor ) 172 | exec( "hi VertSplit " . l:highlightfgbgcolor ) 173 | exec( "hi NonText " . l:highlightfgbgcolor ) 174 | exec( "hi StatusLine " . l:highlightfgbgcolor ) 175 | exec( "hi StatusLineNC " . l:highlightfgbgcolor ) 176 | endfunction 177 | 178 | function! VimroomToggle() 179 | if s:active == 1 180 | let s:active = 0 181 | " Close all other split windows 182 | if g:vimroom_sidebar_height 183 | wincmd j 184 | close 185 | wincmd k 186 | close 187 | endif 188 | if g:vimroom_min_sidebar_width 189 | wincmd l 190 | close 191 | wincmd h 192 | close 193 | endif 194 | " Reset color scheme (or clear new colors, if no scheme is set) 195 | if s:scheme != "" 196 | exec( "colorscheme " . s:scheme ) 197 | else 198 | hi clear 199 | endif 200 | if s:save_t_mr != "" 201 | exec( "set t_mr=" .s:save_t_mr ) 202 | endif 203 | " Reset `scrolloff` and `laststatus` 204 | if s:save_scrolloff != "" 205 | exec( "set scrolloff=" . s:save_scrolloff ) 206 | endif 207 | if s:save_laststatus != "" 208 | exec( "set laststatus=" . s:save_laststatus ) 209 | endif 210 | if s:save_showtabline != "" 211 | exec( "set showtabline=" . s:save_showtabline ) 212 | endif 213 | 214 | exec( "set linespace=0" ) 215 | 216 | if s:save_background != "" 217 | exec( "set background=" . s:save_background ) 218 | endif 219 | if s:save_textwidth != "" 220 | exec( "set textwidth=" . s:save_textwidth ) 221 | endif 222 | if s:save_number != 0 223 | set number 224 | endif 225 | if s:save_relativenumber != 0 226 | set relativenumber 227 | endif 228 | " Remove wrapping and linebreaks 229 | set nowrap 230 | set nolinebreak 231 | 232 | if exists( "*AirlineToggle" ) 233 | " Enable AirLine 234 | exec("silent AirlineToggle") 235 | exec("silent AirlineRefresh") 236 | endif 237 | else 238 | if s:is_the_screen_wide_enough() 239 | let is_mark_or_rst = &filetype == "markdown" || &filetype == "rst" || &filetype == "text" 240 | 241 | if is_mark_or_rst 242 | call s:markdown_room() 243 | endif 244 | 245 | if exists( "*AirlineToggle" ) 246 | " Disable AirLine 247 | exec("silent AirlineToggle") 248 | endif 249 | 250 | let s:active = 1 251 | let s:sidebar = s:sidebar_size() 252 | 253 | " Turn off status bar 254 | if s:save_laststatus != "" 255 | setlocal laststatus=0 256 | endif 257 | " Turn off tabline 258 | if s:save_showtabline != "" 259 | setlocal showtabline=0 260 | endif 261 | if g:vimroom_min_sidebar_width 262 | " Create the left sidebar 263 | exec( "silent leftabove " . s:sidebar . "vsplit new" ) 264 | setlocal noma 265 | setlocal nocursorline 266 | setlocal nonumber 267 | silent! setlocal norelativenumber 268 | wincmd l 269 | " Create the right sidebar 270 | exec( "silent rightbelow " . s:sidebar . "vsplit new" ) 271 | setlocal noma 272 | setlocal nocursorline 273 | setlocal nonumber 274 | silent! setlocal norelativenumber 275 | wincmd h 276 | exec( "silent vertical resize " . g:vimroom_width ) 277 | endif 278 | if g:vimroom_sidebar_height 279 | " Create the top sidebar 280 | exec( "silent leftabove " . g:vimroom_sidebar_height . "split new" ) 281 | setlocal noma 282 | setlocal nocursorline 283 | setlocal nonumber 284 | silent! setlocal norelativenumber 285 | wincmd j 286 | " Create the bottom sidebar 287 | exec( "silent rightbelow " . g:vimroom_sidebar_height . "split new" ) 288 | setlocal noma 289 | setlocal nocursorline 290 | setlocal nonumber 291 | silent! setlocal norelativenumber 292 | wincmd k 293 | endif 294 | " Setup wrapping, line breaking, and push the cursor down 295 | set wrap 296 | set linebreak 297 | if g:vimroom_clear_line_numbers 298 | set nonumber 299 | silent! set norelativenumber 300 | endif 301 | if s:save_textwidth != "" 302 | exec( "set textwidth=".g:vimroom_width ) 303 | endif 304 | if s:save_scrolloff != "" 305 | exec( "set scrolloff=".g:vimroom_scrolloff ) 306 | endif 307 | 308 | " Setup navigation over "display lines", not "logical lines" if 309 | " mappings for the navigation keys don't already exist. 310 | if g:vimroom_navigation_keys 311 | try 312 | noremap g 313 | noremap g 314 | noremap k gk 315 | noremap j gj 316 | inoremap g 317 | inoremap g 318 | catch /E227:/ 319 | echo "Navigational key mappings already exist." 320 | endtry 321 | endif 322 | 323 | " Hide distracting visual elements 324 | if !is_mark_or_rst 325 | if has('gui_running') 326 | let l:highlightbgcolor = "guibg=" . g:vimroom_guibackground 327 | let l:highlightfgbgcolor = "guifg=" . g:vimroom_guibackground . " " . l:highlightbgcolor 328 | else 329 | let l:highlightbgcolor = "ctermbg=" . g:vimroom_ctermbackground 330 | let l:highlightfgbgcolor = "ctermfg=" . g:vimroom_ctermbackground . " " . l:highlightbgcolor 331 | endif 332 | exec( "hi Normal " . l:highlightbgcolor ) 333 | exec( "hi VertSplit " . l:highlightfgbgcolor ) 334 | exec( "hi NonText " . l:highlightfgbgcolor ) 335 | exec( "hi StatusLine " . l:highlightfgbgcolor ) 336 | exec( "hi StatusLineNC " . l:highlightfgbgcolor ) 337 | endif 338 | set t_mr="" 339 | set fillchars+=vert:\ 340 | endif 341 | endif 342 | endfunction 343 | 344 | " Create a mapping for the `VimroomToggle` function 345 | noremap VimroomToggle :call VimroomToggle() 346 | 347 | " Create a `VimroomToggle` command: 348 | command -nargs=0 VimroomToggle call VimroomToggle() 349 | 350 | " If no mapping exists, map it to `V`. 351 | if !hasmapto( 'VimroomToggle' ) 352 | nmap V VimroomToggle 353 | endif 354 | --------------------------------------------------------------------------------