All my other keybindings are working correctly, but I can't bind jj to escape for some reason. Mashing jk or kj doesn't work either. Here is my entire .vimrc:
"Maps for jj to act as Esc
inoremap jk <Esc>
inoremap kj <Esc>
"inoremap jj <Esc>
ino jj <Esc>
cno jj <C-c>
set number
set nocompatible
set paste
"fix cygwin backspace problem
set backspace=indent,eol,start
fixdel
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
"use spaces instead of \t
"set expandtab
set nowrap
syntax on
highlight ExtraWhitespace ctermbg=darkgreen guibg=lightgreen
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/
"remove trailing whitespace
"http://vim.wikia.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace
"autocmd BufWritePre * :%s/\s\+$//e
autocmd BufWritePre *.c :%s/\s\+$//e
autocmd BufWritePre *.cpp :%s/\s\+$//e
autocmd BufWritePre *.c++ :%s/\s\+$//e
autocmd BufWritePre *.h :%s/\s\+$//e
autocmd BufWritePre *.java :%s/\s\+$//e
autocmd BufWritePre *.php :%s/\s\+$//e
autocmd BufWritePre *.pl :%s/\s\+$//e
autocmd BufWritePre *.py :%s/\s\+$//e
"autocmd FileType c,cpp,c++,java,php,pl,py autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,
"search options
set incsearch
set ignorecase
set showmatch
nmap <space> zz
nmap n nzz
nmap N Nzz
"set arrow keys to move between buffer / tabs
inoremap <Up> :bprev<CR>
inoremap <Down> :bnext<CR>
inoremap <Left> :tabprev<CR>
inoremap <Right> :tabnext<CR>
noremap <Up> :bprev<CR>
noremap <Down> :bnext<CR>
noremap <Left> :tabprev<CR>
noremap <Right> :tabnext<CR>
set vb t_vb=
set guioptions-=T
"set foldmethod=indent
set showtabline=2
"au BufWinLeave * mkview
"au BufWinEnter * silent loadview
For the record, timeoutlen is set to the default of 1000 ms.
Just found the answer researching an unrelated .vimrc question. Using set paste disables insert abbreviations, even if it never actually every worked for me in .vimrc.
You want inoremap jj <Esc>, which you seem to have commented. Uncomment it and comment/delete the other mappings for jj. Does that work?
Related
After a line of code wraps onto the next line, I find that the closing brace isn't aligned properly. Here's an image to demonstrate what's going on:
Ideally the closing brace should be in line with while.
Here are my vimrc settings:
filetype plugin indent on
syntax on
set backspace=indent,eol,start
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set showtabline=2
set number
set showcmd
set cursorline
set wildmenu
set lazyredraw
set showmatch
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree'
Plug 'drewtempelmeyer/palenight.vim'
Plug 'NLKNguyen/papercolor-theme'
Plug 'rakr/vim-one'
Plug 'morhetz/gruvbox'
Plug 'tpope/vim-commentary'
Plug 'ajh17/VimCompletesMe'
Plug 'sheerun/vim-polyglot'
call plug#end()
highlight ColorColumn ctermbg=gray
set colorcolumn=81
autocmd BufNewFile,BufRead * setlocal formatoptions=croqtn textwidth=80
set t_Co=256
set term=xterm-256color
let g:gruvbox_contrast_dark='dark'
colorscheme gruvbox
set background=dark
map <C-x> :NERDTreeToggle<CR>
noremap <TAB> <C-W>w
" autoclose matching quotes, braces and parentheses
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O
inoremap jj <Esc>
inoremap <Esc> <Nop>
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <C-y> <C-o>h
inoremap <C-u> <C-o>l
I want to map F2 to compiling tex files, and F3 for viewing tex files.
This is what I put in my .vimrc:
if &filetype == "tex"
nnoremap <F2> :Latexmk<cr>
inoremap <F2> <Esc>:Latexmk<cr>a
nnoremap <F3> :LatexView<cr>
inoremap <F3> <Esc>:LatexView<cr>a
endif
These Latex* commands are from LaTeX-Box plugin. I can execute them manually without any problems. Typing :echo &filetype in any *.tex file returns tex.
You have two methods…
Create a self-clearing group in your vimrc and add as many autocommands as needed:
augroup Tex
autocmd!
autocmd FileType tex nnoremap <buffer> <F2> :Latexmk<cr>
autocmd FileType tex nnoremap <buffer> <F3> :LatexView<cr>
autocmd FileType tex inoremap <buffer> <F2> <Esc>:Latexmk<cr>a
autocmd FileType tex inoremap <buffer> <F3> <Esc>:LatexView<cr>a
augroup END
Use a ftplugin:
Put the following in after/ftplugin/tex.vim:
nnoremap <buffer> <F2> :Latexmk<cr>
nnoremap <buffer> <F3> :LatexView<cr>
inoremap <buffer> <F2> <Esc>:Latexmk<cr>a
inoremap <buffer> <F3> <Esc>:LatexView<cr>a
The second method is recommended because it is a lot cleaner and less expensive than the first.
I replaced the code above with this:
autocmd FileType tex nnoremap <buffer> <F2> :Latexmk<cr>
autocmd FileType tex nnoremap <buffer> <F3> :LatexView<cr>
autocmd FileType tex inoremap <buffer> <F2> <Esc>:Latexmk<cr>a
autocmd FileType tex inoremap <buffer> <F3> <Esc>:LatexView<cr>a
I just moved to Vim about 3 weeks ago. I know this is minor problem but i find it somehow annoy me. Whenever i open vim, statusline (or statusbar?) won't immediately appear (+ cursor always positioned at the last line of the screen) unless i press a key (any key). This is my vimrc for reference:
set nocompatible
" Pathogen
filetype off
runtime bundle/vim-pathogen/autoload/pathogen.vim
execute pathogen#infect()
filetype plugin indent on
" Color Schemes
set t_Co=256
syntax on
set background=dark
colorscheme ir_black
" Misc
set history=200
set backspace=indent,eol,start
set mouse=n
set lazyredraw
runtime macros/matchit.vim
" Escape Timeout
set notimeout
set ttimeout
set ttimeoutlen=10
" Backup & Undo
set noswapfile
set backup
set undofile
set backupdir=~/.vim/backup//
set directory=~/.vim/swap//
set undodir=~/.vim/undo//
" Scroll
set scrolloff=3
" Status Bar
set showmode
set showcmd
set ruler
set laststatus=2
set statusline=
" Tabs & Spaces
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
set shiftround
set smarttab
" Text
set encoding=utf-8
set nowrap
set autoindent
set textwidth=80
set formatoptions=qrn1j
" Splitting
set splitbelow
set splitright
" Buffer
set hidden
" Wildmenu
set wildmenu
set wildmode=list:longest,full
set wildignore+=**/vendor/**
set wildignore+=**/node_modules/**
" Auto-completion
set complete=.,i,w,b,u,t
set omnifunc=
set completeopt=longest,menuone,preview
" Searching + Regex
set ignorecase
set smartcase
set hlsearch
set incsearch
set gdefault
highlight Search cterm=underline
nnoremap / /\v
vnoremap / /\v
nnoremap <space> :noh<cr>
" Mapping
let mapleader=","
noremap \ ,
inoremap jk <esc>
noremap L g_
noremap H ^
" Window Resize
nnoremap <silent> <up> <c-w>+
nnoremap <silent> <down> <c-w>-
nnoremap <silent> <left> <c-w><
nnoremap <silent> <right> <c-w>>
" Disable Arrow Keys
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" Move by Display Line
noremap j gj
noremap k gk
" Toggles
nnoremap <leader>wl :set wrap!<cr>
nnoremap <leader>n :setlocal number!<cr>
nnoremap <leader>l :set list!<cr>
" Wipe Whitespace
nnoremap <leader>ww mz:%s/\s\+$//<cr>:let #/=''<cr>`z
" Easy Access to Active File Directory
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" Toggles
nnoremap <silent> <leader>n :set number!<cr>
nnoremap <silent> <leader>wl :set wrap!<cr>
" Buffer Navigation
nnoremap <silent> [b :bprevious<cr>
nnoremap <silent> ]b :bnext<cr>
nnoremap <silent> [B :bfirst<cr>
nnoremap <silent> ]B :blat<cr>
" Split Navigation
nnoremap <c-h> <c-w><c-h>
nnoremap <c-j> <c-w><c-j>
nnoremap <c-k> <c-w><c-k>
nnoremap <c-l> <c-w><c-l>
" Netrw
let g:netrw_banner=0
" Grep Ag
if executable("ag")
set grepprg=ag\ --nogroup\ --nocolor\ --ignore-case\ --column
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
is there something wrong with it?
edit: this is screenshot of what happen with my vim.
before i press a key
Removing lazyredraw from my vimrc fixed this for me as well.
This was with Vim 7.4 on Ubuntu 16.04.
Background: I'm using skwp's dotfiles, and his recently changes is breaking some functionalities I use on daily basis.
Instead of set up the mappings globally, I'm trying to nnoremap two shortcuts upon quickfix enters and nunmap after quickfixes quits.
BTW, I think syntastic is used for linting, which invokes the quickfix/location lists.
Here's the code:
augroup quickfixShortcutsGroup
autocmd!
autocmd BufWrite * :echom "Foo"
" au BufReadPost quickfix nnoremap <silent> <C-z> :cp<CR>
" au BufReadPost quickfix nnoremap <silent> <C-x> :cn<CR>
au BufWinEnter quickfix nnoremap <silent> <C-z> :cp<CR>
au BufWinEnter quickfix :echo '1'
au BufWinLeave quickfix nnoremap <silent> <C-z> :cp<CR>
au BufWinLeave quickfix :echo 'BufWinLeave'
au BufLeave qf :echo 'BufLeave'
au BufUnload qf :echo 'unload qf'
" au BufLeave qf noremap <silent> <C-z> :cb<CR>
" au BufLeave quickfix noremap <silent> <C-z> :cb<CR>
" au BufWinLeave quickfix noremap <silent> <C-z> :cb<CR>
" au BufWinLeave quickfix nunmap <C-z>
" au BufWinLeave quickfix :echom 'Hello'<cr>
" BufWinEnter
augroup END
After read reference:
http://vimdoc.sourceforge.net/htmldoc/autocmd.html#BufWinLeave
http://vimdoc.sourceforge.net/htmldoc/autocmd.html#autocmd-patterns
I still could not get unmap events working, i.e. BufWinLeave, BufUnload, BufLeave are not invoked.
Can Vimers tell me which event(s) I should be using and help me out on this? Thank you in advance for the help.
As :help BufWinLeave explains, the current buffer "%" may be different from the buffer being unloaded "". So you need a global autocmd, and resolve the buffer number that has been left, and then check for the quickfix 'buftype':
autocmd! BufWinLeave * if getbufvar(bufnr(expand('<afile>')), '&buftype') ==# 'quickfix' | echo "leaving quickfix" | endif
But in general, I'd advise against such tricks and especially conditional mappings. Your <C-z> / <C-x> mappings are still global, now just depending on whether the quickfix list is visible. That's bad for muscle memory, and the overload of the key combos is mentally taxing. I'd rather get rid of the mappings completely, or assign different (if potentially longer) keys.
And there's the next complication: Vim "distributions" and other people's dotfiles lure you with a quick install and out-of-the-box settings, but you pay the price with increased complexity (you need to understand both Vim's runtime loading scheme and the arbitrary conventions of the distribution) and inflexibility (the distribution may make some things easier, but other things very difficult). Vim is incredibly customizable, using someone else's customization makes no sense.
If you would like to nnoremap these two mappings upon quickfix enters and nunmap after quickfix quits, you could
" map silently upon entering Quickfix
autocmd BufWinEnter * if &buftype == 'quickfix'
\| nnoremap <silent> <C-x> :cn<CR>
\| nnoremap <silent> <C-z> :cp<CR>
\| endif
" unmap upon leaving Quickfix
autocmd BufWinLeave * if &buftype == 'quickfix'
\| nunmap <C-x>
\| nunmap <C-z>
\| endif
Or you can make use of local buffer mapping to make your code shorter
" map silently upon entering Quickfix, and only for Quickfix
autocmd BufWinEnter * if &buftype == 'quickfix'
\| nnoremap <buffer><silent> <C-x> :cn<CR>
\| nnoremap <buffer><silent> <C-z> :cp<CR>
\| endif
These autocmd's are invoked every time you enter or leave a buffer. So it is really better just, as Sato Katsura suggested, add in your ~/.vim/ftplugin/qf.vim
nnoremap <buffer><silent> <C-x> :cn<CR>
nnoremap <buffer><silent> <C-z> :cp<CR>
You may consider to read these:
:h ftplugins
:h map-local
:h buftype
:h line-continuation
This is a really strange issue and it's been driving me insane. At one point, in my .vimrc file, I had a line that looked like the following:
nnoremap <tab> gg=G''
which I used to re-indent my whole file. Time goes on and I decide that I want to use tab like %, to move between open/close tags/parens/etc. So I remove the line above, and remap the command to control-i (like Eclipse) and replace it with
nnoremap <tab> %
vnoremap <tab> %
I save the file, source it, close vim, restart my computer, do whatever, but regardless of what I do, pressing tab still indents the entire file. When I check the mapping with
:verbose map <tab>
The output I get is:
v <Tab> * %
Last set from ~/.vimrc
n <Tab> * gg=G''
Last set from ~/.vimrc
Similarly, if I try
:verbose nnoremap <tab>
I get:
n <Tab> * gg=G''
Last set from ~/.vimrc
I'm really not sure what's going on here, that mapping most certainly does not exist any more. Here is my .vimrc:
set nocompatible " be iMproved
filetype off " required!
let mapleader = ","
nnoremap <leader><space> :noh<cr>
nnoremap ; :
nnoremap <leader>v <C-w>v<C-w>l
nnoremap <leader>h <C-w>s<C-w>j
nnoremap <leader>f :CtrlP<CR>
nnoremap <tab> %
vnoremap <tab> %
inoremap jk <ESC>l
nnoremap <C-i> gg=G''
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
syntax enable
set t_Co=16
set background=dark
set tabstop=2
set shiftwidth=2
set softtabstop=2
set smarttab
set expandtab
set number
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
set nobackup
set noswapfile
set smartindent
set hidden
set wildmenu
set nonumber
set nowrap
set relativenumber
set timeoutlen=100
set backspace=indent,eol,start
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
" My Bundles here:
"
" original repos on github
Bundle 'tpope/vim-rails.git'
Bundle 'tpope/vim-endwise.git'
Bundle 'tpope/vim-surround.git'
Bundle 'scrooloose/nerdcommenter.git'
Bundle 'scrooloose/syntastic.git'
Bundle 'jiangmiao/auto-pairs.git'
Bundle 'kien/ctrlp.vim'
Bundle 'altercation/vim-colors-solarized.git'
colorscheme solarized
" vim-scripts repos
Bundle 'bufexplorer.zip'
Bundle 'HTML-AutoCloseTag'
Bundle 'matchit.zip'
Bundle 'ruby-matchit'
Bundle 'Rename2'
filetype plugin indent on " required!
filetype indent on
"
" Brief help
" :BundleList - list configured bundles
" :BundleInstall(!) - install(update) bundles
" :BundleSearch(!) foo - search(or refresh cache first) for foo
" :BundleClean(!) - confirm(or auto-approve) removal of unused bundles
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Bundle command are not allowed..
<c-i> and <tab> share the same key codes so they can not be distinguished from each other.
Use a different mapping than <c-i>. I suggest you use leader, e.g. nnoremap <leader>i gg=G''
For more help see:
:h keycodes
:h mapleader