Search code examples
vimdotfiles

Unmatched ". in dotfile - what is the function of " in dotfiles?


I recently ran into this answer when trying to remove highlighting from Vim, after pressing the # key accidentally. I followed the user's code and entered this at the bottom of my .vimrc file:

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

I exited Vim, and ran source vimrc

And it returned the following error:

Unmatched ".

So I take this to mean that double quotes need a corresponding fullstop afterwards at the end of the line, as the user has done. But I'm looking through my .vimrc and none of the "s have matching fullstops. Indeed, when I deleted the line I inserted and tried to run source vimrc, it still returned an Unmatched ". error. Here's an example:

" 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

And another:

" 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>

My problem here is that I don't understand the function of " here, and haven't been able to find any information from Googling or searching previous SO questions. It seems to be used like a comment, but I thought that # was used for comments. I'm a complete Linux beginner - I don't know what the correct syntax is to fix the dotfile, if it needs fixing.

So my question is twofold:

  1. How should I fix this? Should I go through the whole dotfile and add fullstops at the end of each line starting with a "?

  2. What is the function of " anyway?

I'm using TCSH, I believe.

EDIT: 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>

Solution

  • You seem to confuse shell dot files with your .vimrc. Shells source shell dotfiles, while vim sources a vimrc. Shells don't understand vimrc notation, in particular, " introduces a comment for vim, while it starts a double quoted word in the shell. The shell expects double quotes to come in pairs, that's why you get the Unmatched ".

    In other words, don't tell the shell to source .vimrc, simply start vim and it will automagically source the $HOME/.vimrc for you, because that feature is built into vim.

    If you change .vimrc from within vim (and why would you use another editor?) then you can source it without exiting vim by typing :source ~/.vimrc and make the changes take effect.