iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.69k stars 277 forks source link

Error in Mappings #92

Closed lpvm closed 4 years ago

lpvm commented 4 years ago

When opening some text file, either with nvim or vim, I get errors:

Error detected while processing /home/user/.vimrc:
line  731:
E488: Trailing characters: <Plug>MarkdownPreview
line  732:
E488: Trailing characters: <Plug>MarkdownPreviewStop
line  733:
E488: Trailing characters: <Plug>MarkdownPreviewToggle

In the #vim@freenode IRC channel, a user said that it must be a: "probably an unescaped | in a mapping in a ftplugin script"

iamcco commented 4 years ago

It's not issue of the plugin, checkout your vimrc.

lpvm commented 4 years ago

When I remove those three lines I get no errors.

iamcco commented 4 years ago

it's weird, please paste the vimrc here.

lpvm commented 4 years ago

Here it is:

let &packpath = &runtimepath

if &compatible
  set nocompatible
endif

if has('gui_running')
    set background=light
else
    set background=dark
endif

if &t_Co > 2 || has("gui_running")
  syntax on
  " set vim to 256 before setting the colorscheme!!!
  set t_Co=256
  "let g:solarized_termcolors=256

  syntax enable
  " colorscheme solarized
  "colorscheme impact
  "colorscheme Tomorrow-Night
  "colorscheme http://vimcolors.com/307/moria/dark
  " https://github.com/AlessandroYorba/Alduin
  colorscheme gruvbox

  " toggle backgroud dark or light
  " call togglebg#map("<F5>")
  " Switch on highlighting the last used search pattern.
  set hlsearch
endif

filetype plugin indent on
let mapleader=','
let maplocalleader=','
set scrolloff=9
set dir=~/.config/nvim/tmp
set mouse=a     " Do not select linenumbers with mouse
set equalalways     " Equalize spilts
set iskeyword+=:,-  " For vim-latex suite???
set ruler laststatus=2 showcmd showmode number
set norelativenumber    " Lazy
set whichwrap=hl    " Wrap with left and right
set columns=80      " End of lines...
set colorcolumn=80  " ...with highlight
set cursorline      " Highlight cursor row
set nocursorcolumn  " Highlight cursor column
set backup              " keep a backup file (restore to previous version)
set backupdir=~/.config/nvim/backup
set undofile            " keep an undo file (undo changes after closing)
set undodir=~/.config/nvim/undo
set undolevels=1000
set undoreload=20000
set ruler               " show the cursor position all the time
set showcmd             " display incomplete commands
set formatoptions=o     " Autocomment on 'o'
set formatoptions+=r    " Autocomments on newline
set formatoptions+=j    " Remove comment on join
set formatoptions+=c    " Break comments on 'textwidth'
set formatoptions+=q    " Format comments with gq
set formatoptions+=t    " Break text on 'textwidth' (consider moving to ft)
set formatoptions+=2    " Autoindent on second line of paragraph
set autowrite
set tabstop=8
set shiftwidth=4
command W :w        " Writesudo
command Wsudo :w !sudo tee %

set pastetoggle=<F3>
nmap <F9> :TagbarToggle<CR>
map <F11> :set nonumber<CR>
map <F12> :set number<CR>

autocmd FileType c,cpp,java,scala,javascript,go let b:comment_leader = '// ' 
autocmd FileType sh,ruby,python let b:comment_leader = '# ' 
autocmd FileType conf,fstab let b:comment_leader = '# ' 
autocmd FileType texlet b:comment_leader = '% ' 
autocmd FileType mail let b:comment_leader = '> ' 
autocmd FileType vim let b:comment_leader = '" ' 
autocmd FileType red,rebol let b:comment_leader = '; ' 
autocmd FileType elixir,picolisp let b:comment_leader = '# '
autocmd FileType html let b:comment_leader = '<!--    -->' 
noremap <silent> ,cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
noremap <silent> ,cu :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR> 

abbr re0 Red [ <CR>Title:  "Advent of Code 2018 - Day 01 - Part 01" <CR>Date:   2018-12-xx<CR>File:   %day0x_part0x.red<CR>Author: "my own"<CR>Version: 0.0.1<CR>]
abbr re1 Red [ <CR>     Title:  ""<CR>Date:   <CR>Name:    'F  ; For window title bar<CR>Version: 0.0.1<CR>File:    %l.r<CR>Home:    http://www.rebol.com/ <CR>Author:  "my own"<CR>Owner:   "my own"<CR>Rights:  "Copyright (C) my own 2018"<CR>Needs:   []<CR>Tabs:    4<CR>Purpose: { }<CR>Note: { }<CR>History: [ 0.0.1 [2018-12-31 {.} "my own"] ]<CR>Language: 'English<CR>]

