I'm a complete Linux beginner, trying to understand dotfiles. I've got the .vimrc dotfile, and tried to add the following command to the bottom:

" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>

When I run source .vimrc, I get the Unmatched ". error. I assumed that this meant I had to put a fullstop at the end of a double quotation mark. But when I delete the command I've added in, I still get the error - it's a problem with the dotfile I've got.

So my problem is that I don't know how to fix the dotfile, and I don't understand what the " is doing in the dotfile in the first place. I've Googled and searched on SO but not found any answers. It seems like it's being used to mark a comment - but I thought that # was used to mark comments.

What is " being used for in this dotfile, and how can I fix it so that it runs properly?

Here's the dotfile:

" main
syntax enable
set encoding=utf-8
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set smarttab
set number
set showcmd
set bs=2                                        " use backspace in INSERT mode
"set nomodeline                                  " turn off modeline parsing
set cursorline
set autoindent
filetype indent on
filetype on
filetype plugin on
set wildmenu                                    " autocomplete menu
set lazyredraw                                  " redraw only when necessary
set showmatch                                   " highlight matching parentheses
set smartcase
set incsearch                                   " search as char entered
set hlsearch                                    " highlight search matches
nnoremap #<space> :nohlsearch<CR>               " #<space> turn off search hl
set foldenable                                  " enable folding
set foldlevelstart=10                           " open most folds be default
set foldnestmax=10                              " 10 nested fold max
nnoremap <space> za                             " space open/closes fold
set foldmethod=indent                           " fold based on indent level
nnoremap j gj                                   " move down visually
nnoremap k gk                                   " move up visually
nnoremap gV `[v`]                               " highlight latest - ins mode

" status line that shows more information than the default one
" set statusline=%F%m%r%h%w\ [FMT=%{&ff}]\ [T=%Y]\ [HEX=\%02.2B]\ [POS=%04l,%04v\ (%p%%)]\ [lines=%L]
" set laststatus=2

" split
set splitbelow
set splitright

" split nav
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
  • 2
    Welcome to Vi and Vim!
    – D. Ben Knoble
    Commented Aug 17, 2020 at 13:19
  • Welcome! "When I run source .vimrc, I get the Unmatched ". error." Looks to me that you're trying to source it in bash and not in Vim... Is that the case? If so, what you actually need instead is the :source command inside of Vim.
    – filbranden
    Commented Aug 17, 2020 at 14:29

1 Answer 1


Per filbranden's comment, make sure :source .vimrc is a vim command! You don't run .vimrc from a shell (like bash), which will require balanced quotes in scripts.

The first thing to know is that this particular dotfile, the .vimrc, is used to configure vim.

The second thing to know is that vim has one of the most comprehensive help systems I've ever seen: type :help and press Enter to get started.

The third thing to know is that all of vimscript is Ex-commands (also called colon-commands). They are usually documented as :help :somecommand.

With that out of the way, the .vimrc contains vimscript, so we can check :help :", which gets us to :help :quote:

'"' at the start of a line causes the whole line to be ignored.  '"'
after a command causes the rest of the line to be ignored.  This can be used
to add comments.  Example: >
    :set ai     "set 'autoindent' option
It is not possible to add a comment to a shell command ":!cmd" or to the
":map" command and a few others (mainly commands that expect expressions)
that see the '"' as part of their argument:

So the " is a comment in vimscript.

But we also note that we can't have comments after the map command! This is also seen in :help map-comments:

It is not possible to put a comment after these commands, because the '"'
character is considered to be part of the {lhs} or {rhs}. However, one can
use |", since this starts a new, empty command with a comment.

So now we know what the error is: several nnoremap commands have comments after them; but, they can't, due to the way map works. General best practice is to put the comments on a line before the map:

" space opens/closes fold
nnoremap <space> za

As a complete aside: learning to customize vim is a fantastic journey (and welcome to it!). Most experts recommend not copying wholesale other's config; it tends to help your learning more to understand what's being done (e.g., by reading :help) and proceeding with a mix of (a) writing the code you need and (b) copying the bits from others that you like/need.

  • This is all useful and correct, but I don't think it explains the behaviour the OP is seeing. As you've explained, the problem with trying to put a comment at the end of a map is that the characters are instead included in the rhs, but the OP is actually seeing an error message.
    – Rich
    Commented Aug 17, 2020 at 14:34
  • @Rich you may be right, I just saw fil’s comment and am wondering myself.
    – D. Ben Knoble
    Commented Aug 17, 2020 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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