if (&filetype=='c' || &filetype=='cpp' || &filetype=='h')
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
" class outline viewer : F8
nmap <F8> :TagbarToggle<CR>
endif
I tried this vimrc script, but it is not working.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityif (&filetype=='c' || &filetype=='cpp' || &filetype=='h')
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
" class outline viewer : F8
nmap <F8> :TagbarToggle<CR>
endif
I tried this vimrc script, but it is not working.
Not sure but I think VimEnter
is called before &filetype
is set so that if
is never executed. Try:
augroup C
autocmd!
autocmd FileType c,cpp NERDTree | wincmd p | nmap <F8> :TagbarToggle<CR>
augroup END
Better to write an filetype plugin (see :h ftplugin
). For example I have a file in ~/.config/nvim/after/ftplugin/javascript.vim
with this content:
autocmd BufReadPost,BufWritePost <buffer> Accio eslint
autocmd InsertLeave,TextChanged <buffer> call semhl#highlight()
autocmd FileType javascript call semhl#highlight()
nnoremap <buffer> <C-]> :TernDef<cr>
These auto-commands and the mapping are only available for JavaScript files. I don't know how to call an ftplugin
for both C and C++, but the content would be something like:
autocmd FileType c,cpp NERDTree | wincmd p
nmap <buffer> <F8> :TagbarToggle<CR>
If you use Vim the location of this file would be ~/.vim/after/ftplugin/c.vim
.
According to this answer you can use symbolic links or source your c.vim
ftplugin from your cpp.vim
plugin (or vice versa).