├── .gitignore ├── LICENSE ├── README.md ├── demo.gif ├── doc └── litedfm.txt └── plugin └── litedfm.vim /.gitignore: -------------------------------------------------------------------------------- 1 | /doc/tags 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Bilal Quadri 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LiteDFM 2 | ======== 3 | 4 | A lightweight plugin to remove distractions from Vim. 5 | 6 | This is based loosely on *Distraction Free Mode* in Sublime Text. 7 | 8 | A key differentiator from most other implementations of distraction free writing 9 | in Vim is that support for vsplits remains uncrippled. This comes at the expense 10 | of proper centering, though, so there's a tradeoff. 11 | 12 | ![Demo](https://raw.github.com/bilalq/lite-dfm/master/demo.gif) 13 | 14 | Installation 15 | ------------ 16 | 17 | For Pathogen: 18 | 19 | git clone https://github.com/bilalq/lite-dfm ~/.vim/bundle 20 | 21 | For Vundle, add this to your vimrc and run BundleInstall: 22 | 23 | ```vim 24 | Bundle 'bilalq/lite-dfm' 25 | ``` 26 | 27 | Usage 28 | ----- 29 | 30 | There are 3 commands that are exposed: 31 | * `LiteDFM` 32 | * `LiteDFMClose` 33 | * `LiteDFMToggle` 34 | 35 | For convenience, I would recommend setting up a mapping to quickly toggle. 36 | 37 | ```vim 38 | nnoremap z :LiteDFMToggle 39 | ``` 40 | 41 | If you dislike the fact that the last run command shows up as a message, use 42 | this mapping instead: 43 | 44 | ```vim 45 | nnoremap z :LiteDFMTogglei`^ 46 | ``` 47 | 48 | If you're a tmux user and really want to get fancy, this should interest you: 49 | 50 | ```vim 51 | nnoremap z :LiteDFMToggle:silent !tmux set status > /dev/null 2>&1:redraw! 52 | ``` 53 | 54 | Customization 55 | ------------- 56 | 57 | ### Colors 58 | You can manually specify the color to be used for hiding UI elements. There 59 | are two global variables that can be used to override the one that is normally 60 | detected. One is for CLI Vim, while the other is for gui Vim. You can set 61 | these in your vimrc like so: 62 | 63 | ```vim 64 | let g:lite_dfm_normal_bg_cterm = 234 65 | let g:lite_dfm_normal_bg_gui = '#abcabc' 66 | ``` 67 | 68 | If you are using a value of none for your background color, this is the only 69 | way you will be able to make this plugin properly hide your UI elements. 70 | 71 | ### Left offset 72 | This plugin doesn't center, but instead offsets text from the left. You can 73 | specify exactly how many columns you want this offset to be. Any value from 1 to 74 | 22 is valid. By default, 22 is used. 75 | 76 | ```vim 77 | let g:lite_dfm_left_offset = 16 78 | ``` 79 | 80 | ### Keeping the ruler 81 | You may prefer to have the ruler on when you have LiteDFM active. You can do so 82 | by adding this to your vimrc: 83 | 84 | ```vim 85 | let g:lite_dfm_keep_ruler=1 86 | ``` 87 | 88 | Similar Plugins 89 | --------------- 90 | 91 | * [VimRoom](http://projects.mikewest.org/vimroom/) 92 | * [Distraction Free Writing with Vim](http://www.laktek.com/2012/09/05/distraction-free-writing-with-vim/) 93 | * [goyo.vim](https://github.com/junegunn/goyo.vim) 94 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalq/lite-dfm/fefa654c2e8d1a36aaf73c075e8afc5345a0ef46/demo.gif -------------------------------------------------------------------------------- /doc/litedfm.txt: -------------------------------------------------------------------------------- 1 | *litedfm.txt* A lightweight distraction-free-mode for Vim 2 | 3 | Author: Bilal Quadri 4 | License: MIT 5 | 6 | INTRODUCTION *lite-dfm* 7 | 8 | This is inspired by Sublime Text's distraction free mode. 9 | 10 | 11 | COMMANDS *lite-dfm-commands* 12 | 13 | :LiteDFM Enters distraction free mode. 14 | 15 | :LiteDFMClose Leaves distraction free mode. 16 | 17 | :LiteDFMToggle Toggles distraction free mode. 18 | 19 | CUSTOMIZING *lite-dfm-customizing* 20 | You can manually specify the color to be used for hiding UI elements. There 21 | are two global variables that can be used to override the one that is normally 22 | detected. One is for CLI Vim, while the other is for gui Vim. You can set 23 | these in your vimrc like so: 24 | 25 | let g:lite_dfm_normal_bg_cterm = 234 26 | let g:lite_dfm_normal_bg_gui = '#abcabc' 27 | 28 | If you are using a value of none for your background color, this is the only 29 | way you will be able to make this plugin properly hide your UI elements. 30 | 31 | You can also specify exactly how many columns from the left you want to 32 | offset for DFM. Any integer between 1 and 22 (inclusive) is a valid value. 33 | This value default to 22 if not specified. 34 | 35 | let g:lite_dfm_left_offset = 12 36 | 37 | If you prefer to keep the ruler active when LiteDFM is on, you can do so like 38 | this: 39 | 40 | let g:lite_dfm_keep_ruler = 1 41 | 42 | KNOWN ISSUES *lite-dfm-issues* 43 | 44 | No known issues at this time. 45 | 46 | ABOUT *lite-dfm-about* 47 | 48 | The current implementation does the following upon entering 49 | distraction-free-mode: 50 | 51 | Hide the statusbar 52 | Hide the ruler 53 | Hide GitGutter if it is enabled 54 | For each window, change the width of the line number and fold columns to: 55 | Unless the window is Gundo, NERDTree, or Tagbar: 56 | Enable line numbering 57 | Match the specified offset (default: 22) 58 | Change the fg and bg colors for LineNr to the same as Normal bg 59 | Change the fg and bg colors for NonText to the same as Normal bg 60 | Change the fg and bg colors for FoldColumn to the same as Normal bg 61 | If user is in GUI: 62 | Hide menu and scrollbar chrome, then go fullscreen 63 | Revert to original settings upon closing distraction-free-mode 64 | 65 | 66 | vim:tw=78:et:ft=help:norl: 67 | -------------------------------------------------------------------------------- /plugin/litedfm.vim: -------------------------------------------------------------------------------- 1 | " Remember user's default values. 2 | let s:laststatus_default = &laststatus 3 | let s:ruler_default = &ruler 4 | let s:number_default = &number 5 | let s:foldcolumn_default = &foldcolumn 6 | let s:numberwidth_default = &numberwidth 7 | let s:gitgutter_default = get(g:, 'gitgutter_enabled', 0) 8 | let s:tabline_default = &showtabline 9 | if has('gui_running') 10 | let s:fullscreen_default = has('fullscreen') && &fullscreen 11 | let s:guioptions_default = &guioptions 12 | endif 13 | 14 | 15 | " Allow user to specify left offset as an integer between 1 and 22 inclusive 16 | function! s:LoadOffsets() 17 | if !exists('g:lite_dfm_left_offset') || g:lite_dfm_left_offset < 1 || g:lite_dfm_left_offset > 22 18 | let g:lite_dfm_left_offset = 22 19 | endif 20 | if g:lite_dfm_left_offset <= 10 21 | let s:numberwidth_offset = g:lite_dfm_left_offset 22 | let s:foldcolumn_offset = 0 23 | else 24 | let s:numberwidth_offset = 10 25 | let s:foldcolumn_offset = g:lite_dfm_left_offset - 10 26 | endif 27 | endfunction 28 | 29 | 30 | " See if running CLI or GUI Vim 31 | " If user has termguicolors enabled, gui vim is chosen regardless. 32 | let s:context = (has('gui_running') || &termguicolors) ? 'gui' : 'cterm' 33 | 34 | " List of filetypes where window offsets should not be done 35 | let s:ignoredWindows = ['gundo', 'nerdtree', 'tagbar'] 36 | 37 | 38 | " Retrieves the color for a provided scope and swatch in the current context 39 | function! s:LoadColor(scope, swatch) 40 | let l:scopeColor = synIDattr(hlID(a:scope), a:swatch, s:context) 41 | return l:scopeColor < 0 ? 'none' : l:scopeColor 42 | endfunction 43 | 44 | 45 | " Generates a highlight command for the provided scope, foreground, and 46 | " background 47 | function! s:Highlight(scope, fg, bg) 48 | return 'highlight ' . a:scope . ' ' . s:context . 'fg=' . a:fg . ' ' . s:context . 'bg=' . a:bg 49 | endfunction 50 | 51 | 52 | " Generate a highlight string that hides the given scope by setting its 53 | " foreground and background to match the normal background 54 | function! s:Hide(scope) 55 | return s:Highlight(a:scope, s:NormalBG, s:NormalBG) 56 | endfunction 57 | 58 | 59 | " Generate a highlight string that restores the given scope to its original 60 | " foreground and background values 61 | function! s:Restore(scope) 62 | return s:Highlight(a:scope, s:[a:scope . 'FG'], s:[a:scope . 'BG']) 63 | endfunction 64 | 65 | 66 | " Execute the given command within each window that is not ignored 67 | function! s:ForEachWindow(cmd) 68 | let l:initialWindow = winnr() 69 | let l:isNotIgnoredWindow = '(index(s:ignoredWindows, &filetype) < 0)' 70 | let l:isNotGundoDiff = '(bufname(winbufnr(0)) !=# "__Gundo_Preview__")' 71 | let l:cmd = 'if (' . l:isNotIgnoredWindow . ' && ' . l:isNotGundoDiff . ') | ' . a:cmd . ' | endif' 72 | execute 'windo ' . l:cmd 73 | execute l:initialWindow . 'wincmd w' 74 | endfunction 75 | 76 | 77 | " Load all necessary colors and assign them to script-wide variables 78 | function! s:LoadDFMColors() 79 | let s:LineNrFG = s:LoadColor('LineNr', 'fg') 80 | let s:LineNrBG = s:LoadColor('LineNr', 'bg') 81 | let s:CursorLineNRFG = s:LoadColor('CursorLineNR', 'fg') 82 | let s:CursorLineNRBG = s:LoadColor('CursorLineNR', 'bg') 83 | let s:NonTextFG = s:LoadColor('NonText', 'fg') 84 | let s:NonTextBG = s:LoadColor('NonText', 'bg') 85 | let s:FoldColumnFG = s:LoadColor('FoldColumn', 'fg') 86 | let s:FoldColumnBG = s:LoadColor('FoldColumn', 'bg') 87 | 88 | " Allow users to manually specify the color used to hide UI elements 89 | let s:NormalBG = get(g:, 'lite_dfm_normal_bg_' . s:context, s:LoadColor('Normal', 'bg')) 90 | endfunction 91 | 92 | 93 | " Function to enter DFM 94 | function! LiteDFM() 95 | if !get(s:, 'lite_dfm_on', 0) 96 | call s:LoadDFMColors() 97 | endif 98 | call s:LoadOffsets() 99 | let s:lite_dfm_on = 1 100 | 101 | if get(g:, 'gitgutter_enabled', 0) 102 | GitGutterDisable 103 | endif 104 | 105 | let &ruler = get(g:, 'lite_dfm_keep_ruler', 0) 106 | set number 107 | set laststatus=0 108 | set showtabline=0 109 | call s:ForEachWindow('set numberwidth=' . s:numberwidth_offset . ' foldcolumn=' . s:foldcolumn_offset) 110 | 111 | execute s:Hide('LineNr') 112 | execute s:Hide('CursorLineNR') 113 | execute s:Hide('NonText') 114 | execute s:Hide('FoldColumn') 115 | 116 | if has('gui_running') 117 | set guioptions-=T " Hide icons 118 | set guioptions-=r " Hide scrollbar 119 | set guioptions-=L " Hide NERDTree scrollbar 120 | if has('fullscreen') 121 | set fullscreen 122 | endif 123 | endif 124 | endfunction 125 | 126 | 127 | " Function to close DFM 128 | function! LiteDFMClose() 129 | let s:lite_dfm_on = 0 130 | 131 | if s:gitgutter_default 132 | GitGutterEnable 133 | endif 134 | 135 | let &ruler = s:ruler_default 136 | let &number = s:number_default 137 | let &laststatus = s:laststatus_default 138 | let &showtabline= s:tabline_default 139 | call s:ForEachWindow('set numberwidth=' . s:numberwidth_default . ' foldcolumn=' . s:foldcolumn_default) 140 | 141 | try 142 | execute s:Restore('LineNr') 143 | execute s:Restore('CursorLineNR') 144 | execute s:Restore('NonText') 145 | execute s:Restore('FoldColumn') 146 | catch /.*/ 147 | " Attempting to Restore values fails when they were never changed to begin 148 | " with. This is VimScript, so we don't care and just swallow the 149 | " exception. 150 | endtry 151 | 152 | if has('gui_running') 153 | if has('fullscreen') 154 | let &fullscreen = s:fullscreen_default 155 | endif 156 | let &guioptions = s:guioptions_default 157 | endif 158 | endfunction 159 | 160 | 161 | " Function to toggle DFM 162 | function! LiteDFMToggle() 163 | if get(s:, 'lite_dfm_on', 0) 164 | call LiteDFMClose() 165 | else 166 | call LiteDFM() 167 | endif 168 | endfunction 169 | 170 | 171 | " Map function calls to commands 172 | command! LiteDFM call LiteDFM() 173 | command! LiteDFMClose call LiteDFMClose() 174 | command! LiteDFMToggle call LiteDFMToggle() 175 | --------------------------------------------------------------------------------