Vim opens with a 'c' pressed - vim

When I open vim, I have to press the esc key before working w/ what is in the file because it assumes a 'c' was pressed.
It hasn't always been like this but I am unsure how to troubleshoot it.
When I run vim -u NONE or vim --noplugin, it doesn't assume 'c' has been pressed, but when I comment out the last two plugins that I installed (typescript-vim and ag.vim), it does assume 'c' was pressed.
Can anyone see any other setting that might be the culprit?
set t_Co=16
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle.vim
call vundle#begin()
Bundle 'gmarik/vundle.vim'
" vim-snipmate dependencies
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'vim-scripts/tlib'
Plugin 'ToadJamb/vim_test_runner'
Plugin 'garbas/vim-snipmate'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-rake'
Plugin 'tpope/vim-endwise'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-scripts/DeleteTrailingWhitespace'
Plugin 'altercation/vim-colors-solarized'
Plugin 'ervandew/supertab'
Plugin 'kchmck/vim-coffee-script'
Plugin 'slim-template/vim-slim'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-markdown'
Plugin 'vim-scripts/Align'
Plugin 'ToadJamb/vim_alternate_file'
Plugin 'ToadJamb/vim_tab_number'
Plugin 'Keithbsmiley/swift.vim'
Plugin 'vim-multiple-cursors'
Plugin 'leafgarland/typescript-vim'
Plugin 'rking/ag.vim'
call vundle#end()
filetype plugin indent on
" Plugin settings
let g:instant_markdown_autostart = 0
autocmd BufNewFile,BufRead Capfile setf ruby
autocmd BufNewFile,BufRead Gemfile setf ruby
" System-level settings
set noswapfile " Turn off the use of swap files - seems to use them anyway
"set dir='' " Really turn off the use of swap files
" Behavior
set expandtab " Expand tabs to spaces
set tabstop=2 " Set tabs to two spaces (No conversion - just display)
set shiftwidth=2 " Use 2 spaces when shifting with '>' or '<'
set ignorecase " Ignore case in patterns.
set smartcase " Case-sensitive matching for patterns with an uppercase letter
set backspace=2 " Make backspace/delete work in insert mode.
set showcmd " Show current command
" Presentation - always visible
syntax on " Syntax highlighting
set number " Show line numbers in margin
set cursorline " Highlight the line the cursor is on
set fillchars=stl:-,vert:\| " Set the characters used to fill borders
let &stl='%t %([%R%M]%) %L %l,%c ' " Status line format
" Presentation - conditional
set nowrap " Do not wrap text
set hlsearch " Highligh search text
set laststatus=2 " Always show the status bar
set listchars=trail::,tab:-> " How trailing spaces & tabs should be represented (tabstop matters for tab)
set list " Required in order for listchars to work
set colorcolumn=80 " Right margin at 80 characters
" Performance - Primarily for Ruby - Any file around 200 lines has a problem.
" Solution found here:
" http://stackoverflow.com/questions/16902317/vim-slow-with-ruby-syntax-highlighting
"set ttyfast " When playing with these 3 options, this one seemed to have no effect.
"set re=1 " Use the old regex engine (default is 0).
set lazyredraw " Don't redraw the screen for every little thing.
" Features
set foldmethod=indent " Enable folding based on language syntax
set nofoldenable " Open files with all folds expanded
" Toggle folding using the space bar.
nnoremap <silent> <Space> #=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf
:let mapleader = ","
" Toggle buffers using leader
map <leader><leader> :b#<cr>
" Enter clears highlighting
nnoremap <cr> :nohlsearch<cr>
" Open alternate files
command AF :execute OpenAlternateFile()
map <silent> <leader>s :call OpenAlternateFile() <CR>
" Run tests
map <silent> <leader>t :call TriggerTest()<CR>
map <silent> <leader>r :call TriggerPreviousTest()<CR>
" Binding for Ag
map <leader>/ :Ag<space>
" Quickfix bindings
map <ENTER> :cn<CR>
" *** No Color Scheme ***
"hi! String ctermfg=00
"hi! LineNr ctermfg=04
"hi! CursorLine ctermfg=none ctermbg=07 cterm=none
" *** Miscellaneous ***
"let g:solarized_termcolors=16 " Local
"let g:solarized_termcolors=256 " Remote
"set background=light
color solarized

Related

Vim entering normal mode when option + 8 or 9