autocmd FileType rebol nnoremap <Leader>fr :w<CR>:exec '!/usr/bin/r3-64-view-linux-dev' shellescape(@%, 1)<cr>
autocmd FileType red nnoremap <Leader>fr :w<CR>:exec '!/usr/local/bin/red_linux' shellescape(@%, 1)<cr>
autocmd FileType picolisp nnoremap <Leader>fr :w<CR>:exec '!/usr/bin/pil' shellescape(@%, 1)<cr>
autocmd FileType javascript nnoremap <Leader>fr :w<CR>:exec '!/usr/bin/casperjs --verbose --log-level=info' shellescape(@%, 1)<cr> 
autocmd FileType elixir nnoremap <Leader>fr :w<CR>:exec '!/usr/bin/elixir' shellescape(@%, 1)<cr>

autocmd BufNewFile,BufRead *.lpr set syntax=pascal

autocmd FileType go nmap <leader>b  <Plug>(go-build)
autocmd FileType go nmap <leader>r  <Plug>(go-run)

au BufNewFile,BufRead *.js, *.html, *.css, *.gohtml                                                                                                                                                          
    \ set tabstop=8
    \ set softtabstop=2
    \ set shiftwidth=4

let g:go_fmt_command = "goimports"
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_functions = 1
let g:go_metalinter_autosave = 1
let g:go_metalinter_autosave_enabled = ['vet', 'golint']

let g:tex_flavor = 'xelatex'
let g:vimtex_view_method='zathura'
let g:vimtex_latexmk_progname='nvr'
let vimtex_view_zathura_options=''
nnoremap <localleader>wc :VimtexWordCount<cr>

let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline_symbols = get(g:, 'airline_symbols', {})
let g:airline_symbols.space = "\ua0"

 "set background=dark
 let $NVIM_TUI_ENABLE_TRUE_COLOR=1
let g:airline_theme='gruvbox'

 " \ pumvisible() ? "\<C-n>" :
 " \ neosnippet#expandable_or_jumpable() ?
 " \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"

augroup vimrcEx
  autocmd!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " 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
  autocmd BufReadPost *
    \ if line("'\"") >= 1 && line("'\"") <= line("$") |
    \   execute "normal! g`\"" |
    \ endif

augroup END

if !exists(":DiffOrig")
  command DiffOrig vert new | set buftype=nofile | read ++edit # | 0d_ | diffthis
                 \ | wincmd p | diffthis
endif

call plug#begin()
    Plug 'scrooloose/syntastic'
    Plug 'Valloric/YouCompleteMe', { 'for': 'go' }
    Plug 'trapd00r/vidir'
    " asynchronous unite all interfaces
    Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
    Plug 'junegunn/fzf.vim'

    " mru - most recent used
    " Plug 'Shougo/neomru.vim'
    "
    "Plug 'Shougo/vimshell.vim'

    "Plug 'tpope/vim-surround'

    " appearance
    Plug 'morhetz/gruvbox'
    Plug 'ericbn/vim-solarized'
    Plug 'dikiaap/minimalist'
    " status bar
    Plug 'edkolev/tmuxline.vim'
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'chriskempson/tomorrow-theme'
    Plug 'guns/xterm-color-table.vim'
    "Plug 'vimwiki/vimwiki', {'branch': 'dev'}
    "Plug 'jceb/vim-orgmode'
    "Plug 'guns/vim-sexp'
    "Plug 'tpope/vim-sexp-mappings-for-regular-people'
    Plug 'tpope/vim-repeat'
    Plug 'tpope/vim-fugitive'
    Plug 'elixir-lang/vim-elixir', { 'for': 'elixir' }
    Plug 'slashmili/alchemist.vim', { 'for': 'elixir' }
        " ALE toggle
    " :DiffConflictsShowHistory
    Plug 'whiteinge/diffconflicts'
    Plug 'w0rp/ale'
    Plug 'DavidFeng/vim-red'
    Plug 'arcticicestudio/nord-vim'
    " Plug 'boeckmann/vim-freepascal'
    Plug 'fatih/vim-go'
    Plug 'jstemmer/gotags'
    Plug 'majutsushi/tagbar'
    Plug 'dylanaraps/fff.vim'
    Plug 'junegunn/limelight.vim'
    Plug 'godlygeek/tabular'
    Plug 'plasticboy/vim-markdown'
    Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } }

call plug#end()

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_tex_checkers = ['chktex']
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

function! SetBasicStatusLine()
  set statusline=%f   " path to file
  set statusline+=\   " separator
  set statusline+=%m  " modified flag
  set statusline+=%=  " switch to right side
  set statusline+=%y  " filetype of file
