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:
How should I fix this? Should I go through the whole dotfile and add fullstops at the end of each line starting with a "?
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>
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.
Related
In vim, frequently when I perform a ':help ' command, I get an error. Here's an error I see when I perform ':help tags' for example:
"tagsrch.txt.gz" [readonly][noeol] 42L, 11288C
Error detected while processing function gzip#read:
line 51:
E303: Unable to open swap file for "/usr/share/vim/vim74/doc/tagsrch.txt.gz", recovery impossible
41 fewer lines
Press ENTER or type command to continue
When I press enter, the help comes up as desired, but this is still a nuisance. What have I done wrong? My google-foo is apparently too weak for this because I don't see other people complaining about this.
Is this because I have this set for my swap directory?
set directory=~/.vim/swap,.
Let me know if it would be helpful to paste my entire vimrc. I'm on rhel7 with vim 7.4, in case it's helpful.
Here's my ~/.vimrc:
" vim:softtabstop=4:shiftwidth=4:et
" Tab preferences
set shiftwidth=4
set softtabstop=4
set autoindent
set expandtab
execute pathogen#infect()
" Where to store swap files. By default, they will go into ~/.vim/swap, but
" if that doesn't work, they will go in cwd.
set directory=~/.vim/swap,.
filetype plugin indent on " enables filetype indent specific plugins
" Instructions on how to tab complete filenames.
" set wildmode=longest,list,full
set wildmode=longest,list
set wildmenu
" In case there are vim modelines at the top of the file, as there
" is with this one.
set modeline
" Always show the status line.
set laststatus=2
" Look for a tags file.
set tags=./tags,tags;
" Also search for .git/tags files.
set tags^=./.git/tags,*/.git/tags;~
" Make Ctrl-] show the list of options by default.
nnoremap <C-]> g<C-]>
nnoremap <C-w><C-]> <C-w>g<C-]>
" Colors
" Have syntax highlighting in terminals which can display colours:
if has('syntax') && (&t_Co > 2)
syntax on
else
syntax off
endif
set background=dark
set hlsearch
set incsearch
" I so often type teh instead of the.
abbreviate teh the
" To help vim deal with pasting text
:map <F9> :set invpaste <CR>
set pt=<F9>
" Toggle vim's spell checker with <F5>
:map <F5> :setlocal spell! spelllang=en_us<cr>
" Shortcuts for c code.
map! ,bc /* */^[hhi
map! ,bz #if 0^M#endif /* 0 */^[O
" Ignore whitespace when diffing files.
map ,iw :set diffopt+=iwhite<CR>
set path^=/home/bneradt/work/trafficserver/**
In my situation / partition is full. Cleaned it and it works now.
Pressing tab in the command line also just prints out ^] instead of auto completing. My .vimrc file is as follows:
filetype plugin indent on " show existing tab with 4 spaces width
set tabstop=4 " use 4 spaces width for indenting
set shiftwidth=4 " same but when you use tab
set expandtab " use spaces instead of tabs
filetype plugin on " for syntax highlighting
syntax on " syntax highlighting
set number " show line numbers
inoremap jj <Esc>
Also I am running a fairly new install of Arch linux. I have tried in Konsole, XTerm and Termite but return the same results. Thanks in advance.
You need to turn off vi compatibility. inoremap is not available in compatible mode.
Also, I notice that you have filetype plugin on twice. You don't need to do that; you can probably eliminate the second one.
set nocompatible
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab
syntax on
set number
inoremap jj <Esc>
I can't seem to get cursor wrapping to work in vim 7.3. I've tried suggestions found elsewhere, including the following, which have no effect:
:set whichwrap+=<,>
:set whichwrap+=>,l
:set whichwrap+=<,h
Any suggestions? I've included my .vimrc in case there is a conflict...
syntax on
":set whichwrap+=<,h
set whichwrap+=<,>,[,]
colorscheme koehler
noremap <tab> i
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
nnoremap ; :
nnoremap : ;
set more " use more prompt
set autoread " watch for file changes
set number " line numbers
set noautowrite " don't automagically write on :next
set lazyredraw " don't redraw when don't have to
set showmode
set showcmd
set nocompatible " vim, not vi
set autoindent smartindent " auto/smart indent
set smarttab " tab and backspace are smart
set tabstop=4 " 6 spaces
set shiftwidth=2
set scrolloff=5 " keep at least 5 lines above/below
set sidescrolloff=5 " keep at least 5 lines left/right
set history=200
set backspace=indent,eol,start
set linebreak
set cmdheight=2 " command line two lines high
set undolevels=1000 " 1000 undos
set updatecount=100 " switch every 100 chars
set complete=.,w,b,u,U,t,i,d " do lots of scanning on tab completion
set noerrorbells " No error bells please
set visualbell t_vb= " and don't make faces
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
filetype plugin on " Enable filetype-specific plugins
set wildmode=longest:full
set wildmenu " menu has tab completion
set laststatus=2
set incsearch " incremental search
set ignorecase " search ignoring case
set hlsearch " highlight the search
set showmatch " show matching bracket
set diffopt=filler,iwhite " ignore all whitespace and sync
if v:version >= 700
" Enable spell check for text files
autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en
endif
" mappings
" toggle list mode
nmap <LocalLeader>tl :set list!<cr>
" toggle paste mode
nmap <LocalLeader>pp :set paste!<cr>
The following line in your .vimrc is a conflict. Commenting out that line will probably fix the issue.
set nocompatible " vim, not vi
And for automatic wrap, I suggest you use this one and use more of h and l than the left & right arrow keys:
set whichwrap+=<,>,h,l,[,]
The issue is putting set nocompatible in the middle of your vimrc (I made the same mistake).
Actually nocompatible is set when a vimrc is detected, but set nocompatible has a side effect of resetting all options to default.
From :help nocompatible:
This is a special kind of option, because when it's set or reset, other options are also changed as a side effect.
NOTE: Setting or resetting this option can have a lot of unexpected
effects: Mappings are interpreted in another way, undo behaves
differently, etc. If you set this option in your vimrc file, you
should probably put it at the very start.
I used the following to make saving saving faster in Vim:
nnoremap <leader>w :w!<cr>
inoremap <leader>w <esc>:w!<cr>
Something strange happens with the first one, though, each time I save there is like a 2-second delay. I think this is strange since it is set as nnoremap and there isn't another mapping pointing to w.
What could be the problem?
My .virmc:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer: Alexandro Chen
" Website: http://alexandrochen.com
" Version: 0.1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Basic
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700
filetype plugin on
filetype indent on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Appareance
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable
colorscheme molokai
set guifont=Droid\ Sans\ Mono\ 10
set encoding=utf8
set number
set ruler
set magic
set nolazyredraw
set showmatch
" Sets initial window size
set lines=40 columns=160
set softtabstop=2
set shiftwidth=2
set tabstop=2
set expandtab
set guioptions-=r " Disable right scrollbar
set guioptions-=R
set guioptions-=l " Disable left scrollbar
set guioptions-=L
set t_Co=256
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mapping
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader = ","
nnoremap <leader>w :w!<cr>
inoremap <leader>w <esc>:w!<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
nnoremap <leader>ev :split $MYVIMRC<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Files
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nobackup
set nowb
set noswapfile
autocmd FileType ruby,coffeescript autocmd BufWritePre <buffer> :%s/\s\+$//e
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Workarounds
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:session_autoload = 'no'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDTree
au VimEnter * NERDTree /home/alex/
" Zen Coding
let g:user_zen_expandabbr_key = '<leader>e'
So, when you comment out
inoremap <leader>w <esc>:w!<cr>
you still have a problem with the first one?
Also, :help ttimeoutlen
'ttimeoutlen' 'ttm' number (default -1)
The time in milliseconds that is waited for a key code or mapped
key sequence to complete.
I have set ttimeoutlen=10 in my .vimrc
Also, I've played with save mappings for a while, and finally mapped
save on space bar. Very happy with it.
I think you had better to remove the inoremap <leader>w <esc>:w!<cr>, and add inoremap jk <esc>,everytime you want to save file, you had better to return normal mode and save it.Or when you press ,word, vim will regard ,w to save file.
I am currently using VIM in the terminal and have perfect syntax highlighting happening. But then when I try to use gvim no matter what type of file or how many times I type: ":syntax on" I don't get any syntax highlighting. Any ideas anyone?
Thank you.
Here is my .vimrc for those who are interested:
" Turn on pathogen for all plug-ins installed after 9/13/2010
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
" My color theme for vim
colors sorcerer
" Disable line wrapping for now
set nowrap
" Enable the mouse even when vi is used in the terminal
set mouse=a
" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'
" This shows what you are typing as a command. I love this!
set showcmd
" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')
"Fix Vim's regex...
nnoremap / /\v
vnoremap / /\v
" Gimme some breathing room at the bottom please...
set scrolloff=5
" makes vim usable with screen
set restorescreen
" Disable the arrow keys... helps the learning
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
"Kill error bells
set noerrorbells
set visualbell
set t_vb=
" Turn on spell check
" set spell
" Thesaurus!!
set thesaurus+=/usr/share/myspell/dicts/mthesaur.txt
" Some NERDTree love
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
let NERDTreeShowBookmarks=1
let NERDTreeQuitOnOpen=1
let NERDTreeHighlightCursorline=1
let NERDTreeShowFiles=1
let NERDTreeShowHidden=1
" Make swapping windows easier...
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Allow for buffers to be hidden so that they need not be closed to go to
" another file
set hidden
" Turn on incremental search
set incsearch
set smartcase
" Long history is long
set history=1000
set undolevels=1000
" No need for a vi backup file
set nobackup
" Colors!!
set t_Co=256
" Compatibility
set nocompatible
set formatprg=par
" Syntastic!!
let g:syntastic_enable_signs=1
let g:syntastic_auto_loclist=1
let g:syntastic_quiet_warnings=0
" For soft wrapping text
command! -nargs=* Wrap set wrap linebreak nolist
set showbreak=…
" Sandro spacing preferences here
set number
set expandtab
set autoindent
set smartindent
set softtabstop=4
set shiftwidth=4
set shiftround
" Sandro key mapping here
map <F2> :NERDTreeToggle<CR>
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
set showmode "show current mode down the bottom
"Setting the status line...
set statusline=%f "tail of the filename
"display a warning if the file format isn't Unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*
"display a warning if file encoding isn't UTf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*
set statusline+=%h "help file flag
set statusline+=%y "filetype
set statusline+=%r "read only flag
set statusline+=%m "modified flag
"Syntastic!!
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" Auto completion options
set wildmode=list:longest "Change tab completion to be like Bash's
set wildignore=*.o,*.obj,*~,*.swp,*.pyc "Files to ignore on auto complete
"display tabs and trailing spaces
set list
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\•,extends:»,precedes:«,trail:•
let g:pydiction_location='~/.vim/after/ftplugin/pydiction/complete-dict'
set sm
set ai
let java_highlight_all=1
let java_highlight_functions="style"
let java_allow_cpp_keywords=1
set tags=~/.tags
set complete=.,w,b,u,t,i
command W w !sudo tee % > /dev/null
" IMPORTANT: win32 users will need to have 'shell slash' set so that latex
" can be called correctly.
"set shell slash
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
"set grepprg=grep\ -nH\ $*
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
" let g:tex_flavor='latex'
filetype on " enables filetype detection
filetype plugin on " enables filetype specific plug-ins
syntax on
filetype indent on " OPTIONAL: This enables automatic indentation as you type.
" VIM 7.3 features here...
if v:version >= 703
set relativenumber
set undofile
endif
Use :let g:colors_name to see the name of the colourscheme that has been loaded, the value should be 'sorcerer', if it's not then something has gone seriously wrong
Type :hi Operator, you 'xxx' part should be coloured and you should see guifg=<color> in the output.
Put a new line at the top of your .vimrc containing just the word "finish", this will stop vim processing your .vimrc. Using :colors default and :syntax on should be enough to get syntax highlighting turned on. If this works then just move the finish line down through your .vimrc until you find the section that is breaking syntax highlighting.
On windows, gVim uses a file called _vimrc, so check for that as well.
When you type :version in gvim do you see +syntax listed in your features list?
Try comparing that to your regular Vim version. Maybe your gvim build didn't include the syntax highlighting feature.
The issue was fixed once I finally figured out how to get gvim 7.3. Then the syntax highlighting magically came.
Building on Thien's response, I also had the same experience (set syntax=on fails, the menu options succeed but only until Vim is restarted).
The menu option apparently triggers :syn=on, and adding that to _vimrc does enable syntax highlighting persistently where set syntax=on did not. I'll leave it to someone with more experience to explain the difference between those two.
set syntax=xxx was not working for me in gvim 7.3 on Windows XP although it did for vim in cygwin. To get syntax highlighting I had to go to Menu > Syntax > Show filetypes in menu > select syntax. I guess the menu command and the vim commands don't do the same thing with gvim on Windows.