While in insert mode, my vim is entering normal mode when I press the key: option + 8 or 9, this corresponds to a [ or ], respectively on my mac. To write code this is really annoying, as I need brackets a lot. How can I remove this? Thank you.
I attach below my .vimrc file.
I have changed the esc key in inoremap to "jk" and the map leader key to ";".
Update: My terminal is alacritty, and there I don't have this problem. Only in vim.
" Disable compatibility with vi which can cause unexpected issues.
set nocompatible
" Enable type file detection. Vim will be able to try to detect the type of file in use.
filetype on
" Enable plugins and load plugin for the detected file type.
filetype plugin on
" Load an indent file for the detected file type.
filetype indent on
" While searching though a file incrementally highlight matching characters as you type.
set incsearch
" Enable auto completion menu after pressing TAB.
set wildmenu
" Make wildmenu behave like similar to Bash completion.
set wildmode=list:longest
" There are certain files that we would never want to edit with Vim.
" Wildmenu will ignore files with these extensions.
set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx
:set relativenumber
:set number
:set autoindent
:set tabstop=4
:set shiftwidth=4
:set smarttab
:set softtabstop=4
:set mouse=a
:colorscheme iceberg
set termguicolors
set t_Co=256
set background=dark
set term=xterm-256color
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=2
syntax on
syntax enable
" Highlight cursor line underneath the cursor horizontally.
set cursorline
set backspace=indent,eol,start
" Highlight cursor line underneath the cursor vertically.
set cursorcolumn
set list
set showbreak=↪\
set listchars=tab:→\ ,eol:↲,nbsp:␣,trail:•,extends:⟩,precedes:⟨
call plug#begin('~/.config/nvim/plugged')
Plug 'https://github.com/tpope/vim-commentary' " For Commenting gcc & gc
Plug 'https://github.com/tc50cal/vim-terminal' " Vim Terminal
Plug 'https://github.com/ryanoasis/vim-devicons' " Developer Icons
Plug 'https://github.com/neoclide/coc.nvim' " Auto Completion
Plug 'https://github.com/preservim/nerdtree' " NerdTree
"Plug 'ap/vim-css-color'
Plug 'ryanoasis/vim-devicons'
Plug 'vim-airline/vim-airline'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'airblade/vim-gitgutter'
Plug 'ctrlpvim/ctrlp.vim' " fuzzy find files
Plug 'scrooloose/nerdcommenter'
Plug 'christoomey/vim-tmux-navigator'
Plug 'morhetz/gruvbox'
Plug 'HerringtonDarkholme/yats.vim' " TS Syntax
Plug 'https://github.com/terryma/vim-multiple-cursors' " CTRL + N for multiple cursors
Plug 'vimwiki/vimwiki'
set encoding=UTF-8
call plug#end()
let g:vimwiki_list = [{'path': '~/vimwiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]
nnoremap <C-n> :NERDTree<CR>
inoremap jk <ESC>
" Set the backslash as the leader key."
let mapleader = ','
nmap <C-n> :NERDTreeToggle<CR>
vmap ++ <plug>NERDCommenterToggle
let g:NERDTreeGitStatusWithFlags = 1
tnoremap jk <C-\><c-n>
nmap <F8> :TagbarToggle<CR>
let &t_SI.="\e[5 q" "SI = INSERT mode
let &t_SR.="\e[4 q" "SR = REPLACE mode
" Have nerdtree ignore certain files and directories.
let NERDTreeIgnore=['\.git$', '\.jpg$', '\.mp4$', '\.ogg$', '\.iso$', '\.pdf$', '\.pyc$', '\.odt$', '\.png$', '\.gif$', '\.db$']
The problem was in my alacritty terminal. Fixed it by changing the alacritty.yml config to:
alt_send_esc: false

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

vim help produces "unable to open swap file" error

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.

Vim cursor wrapping with .vimrc

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.

Vim Question: Sparkup doesn't work for files opened from a running Vim session

If I were to open a file with Vim from the command prompt (eg: vim ~/.vimrc), the Sparkup text generation seems to work perfectly fine. For example if I insert:
html:xs
and then push control + e, sparkup generates a nice HTML strict boilerplate. However if I then split to another file from the running Vim session, Sparkup stops working in the newly opened file. It's totally possible that other plugins lose their functionality as well. Here is my .vimrc file:
set nocompatible " use vim defaults
set number " show line numbers
set tags=tags;$HOME/.vim/tags/ "recursively searches directory for 'tags' file
set expandtab " tabs are converted to spac
set tabstop=4 " numbers of spaces of tab character
set shiftwidth=4 " numbers of spaces to (auto)indent
set showcmd " display incomplete commands
set incsearch " do incremental searching
set ruler " show the cursor position all the time
set numberwidth=4 " line numbering takes up 5 spaces
set ignorecase " ignore case when searching
set nowrap " stop lines from wrapping
set incsearch " show search matches as you type
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
filetype on " enables filetype detection
filetype plugin on " enables filetype specific plugins
filetype plugin indent on " Loads pyflake-vim's ftplugin files automatically when a Python buffer is opened
syntax on " syntax highlighing
colorscheme default
nmap <silent> <c-y> :NERDTreeToggle<CR>
nmap <silent> <c-o> :OpenBookmark
" TagList Plugin Configuration
let Tlist_Ctags_Cmd='/usr/bin/ctags' " point taglist to ctags
let Tlist_GainFocus_On_ToggleOpen = 1 " Focus on the taglist when its toggled
let Tlist_Close_On_Select = 1 " Close when something's selected
let Tlist_Use_Right_Window = 1 " Project uses the left window
let Tlist_File_Fold_Auto_Close = 1 " Close folds for inactive files
" Omnicompletion functions
set ofu=syntaxcomplete#complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
au FileType py set expandtab
map <F2> :previous<CR> " map F2 to open previous buffer
map <F3> :next<CR> " map F3 to open next buffer
map <F5> :TlistToggle<CR> " map F5 to toggle the Tag Listing
map <silent><C-Left> <C-T> " taglist - map Ctrl-LeftArrow to jump to the method/property under your cursor
map <silent><C-Right> <C-]> " taglist - map Ctrl-RhitArrow to jump back to your source code
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc
highlight SpellBad term=reverse ctermbg=Gray ctermfg=Red
And here are some other plugins I have inside ~/.vim/bundles:
IndexedSearch nerdtree snipmate.vim vim-css-color vim-git vim-rails vim-ruby-debugger vim-supertab vim-tcomment
gist pyflakes-vim textile.vim vim-cucumber vim-haml vim-repeat vim-shoulda vim-surround vim-vividchalk
jquery pysmell vim-align vim-fugitive vim-markdown vim-ruby vim-sparkup vim-taglist
Can it be that this plugin is bound to a given FileType and that when you change window the FileType is not the same?
If it doesn't work, try adding your plugin to ftplugins.

Resources