endfunction

let g:fzf_command_prefix = 'Fzf'

nnoremap <space>- :FZF <c-r>=fnameescape(expand('%:p:h'))<cr>/<cr>
nnoremap <space>+ :FZF<cr>
nnoremap <space>b :FzfBuffers<cr>
nnoremap <space>ff :FZF<space>
nnoremap <space>fl :FzfLines<cr>
nnoremap <space>fb :FzfBLines<cr>
nnoremap <space>ft :FzfTags<cr>
nnoremap <space>fr :FzfHistory<cr>
nnoremap <space>fh :FzfHelptags<cr>
nnoremap <space>f: :FzfHistory:<cr>
nnoremap <space>f/ :FzfHistory/<cr>
nnoremap <space><space> :FzfCommands<cr>

if &diff
    map gs :call IwhiteToggle()<CR>
    function! IwhiteToggle()
        if &diffopt =~ 'iwhite'
            set diffopt-=iwhite
        else
            set diffopt+=iwhite
        endif
    endfunction
 endif

let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
    \ }

autocmd FileType markdown let b:sleuth_automatic=0
autocmd FileType markdown set conceallevel=0
autocmd FileType markdown normal zR

let g:vim_markdown_frontmatter=1

let g:mkdp_refresh_slow=1
let g:mkdp_markdown_css="/home/lupe/prog/go/src/github.com/lpvm/computationaldata/html/css/github-markdown-css.css"

<Plug>MarkdownPreview
<Plug>MarkdownPreviewStop
<Plug>MarkdownPreviewToggle
iamcco commented 4 years ago

You have to use like this.

" example
nmap <C-s> <Plug>MarkdownPreview
nmap <M-s> <Plug>MarkdownPreviewStop
nmap <C-p> <Plug>MarkdownPreviewToggle
lpvm commented 4 years ago

Alright, but including those lines doesn't change anything. There's the error, still.

iamcco commented 4 years ago

you should remove the

<Plug>MarkdownPreview
<Plug>MarkdownPreviewStop
<Plug>MarkdownPreviewToggle

and use like

nmap <C-s> <Plug>MarkdownPreview
nmap <M-s> <Plug>MarkdownPreviewStop
nmap <C-p> <Plug>MarkdownPreviewToggle
lpvm commented 4 years ago

Without those lines, starting nvim returns no error, but I cannot use the :MarkdownPreview* commands, as they're doesn't seem to be available.

iamcco commented 4 years ago

Those lines have no relative to the :MarkdownPreview* commands.

lpvm commented 4 years ago

Things are already working, not sure what is different. Uninstalled all plugins, installed again, commented those '' lines, no errors. Now I can try your plugin. Thank you very much for your support!

rstecca commented 3 years ago

Hello, I know this is closed but I'm having the same issues. I'm using nvim on iTerm2 on macOS Catalina. The errors I got are as follows:

Error detected while processing /Users/r/.config/nvim/mappings.vim:
line    3:
E488: Trailing characters: <Plug>MarkdownPreview
line    4:
E488: Trailing characters: <Plug>MarkdownPreviewStop
line    5:
E488: Trailing characters: <Plug>MarkdownPreviewToggle
Press ENTER or type command to continue

so exactly like @lpvm I tried reinstalling all plugins but it didn't work. I then had a look at the file markdown-preview.nvim/plugin/mkdp.vim and found that there were trailing 'a' in 2 lines (105 and 107).

function! s:init_command() abort
  " mapping for user
  noremap <buffer> <silent> <Plug>MarkdownPreview :call mkdp#util#open_preview_page()<CR>
  inoremap <buffer> <silent> <Plug>MarkdownPreview <Esc>:call mkdp#util#open_preview_page()<CR>a
  noremap <buffer> <silent> <Plug>MarkdownPreviewStop :call mkdp#util#stop_preview()<CR>
  inoremap <buffer> <silent> <Plug>MarkdownPreviewStop <Esc>:call mkdp#util#stop_preview()<CR>a
  nnoremap <buffer> <silent> <Plug>MarkdownPreviewToggle :call mkdp#util#toggle_preview()<CR>
  inoremap <buffer> <silent> <Plug>MarkdownPreviewToggle <Esc>:call mkdp#util#toggle_preview()<CR>
endfunction

Not sure if these 'a's have a purpose, I tried removing them but nothing seems to change, I still get the annoying errors but in some cases (for example when I do nvim .) I only get the line

Error detected while processing /Users/r/.config/nvim/mappings.vim:

...without the errors.

My config files are very basic.

init.vim

set number
set noexpandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent

