I am trying to create my own C++ environment inside of VIM.

So far, this is my setup when I run $ vim ~/shape.cpp: for example:

enter image description here

As you can see, only NERDTree has full syntax highlighting (which isn't too important) and the .cpp only has limited header colours (should be different) and none on the hpp file.

How can I get syntax to work on my c++ file with this setup?

If I do not create the header window, syntax highlighting does work as shown below:

enter image description here

Also the following information may help as it may affect configuration.

  • This machine is running macOS
  • Tmux is used to create the bottom window
  • The top section is one pane and three vim vertical splits
  • I am using a.vim to create the .hpp split

The vimrc does the following:

  1. Creates the NERDTree window
  2. Goes to the second pane (NERDTree is the first window)
  3. Executes a.vim command :AV which creates a vertical splits and switches. This opens .hpp in the second window and .cpp in third
  4. Resizes window one (cpp) to 50 width
  5. Swaps hpp and cpp around so the order is now NERDTree, cpp, hpp

Finally, here is my vimrc:

set nocompatible              " be iMproved, required
filetype off                  " required

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'

Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Plugin 'dart-lang/dart-vim-plugin'

Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
Plugin 'vim-scripts/a.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'altercation/vim-colors-solarized'

"Optional:
Plugin 'honza/vim-snippets'

call vundle#end()            " required
syntax on
filetype plugin indent on    " required
filetype on
let g:solarized_termcolors = 256
colorscheme solarized

set number

set tabstop=2
set shiftwidth=2
set expandtab

autocmd FileType python setlocal noexpandtab shiftwidth=2 softtabstop=2

set background=dark

let mapleader = ":"

"Map keys to create new window
nmap nvw <c-w>v
nmap nhw <c-w>s

"Mak keys to change window
nmap + <C-w><Up>
nmap = <C-w><Down>
nmap _ <C-w><Left>
nmap - <C-w><Right>

"Map key to Open NERDTree
map <leader>fs :NERDTreeToggle<CR>

"Close VIM if NERDTree is final window
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

"Run NERDTree automaticly on VIM start
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd l
autocmd VimEnter * normal <C-w>l
autocmd FileType cpp :AV
autocmd FileType cpp 50 wincmd |
autocmd FileType cpp wincmd x

Edit: Output of :syntax:

--- Syntax items ---
confTodo       xxx contained XXX FIXME TODO
                   links to Todo
confComment    xxx match /^#.*/  contains=confTodo
                   match /\s#.*/ms=s+1  contains=confTodo
                   links to Comment
confString     xxx start=/"/ skip=/\\\\\|\\"/ end=/"/  oneline
                   start=/'/ skip=/\\\\\|\\'/ end=/'/  oneline
                   links to String

And of :highlight:

SpecialKey     xxx term=bold cterm=bold ctermfg=240 ctermbg=235 guifg=Cyan
EndOfBuffer    xxx links to NonText
NonText        xxx term=bold cterm=bold ctermfg=240 gui=bold guifg=Blue
Directory      xxx ctermfg=33 guifg=Cyan
ErrorMsg       xxx term=reverse cterm=reverse ctermfg=124 guifg=White guibg=Red
IncSearch      xxx term=standout cterm=standout ctermfg=166 gui=reverse
Search         xxx term=reverse cterm=reverse ctermfg=136 guifg=Black guibg=Yellow
MoreMsg        xxx ctermfg=33 gui=bold guifg=SeaGreen
ModeMsg        xxx ctermfg=33 gui=bold
LineNr         xxx ctermfg=239 ctermbg=235 guifg=Yellow
CursorLineNr   xxx term=bold ctermfg=11 gui=bold guifg=Yellow
Question       xxx term=bold cterm=bold ctermfg=37 gui=bold guifg=Green
StatusLine     xxx term=reverse cterm=reverse ctermfg=245 ctermbg=235 gui=bold,reverse
StatusLineNC   xxx term=reverse cterm=reverse ctermfg=240 ctermbg=235 gui=reverse
VertSplit      xxx ctermfg=240 ctermbg=240 gui=reverse
Title          xxx term=bold cterm=bold ctermfg=166 gui=bold guifg=Magenta
Visual         xxx term=reverse cterm=reverse ctermfg=239 ctermbg=234 guibg=DarkGrey
VisualNOS      xxx term=reverse cterm=reverse ctermbg=235
WarningMsg     xxx term=bold cterm=bold ctermfg=124 guifg=Red
WildMenu       xxx term=reverse cterm=reverse ctermfg=187 ctermbg=235 guifg=Black guibg=Yellow
Folded         xxx term=bold,underline cterm=bold,underline ctermfg=244 ctermbg=235 guifg=Cyan guibg=DarkGrey
FoldColumn     xxx ctermfg=244 ctermbg=235 guifg=Cyan guibg=Grey
DiffAdd        xxx ctermfg=64 ctermbg=235 guibg=DarkBlue
DiffChange     xxx ctermfg=136 ctermbg=235 guibg=DarkMagenta
DiffDelete     xxx ctermfg=124 ctermbg=235 gui=bold guifg=Blue guibg=DarkCyan
DiffText       xxx ctermfg=33 ctermbg=235 gui=bold guibg=Red
SignColumn     xxx ctermfg=244 ctermbg=242 guifg=Cyan guibg=Grey
Conceal        xxx ctermfg=33
SpellBad       xxx term=undercurl cterm=undercurl gui=undercurl guisp=Red
SpellCap       xxx term=undercurl cterm=undercurl gui=undercurl guisp=Blue
SpellRare      xxx term=undercurl cterm=undercurl gui=undercurl guisp=Magenta
SpellLocal     xxx term=undercurl cterm=undercurl gui=undercurl guisp=Cyan
Pmenu          xxx term=reverse cterm=reverse ctermfg=244 ctermbg=235 guibg=Magenta
PmenuSel       xxx term=reverse cterm=reverse ctermfg=239 ctermbg=187 guibg=DarkGrey
PmenuSbar      xxx term=reverse cterm=reverse ctermfg=187 ctermbg=244 guibg=Grey
PmenuThumb     xxx term=reverse cterm=reverse ctermfg=244 ctermbg=234 guibg=White
TabLine        xxx term=underline cterm=underline ctermfg=244 ctermbg=235 gui=underline guibg=DarkGrey
TabLineSel     xxx term=underline,reverse cterm=underline,reverse ctermfg=239 ctermbg=187 gui=bold
TabLineFill    xxx term=underline cterm=underline ctermfg=244 ctermbg=235 gui=reverse
CursorColumn   xxx ctermbg=235 guibg=Grey40
CursorLine     xxx ctermbg=235 guibg=Grey40
ColorColumn    xxx ctermbg=235 guibg=DarkRed
QuickFixLine   xxx links to Search
StatusLineTerm xxx cleared
StatusLineTermNC xxx cleared
MatchParen     xxx term=bold cterm=bold ctermfg=124 ctermbg=239 guibg=DarkCyan
ToolbarLine    xxx term=underline ctermbg=242 guibg=Grey50
ToolbarButton  xxx cterm=bold ctermfg=0 ctermbg=7 gui=bold guifg=Black guibg=LightGrey
Error          xxx term=bold cterm=bold ctermfg=124 guifg=White guibg=Red
Comment        xxx ctermfg=239 guifg=#80a0ff
Constant       xxx ctermfg=37 guifg=#ffa0a0
Special        xxx ctermfg=124 guifg=Orange
Identifier     xxx ctermfg=33 guifg=#40ffff
Statement      xxx ctermfg=64 gui=bold guifg=#ffff60
PreProc        xxx ctermfg=166 guifg=#ff80ff
Type           xxx ctermfg=136 gui=bold guifg=#60ff60
Underlined     xxx ctermfg=61 gui=underline guifg=#80a0ff
Ignore         xxx guifg=bg
Todo           xxx term=bold cterm=bold ctermfg=125 guifg=Blue guibg=Yellow
String         xxx links to Constant
Character      xxx links to Constant
Number         xxx links to Constant
Boolean        xxx links to Constant
Float          xxx links to Number
Function       xxx links to Identifier
Conditional    xxx links to Statement
Repeat         xxx links to Statement
Label          xxx links to Statement
Operator       xxx links to Statement
Keyword        xxx links to Statement
Exception      xxx links to Statement
Include        xxx links to PreProc
Define         xxx links to PreProc
Macro          xxx links to PreProc
PreCondit      xxx links to PreProc
StorageClass   xxx links to Type
Structure      xxx links to Type
Typedef        xxx links to Type
Tag            xxx links to Special
SpecialChar    xxx links to Special
Delimiter      xxx links to Special
SpecialComment xxx links to Special
Debug          xxx links to Special
Normal         xxx ctermfg=244 ctermbg=234
Cursor         xxx ctermfg=234 ctermbg=244
lCursor        xxx links to Cursor
vimVar         xxx links to Identifier
vimFunc        xxx links to Function
vimUserFunc    xxx links to Function
helpSpecial    xxx links to Special
vimSet         xxx links to Normal
vimSetEqual    xxx links to Normal
vimCommentString xxx ctermfg=61
vimCommand     xxx ctermfg=136
vimCmdSep      xxx term=bold cterm=bold ctermfg=33
helpExample    xxx ctermfg=245
helpOption     xxx ctermfg=37
helpNote       xxx ctermfg=125
helpVim        xxx ctermfg=125
helpHyperTextJump xxx term=underline cterm=underline ctermfg=33
helpHyperTextEntry xxx ctermfg=64
vimIsCommand   xxx ctermfg=240
vimSynMtchOpt  xxx ctermfg=136
vimSynType     xxx ctermfg=37
vimHiLink      xxx ctermfg=33
vimHiGroup     xxx ctermfg=33
vimGroup       xxx term=bold,underline cterm=bold,underline ctermfg=33
diffAdded      xxx links to Statement
diffLine       xxx links to Identifier
gitcommitComment xxx ctermfg=239
gitcommitUntracked xxx links to gitcommitComment
gitcommitDiscarded xxx links to gitcommitComment
gitcommitSelected xxx links to gitcommitComment
gitcommitUnmerged xxx term=bold cterm=bold ctermfg=64
gitcommitOnBranch xxx term=bold cterm=bold ctermfg=239
gitcommitBranch xxx term=bold cterm=bold ctermfg=125
gitcommitNoBranch xxx links to gitcommitBranch
gitcommitDiscardedType xxx ctermfg=124
gitcommitSelectedType xxx ctermfg=64
gitcommitHeader xxx ctermfg=239
gitcommitUntrackedFile xxx term=bold cterm=bold ctermfg=37
gitcommitDiscardedFile xxx term=bold cterm=bold ctermfg=124
gitcommitSelectedFile xxx term=bold cterm=bold ctermfg=64
gitcommitUnmergedFile xxx term=bold cterm=bold ctermfg=136
gitcommitFile  xxx term=bold cterm=bold ctermfg=244
gitcommitDiscardedArrow xxx links to gitcommitDiscardedFile
gitcommitSelectedArrow xxx links to gitcommitSelectedFile
gitcommitUnmergedArrow xxx links to gitcommitUnmergedFile
htmlTag        xxx ctermfg=239
htmlEndTag     xxx ctermfg=239
htmlTagN       xxx term=bold cterm=bold ctermfg=245
htmlTagName    xxx term=bold cterm=bold ctermfg=33
htmlSpecialTagName xxx ctermfg=33
htmlArg        xxx ctermfg=240
javaScript     xxx ctermfg=136
perlHereDoc    xxx ctermfg=245 ctermbg=234
perlVarPlain   xxx ctermfg=136 ctermbg=234
perlStatementFileDesc xxx ctermfg=37 ctermbg=234
texStatement   xxx ctermfg=37 ctermbg=234
texMathZoneX   xxx ctermfg=136 ctermbg=234
texMathMatcher xxx ctermfg=136 ctermbg=234
texRefLabel    xxx ctermfg=136 ctermbg=234
rubyDefine     xxx term=bold cterm=bold ctermfg=245 ctermbg=234
cPreCondit     xxx ctermfg=166
VarId          xxx ctermfg=33
ConId          xxx ctermfg=136
hsImport       xxx ctermfg=125
hsString       xxx ctermfg=240
hsStructure    xxx ctermfg=37
hs_hlFunctionName xxx ctermfg=33
hsStatement    xxx ctermfg=37
hsImportLabel  xxx ctermfg=37
hs_OpFunctionName xxx ctermfg=136
hs_DeclareFunction xxx ctermfg=166
hsVarSym       xxx ctermfg=37
hsType         xxx ctermfg=136
hsTypedef      xxx ctermfg=37
hsModuleName   xxx term=underline cterm=underline ctermfg=64
hsModuleStartLabel xxx ctermfg=125
                   links to hsStructure
hsImportParams xxx links to Delimiter
hsDelimTypeExport xxx links to Delimiter
hsModuleWhereLabel xxx links to hsModuleStartLabel
hsNiceOperator xxx ctermfg=37
pandocTitleBlock xxx ctermfg=33
pandocTitleBlockTitle xxx term=bold cterm=bold ctermfg=33
pandocTitleComment xxx term=bold cterm=bold ctermfg=33
pandocComment  xxx ctermfg=239
pandocVerbatimBlock xxx ctermfg=136
pandocVerbatimBlockDeep xxx links to pandocVerbatimBlock
pandocCodeBlock xxx links to pandocVerbatimBlock
pandocCodeBlockDelim xxx links to pandocVerbatimBlock
pandocBlockQuote xxx ctermfg=33
pandocBlockQuoteLeader1 xxx ctermfg=33
pandocBlockQuoteLeader2 xxx ctermfg=37
pandocBlockQuoteLeader3 xxx ctermfg=136
pandocBlockQuoteLeader4 xxx ctermfg=124
pandocBlockQuoteLeader5 xxx ctermfg=244
pandocBlockQuoteLeader6 xxx ctermfg=239
pandocListMarker xxx ctermfg=125
pandocListReference xxx term=underline cterm=underline ctermfg=125
pandocDefinitionBlock xxx ctermfg=61
pandocDefinitionTerm xxx term=standout cterm=standout ctermfg=61
pandocDefinitionIndctr xxx term=bold cterm=bold ctermfg=61
pandocEmphasisDefinition xxx ctermfg=61
pandocEmphasisNestedDefinition xxx term=bold cterm=bold ctermfg=61
pandocStrongEmphasisDefinition xxx term=bold cterm=bold ctermfg=61
pandocStrongEmphasisNestedDefinition xxx term=bold cterm=bold ctermfg=61
pandocStrongEmphasisEmphasisDefinition xxx term=bold cterm=bold ctermfg=61
pandocStrikeoutDefinition xxx term=reverse cterm=reverse ctermfg=61
pandocVerbatimInlineDefinition xxx ctermfg=61
pandocSuperscriptDefinition xxx ctermfg=61
pandocSubscriptDefinition xxx ctermfg=61
pandocTable    xxx ctermfg=33
pandocTableStructure xxx ctermfg=33
pandocTableStructureTop xxx links to pandocTableStructre
pandocTableStructre xxx cleared
pandocTableStructureEnd xxx links to pandocTableStructre
pandocTableZebraLight xxx ctermfg=33 ctermbg=234
pandocTableZebraDark xxx ctermfg=33 ctermbg=235
pandocEmphasisTable xxx ctermfg=33
pandocEmphasisNestedTable xxx term=bold cterm=bold ctermfg=33
pandocStrongEmphasisTable xxx term=bold cterm=bold ctermfg=33
pandocStrongEmphasisNestedTable xxx term=bold cterm=bold ctermfg=33
pandocStrongEmphasisEmphasisTable xxx term=bold cterm=bold ctermfg=33
pandocStrikeoutTable xxx term=reverse cterm=reverse ctermfg=33
pandocVerbatimInlineTable xxx ctermfg=33
pandocSuperscriptTable xxx ctermfg=33
pandocSubscriptTable xxx ctermfg=33
pandocHeading  xxx term=bold cterm=bold ctermfg=166
pandocHeadingMarker xxx term=bold cterm=bold ctermfg=136
pandocEmphasisHeading xxx term=bold cterm=bold ctermfg=166
pandocEmphasisNestedHeading xxx term=bold cterm=bold ctermfg=166
pandocStrongEmphasisHeading xxx term=bold cterm=bold ctermfg=166
pandocStrongEmphasisNestedHeading xxx term=bold cterm=bold ctermfg=166
pandocStrongEmphasisEmphasisHeading xxx term=bold cterm=bold ctermfg=166
pandocStrikeoutHeading xxx term=reverse cterm=reverse ctermfg=166
pandocStrikeoutHeading xxx term=reverse cterm=reverse ctermfg=166
pandocVerbatimInlineHeading xxx term=bold cterm=bold ctermfg=166
pandocSuperscriptHeading xxx term=bold cterm=bold ctermfg=166
pandocSubscriptHeading xxx term=bold cterm=bold ctermfg=166
pandocLinkDelim xxx ctermfg=239
pandocLinkLabel xxx term=underline cterm=underline ctermfg=33
pandocLinkText xxx term=bold,underline cterm=bold,underline ctermfg=33
pandocLinkURL  xxx term=underline cterm=underline ctermfg=240
pandocLinkTitle xxx term=underline cterm=underline ctermfg=240
pandocLinkTitleDelim xxx term=underline cterm=underline ctermfg=239
pandocLinkDefinition xxx term=underline cterm=underline ctermfg=37
pandocLinkDefinitionID xxx term=bold cterm=bold ctermfg=33
pandocImageCaption xxx term=bold,underline cterm=bold,underline ctermfg=61
pandocFootnoteLink xxx term=underline cterm=underline ctermfg=64
pandocFootnoteDefLink xxx term=bold cterm=bold ctermfg=64
pandocFootnoteInline xxx term=bold,underline cterm=bold,underline ctermfg=64
pandocFootnote xxx ctermfg=64
pandocCitationDelim xxx ctermfg=125
pandocCitation xxx ctermfg=125
pandocCitationID xxx term=underline cterm=underline ctermfg=125
pandocCitationRef xxx ctermfg=125
pandocStyleDelim xxx ctermfg=239
pandocEmphasis xxx ctermfg=244
pandocEmphasisNested xxx term=bold cterm=bold ctermfg=244
pandocStrongEmphasis xxx term=bold cterm=bold ctermfg=244
pandocStrongEmphasisNested xxx term=bold cterm=bold ctermfg=244
pandocStrongEmphasisEmphasis xxx term=bold cterm=bold ctermfg=244
pandocStrikeout xxx term=reverse cterm=reverse ctermfg=239
pandocVerbatimInline xxx ctermfg=136
pandocSuperscript xxx ctermfg=61
pandocSubscript xxx ctermfg=61
pandocRule     xxx term=bold cterm=bold ctermfg=33
pandocRuleLine xxx term=bold cterm=bold ctermfg=33
pandocEscapePair xxx term=bold cterm=bold ctermfg=124
pandocNonBreakingSpace xxx term=reverse cterm=reverse ctermfg=124
pandocEscapedCharacter xxx links to pandocEscapePair
pandocLineBreak xxx links to pandocEscapePair
pandocMetadataDelim xxx ctermfg=239
pandocMetadata xxx term=bold cterm=bold ctermfg=33
pandocMetadataKey xxx ctermfg=33
pandocMetadataTitle xxx links to pandocMetadata
cStatement     xxx links to Statement
cLabel         xxx links to Label
cConditional   xxx links to Conditional
cRepeat        xxx links to Repeat
cTodo          xxx links to Todo
cBadContinuation xxx links to Error
cSpecial       xxx links to SpecialChar
cFormat        xxx links to cSpecial
cString        xxx links to String
cCppString     xxx links to cString
cSpaceError    xxx links to cError
cCppSkip       xxx cleared
cCharacter     xxx links to Character
cSpecialError  xxx links to cError
cSpecialCharacter xxx links to cSpecial
cBadBlock      xxx cleared
cCurlyError    xxx links to cError
cErrInParen    xxx links to cError
cCppParen      xxx cleared
cErrInBracket  xxx links to cError
cCppBracket    xxx cleared
cBlock         xxx cleared
cParenError    xxx links to cError
cIncluded      xxx links to cString
cCommentSkip   xxx links to cComment
cCommentString xxx links to cString
cComment2String xxx links to cString
cCommentStartError xxx links to cError
cUserLabel     xxx links to Label
cBitField      xxx cleared
cOctalZero     xxx links to PreProc
cNumber        xxx links to Number
cFloat         xxx links to Float
cOctal         xxx links to Number
cOctalError    xxx links to cError
cNumbersCom    xxx cleared
cParen         xxx cleared
cBracket       xxx cleared
cNumbers       xxx cleared
cCommentL      xxx links to cComment
cCommentStart  xxx links to cComment
cComment       xxx links to Comment
cCommentError  xxx links to cError
cOperator      xxx links to Operator
cType          xxx links to Type
cStructure     xxx links to Structure
cStorageClass  xxx links to StorageClass
cConstant      xxx links to Constant
cPreConditMatch xxx links to cPreCondit
cCppInIf       xxx cleared
cCppInElse     xxx cleared
cCppInElse2    xxx links to cCppOutIf2
cCppOutIf      xxx cleared
cCppOutIf2     xxx links to cCppOut
cCppOutElse    xxx cleared
cCppInSkip     xxx cleared
cCppOutSkip    xxx links to cCppOutIf2
cCppOutWrapper xxx links to cPreCondit
cCppInWrapper  xxx links to cCppOutWrapper
cPreProc       xxx links to PreProc
cInclude       xxx links to Include
cDefine        xxx links to Macro
cMulti         xxx cleared
cUserCont      xxx cleared
cError         xxx links to Error
cCppOut        xxx links to Comment
cppStatement   xxx links to Statement
cppAccess      xxx links to cppStatement
cppModifier    xxx links to Type
cppType        xxx links to Type
cppExceptions  xxx links to Exception
cppOperator    xxx links to Operator
cppCast        xxx links to cppStatement
cppStorageClass xxx links to StorageClass
cppStructure   xxx links to Structure
cppBoolean     xxx links to Boolean
cppConstant    xxx links to Constant
cppRawStringDelimiter xxx links to Delimiter
cppRawString   xxx links to String
cppNumber      xxx links to Number
cppMinMax      xxx cleared
confTodo       xxx links to Todo
confComment    xxx links to Comment
confString     xxx links to String
NERDTreeIgnore xxx links to Ignore
NERDTreeUp     xxx links to Directory
NERDTreeHelpKey xxx links to Identifier
NERDTreeHelpTitle xxx links to Macro
NERDTreeToggleOn xxx links to Question
NERDTreeToggleOff xxx links to WarningMsg
NERDTreeHelpCommand xxx links to Identifier
NERDTreeHelp   xxx links to String
NERDTreeDir    xxx links to Directory
NERDTreeFile   xxx links to Normal
NERDTreeLinkTarget xxx links to Type
NERDTreeLinkFile xxx links to Macro
NERDTreeLinkDir xxx links to Macro
NERDTreeDirSlash xxx links to Identifier
NERDTreeClosable xxx links to Directory
NERDTreeOpenable xxx links to Directory
NERDTreeRO     xxx links to WarningMsg
NERDTreeBookmark xxx links to Normal
NERDTreeExecFile xxx links to Title
NERDTreeLink   xxx cleared
NERDTreeFlags  xxx links to Number
And a few others that belong to nerd tree.
  • If you remove all but NerdTree and a.vim, does this still happen? What about without nerdtree? Is the filetype of both buffers set correctly? What is the output of :syntax and :highlight ? This additional information could help tremendously. Also check :scriptnames. – D. Ben Knoble Nov 10 at 22:10
  • @D.BenKnoble added the info. Also if I remove all plugins but NERDTree and a.vim, I still get the same issue. – iProgram Nov 10 at 22:28
  • @D.BenKnoble This also happens outside of tmux too. – iProgram Nov 10 at 22:31
  • From that syntax output, it looks like vim doesnt recognize your files as cpp and hpp, but as conf files. Not sure why, but that’s the issue. – D. Ben Knoble Nov 10 at 22:36
  • @D.BenKnoble Strange. How would I fix this? – iProgram Nov 10 at 22:42
up vote 2 down vote accepted

What you are doing here is a little bit "catch-22".

A autocmd is calling :AV which loads a file. This again triggers auto commands. By default this is disabled. See :help autocmd-nested. You could enable nested autocmd by using:

autocmd FileType cpp nested :AV

Unfortunately this triggers a error in a.vim, which is solvable. But this doesn't help, as the real problem is the cascade of autocmds. As soon as the hpp file is opened it again triggers the autocmd for the FileType cpp. Not what you want.

I played around and found the following workaround (I don't want to call it "solution"):

let g:DoingCppSplit=0
function CppSplit()
    if (g:DoingCppSplit == 0)
        let g:DoingCppSplit = 1
        AV
        vertical resize 50
        wincmd x
        let g:DoingCppSplit = 0
    endif
endfunction

autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd l
autocmd FileType cpp nested :call CppSplit()

This just handles your described situation. Play around with it. Maybe it is better to trigger the function on the event BufEnter. Like:

autocmd BufEnter *.cpp nested :call CppSplit()
New contributor
Ralf is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • I might be wrong, but the parens in your if statement are unnecessary. Also, stand vimscript indentation is usually two spaces. – D. Ben Knoble 2 days ago
  • 1
    Yes, the parent are superfluous. Indent is a personal choice, I use 4 chars by default. – Ralf 2 days ago

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.