Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to toggle off only if the buffer is readonly #29

Closed
sicr0 opened this issue Sep 11, 2021 · 5 comments
Closed

trying to toggle off only if the buffer is readonly #29

sicr0 opened this issue Sep 11, 2021 · 5 comments

Comments

@sicr0
Copy link

sicr0 commented Sep 11, 2021

To avoid having the plug-in activated in all files except :help buffers or NERDTree I put this snippet in the .vimrc

augroup rainbow
  autocmd!
  autocmd FileType * if &readonly | RainbowParentheses | RainbowParentheses!
augroup END

Unfortunatly I'm not skilled with VimScript and it does not work. Could you please help me?

@sheldond
Copy link

sheldond commented Sep 21, 2021

Hi sicr0,

This might work:

augroup rainbow
  autocmd!
  autocmd FileType * if &readonly | RainbowParentheses! | else | RainbowParentheses | endif
augroup END

Or alternatively this:

augroup rainbow
  autocmd!
  autocmd FileType * RainbowParentheses
  autocmd FileType help,nerdtree RainbowParentheses!
augroup END

@satish-chef
Copy link

I get this error when using this plugin and this snippet on Mac. Can someone please help:

augroup rainbow
  autocmd!
  autocmd FileType * if &readonly | RainbowParentheses! | else | RainbowParentheses | endif
augroup END

Error detected while processing BufRead Autocommands for "*/etc/passwd"..FileType Autocommands for "*":
E492: Not an editor command: RainbowParentheses

@sicr0
Copy link
Author

sicr0 commented Sep 29, 2021

I use this code now and it works partially.

augroup rainbow
  autocmd!
  let ignore = [ 'help', 'nerdtree', 'tagbar' ]
  autocmd WinEnter,BufEnter,BufWinEnter,TabEnter * if index(ignore, &filetype) < 0 | RainbowParentheses | else | RainbowParentheses! | endif
augroup END

It still presents a problem that I cannot solve. When opening NERDTree for the first time it shows square brackets surrounding the icons. If you close and open NERDTree again they disappear. I don't know why but it is a bit annoying.

@sicr0
Copy link
Author

sicr0 commented Sep 29, 2021

I get this error when using this plugin and this snippet on Mac. Can someone please help:

augroup rainbow
  autocmd!
  autocmd FileType * if &readonly | RainbowParentheses! | else | RainbowParentheses | endif
augroup END
Error detected while processing BufRead Autocommands for "*/etc/passwd"..FileType Autocommands for "*":
E492: Not an editor command: RainbowParentheses

Are you sure you have the plugin installed?

@satish-chef
Copy link

@sicr0 I think I have the plugin installed. Below is the output when i run vim +PlugInstall on my Mac:

  Updated. Elapsed time: 0.037616 sec.                         |
  [====]                                                       |~
                                                               |~
  - Finishing ... Done!                                        |~
  - rainbow_parentheses.vim: Already installed                 |~
  - rainbow: Already installed                                 |~
  - vim-go: Already installed                                  |~
  - coc.nvim: Already installed                                |~

Below is the content if my ~/.vimrc file:

" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/autoload')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-default branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'

" Initialize plugin system
call plug#end()

call plug#begin('~/.vim/plugged')

" < Other Plugins, if they exist >

Plug 'fatih/vim-go'
call plug#end()

call plug#begin('~/.vim/plugged')

" < Other Plugins, if they exist >

Plug 'fatih/vim-go'
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}
call plug#end()


" -------------------------------------------------------------------------------------------------
" coc.nvim default settings
" -------------------------------------------------------------------------------------------------

" if hidden is not set, TextEdit might fail.
set hidden
" Better display for messages
set cmdheight=2
" Smaller updatetime for CursorHold & CursorHoldI
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes

" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()

" Use `[c` and `]c` to navigate diagnostics
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)

" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use U to show documentation in preview window
nnoremap <silent> U :call <SID>show_documentation()<CR>

" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)

" Remap for format selected region
vmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)
" Show all diagnostics
nnoremap <silent> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e  :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p  :<C-u>CocListResume<CR>

" disable vim-go :GoDef short cut (gd)
" this is handled by LanguageClient [LC]
let g:go_def_mapping_enabled = 0

Plug 'luochen1990/rainbow'
let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle

Plug 'junegunn/rainbow_parentheses.vim'

let g:rainbow#max_level = 16
let g:rainbow#pairs = [['(', ')'], ['[', ']']]

I searched on google for the error Not an editor command: RainbowParentheses but did not find anything that resolves this issue.

@sicr0 sicr0 closed this as completed Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants