With Vim Markdown highlighting (and folding) up and running, the most straightforward solution is to evoke vim
in the read only mode with either vim -R
, or (at least on Ubuntu) more elegantly:
$ view filename.md
Add the following at the very bottom of your .vimrc
file, and view
will behave just like less
with the added benefit of your favourite syntax highlighting (not only for markdown!) and folding:
" less behaviour for view
" https://stackoverflow.com/a/39836959/2192488
" http://vim.wikia.com/wiki/Using_vim_as_a_syntax-highlighting_pager
function! LessBehaviour()
if (!&modifiable || &ro)
set nonumber
set nospell
set laststatus=0 " Status line
set cmdheight=1
set guioptions=aiMr " No menu bar, nor tool bar
noremap u <C-u>
noremap d <C-d>
noremap q :q<CR>
endif
endfunction
" https://vi.stackexchange.com/a/9101/3168
augroup ReadOnly
au!
au VimEnter * :call LessBehaviour()
augroup END
There exists also a more rigorous less.sh
script. On my system, it comes packaged with vim
. To find it, use:
$ find /usr/share/vim -name less.sh
However, contrary to the script listed above, folding will not work with this less.sh
.