source $HOME/.config/nvim/plugin.vim
source $HOME/.config/nvim/mkdp.vim
source $HOME/.config/nvim/mappings.vim

plugin.vim

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" OR
" Install plugin manager with
" curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

call plug#begin('~/.vim/plugged')
" Plug 'itchyny/lightline.vim'
" Plug 'https://github.com/iamcco/markdown-preview.vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
Plug 'https://github.com/Shougo/deoplete.nvim'
" Plug 'https://github.com/plasticboy/vim-markdown'
Plug 'https://github.com/preservim/nerdtree'
call plug#end()

mkdp.vim

" https://github.com/iamcco/markdown-preview.nvim

" set to 1, nvim will open the preview window after entering the markdown buffer
" default: 0
let g:mkdp_auto_start = 0

" set to 1, the nvim will auto close current preview window when change
" from markdown buffer to another buffer
" default: 1
let g:mkdp_auto_close = 1

" set to 1, the vim will refresh markdown when save the buffer or
" leave from insert mode, default 0 is auto refresh markdown as you edit or
" move the cursor
" default: 0
let g:mkdp_refresh_slow = 0

" set to 1, the MarkdownPreview command can be use for all files,
" by default it can be use in markdown file
" default: 0
let g:mkdp_command_for_global = 0

" set to 1, preview server available to others in your network
" by default, the server listens on localhost (127.0.0.1)
" defalt: 0
let g:mkdp_open_to_the_world = 0

" use custom IP to open preview page
" useful when you work in remote vim and preview on local browser
" more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9
" default empty
let g:mkdp_open_ip = ''

" specify browser to open preview page
" default: ''
let g:mkdp_browser = ''

" set to 1, echo preview page url in command line when open preview page
" default is 0
let g:mkdp_echo_preview_url = 0

" a custom vim function name to open preview page
" this function will receive url as param
" default is empty
let g:mkdp_browserfunc = ''

" options for markdown render
" mkit: markdown-it options for render
" katex: katex options for math
" uml: markdown-it-plantuml options
" maid: mermaid options
" disable_sync_scroll: if disable sync scroll, default 0
" sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle'
"   middle: mean the cursor position alway show at the middle of the preview page
"   top: mean the vim top viewport alway show at the top of the preview page
"   relative: mean the cursor position alway show at the relative positon of the preview page
" hide_yaml_meta: if hide yaml metadata, default is 1
" sequence_diagrams: js-sequence-diagrams options
" content_editable: if enable content editable for preview page, default: v:false
" disable_filename: if disable filename header for preview page, default: 0
let g:mkdp_preview_options = {
    \ 'mkit': {},
    \ 'katex': {},
    \ 'uml': {},
    \ 'maid': {},
    \ 'disable_sync_scroll': 0,
    \ 'sync_scroll_type': 'middle',
    \ 'hide_yaml_meta': 1,
    \ 'sequence_diagrams': {},
    \ 'flowchart_diagrams': {},
    \ 'content_editable': v:false,
    \ 'disable_filename': 0
    \ }

" use a custom markdown style must be absolute path
" like '/Users/username/markdown.css' or expand('~/markdown.css')
let g:mkdp_markdown_css = expand('~/.config/nvim/mkdpstyles/customric.css')

" use a custom highlight style must absolute path
" like '/Users/username/highlight.css' or expand('~/highlight.css')
let g:mkdp_highlight_css = ''

" use a custom port to start server or random for empty
let g:mkdp_port = ''

" preview page title
" ${name} will be replace with the file name
let g:mkdp_page_title = '「${name}」'

" recognized filetypes
" these filetypes will have MarkdownPreview... commands
let g:mkdp_filetypes = ['markdown']

mappings.vim

map <F7> :NERDTreeToggle<CR>

<Plug>MarkdownPreview
<Plug>MarkdownPreviewStop
<Plug>MarkdownPreviewToggle

" MarkdownPreview
" normal/insert
nmap <C-s> <Plug>MarkdownPreview
nmap <M-s> <Plug>MarkdownPreviewStop
nmap <C-p> <Plug>MarkdownPreviewToggle<CR>

As suggested, I tried to remove the lines

<Plug>MarkdownPreview
<Plug>MarkdownPreviewStop
<Plug>MarkdownPreviewToggle

but no luck.

iamcco commented 3 years ago

@rstecca

remove

<Plug>MarkdownPreview
<Plug>MarkdownPreviewStop
<Plug>MarkdownPreviewToggle

and restart vim

rstecca commented 3 years ago

I already tried, as I said. If I remove them, CTRL+P does nothing. The same happened to @lpvm

iamcco commented 3 years ago

@rstecca remove those lines and the <CR> of last line