9

In .vimrc:

inoremap ii <esc>                               " ii to go back into command mode

The problem is, after ii, cursor jumps 35 columns right. The only other line which affects Esc:

nnoremap <esc><esc> :noh<return><esc>

I have tried commenting it out, doesn't help.


Full .vimrc:

set nocompatible
filetype off


" Vundle ---------------------------------------------------------------------
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/syntastic'
Plugin 'freitass/todo.txt-vim'
Plugin 'plasticboy/vim-markdown'
Plugin 'tpope/vim-fugitive'                     " :GitCommands
Plugin 'tpope/vim-git'                          " allows to see branch in airline
Plugin 'airblade/vim-gitgutter'                 " git status in SL area
Plugin 'ctrlpvim/ctrlp.vim'                     " TODO: learn more about this
Plugin 'Shougo/neocomplete.vim'                 " TAB completion
" Plugin 'tmhedberg/SimpylFold'                 " should we add FastFold?
Plugin 'spf13/vim-autoclose'                    " autoclose brackets(properly)
Plugin 'godlygeek/tabular'                      " V -> : -> /SYMBOL_TO_LINE-UP
Plugin 'terryma/vim-multiple-cursors'           " steep learning curve
Plugin 'Yggdroot/indentLine'                    " shows | intendation
Plugin 'mhinz/vim-startify'                     " start screen
Plugin 'hashivim/vim-vagrant'
Plugin 'pearofducks/ansible-vim'
Plugin 'whatyouhide/vim-gotham'
Plugin 'ryanoasis/vim-devicons'                 " glyph icons everywhere
call vundle#end()


" System ---------------------------------------------------------------------
set lazyredraw                                  " do we need this?
set ttyfast                                     " theoretically make things faster
set mouse=a                                     " enable mouse
set guicursor=a:blinkon0                        " don't blink with the cursor
set termencoding=utf-8                          " terminal is UTF-8
set encoding=utf8                               " ...as well as the editor
set fileformat=unix                             " *nix format
set clipboard=unnamed                           " Fix clipboard in *nix
set wildmenu
set wildmode=longest:full,full
set wildignore=*.o,*.pyc,*.DS_Store
set magic                                       " needed for regexp
set hidden                                      " allow switching buffers w/o saving
set nojoinspaces                                " don't join spaces on paste
set formatoptions-=r formatoptions-=c formatoptions-=o " don't autoextend comments
set lines=40 columns=90                         " default size for GUI
set gdefault                                    " replace all without /g
set virtualedit=all                             " keep cursor horizontal pos. when scrolling

set backup                                      " backups ON
set undofile                                    " persistent undo
set backupdir=~/.vim/backup
set directory=~/.vim/tmp
set undolevels=1000                             " max number of undos
set undoreload=10000                            " max lines to to save for undo
set history=1000                                " 1000 of history (what?)

set incsearch                                   " incremental search
set smartcase                                   " ... and case sensitive if Uppercase is present

set expandtab                                   " spaces instead of tabs
set smarttab                                    " smart tabs/intends
set tabstop=4                                   " TAB = 4 spaces
set softtabstop=4
set smartindent
set autoindent
set shiftwidth=4
set shiftround                                  " round to 4

let NERDSpaceDelims=1                           " add space before comment
let NERDTreeMapOpenInTab='\r'                   " open files in new tab
let g:vim_markdown_folding_disabled=1           " don't fold *.md

let g:neocomplete#enable_at_startup = 1         " NeoComplete
let g:neocomplete#enable_auto_select = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#min_keyword_length = 2        " min symbols before autocomplete


" Visuals --------------------------------------------------------------------
filetype plugin indent on                       " enable filetype plugins
syntax enable                                   " enable syntax highlighting
let python_highlight_all=1                      " full python highlighting
colorscheme gotham256                           " GUI colours
let g:airline_theme = "gotham256"               " airline theme
if has("gui_running")
    set cul
endif

set title                                       " set terminal title
set t_Co=256                                    " 256 colors terminal
set guifont=Meslo\ LG\ S\ Regular\ for\ Powerline\ Nerd\ Font\ Complete\ Windows\ Compatible:h12
set guioptions=L                                " disable right scrlbar
set guioptions=R                                " disable left scrlbar
set number                                      " show line numbers
set nowrap                                      " don't wrap long lines
set fillchars+=vert:\?                          " vertical unicode split
set shortmess+=I                                " remove startup message

set splitbelow                                  " Natural splits
set splitright

set hlsearch                                    " highlight search results
set showmatch                                   " show matching brackets

set noerrorbells                                " disable bells
set novisualbell
set vb t_vb=

set laststatus=2                                " always show airline
let g:airline_powerline_fonts=1                 " use glyph fonts
let g:airline#extensions#tabline#enabled=1      " enable tabline (top)
let g:airline#extensions#tabline#fnamemod=':t'  " filename only

set completeopt-=preview                        " don't show doc. window by default
let g:SimplylFold_docstring_preview=1           " keep docstring unfolded.

let g:gitgutter_sign_added = '?'                " Gitgutter
let g:gitgutter_sign_modified = '•'
let g:gitgutter_sign_removed = '?'
let g:indentLine_char = '¦'                     " intendation vertical lines


" Hotkeys --------------------------------------------------------------------
nnoremap <F1> <nop>                             " F1 does noothing
map <F2> :NERDTreeToggle<CR>                    " F2 to open NerdTree
set pastetoggle=<F3>                            " F3 to switch in paste mode
map <F4> :mksession! ~/.vim/vim_session<CR>     " F4 to write current session
map <F5> :source ~/.vim/vim_session<CR>         " F5 to load prev. session

inoremap ii <esc>                               " ii to go back into command mode
let mapleader = "\<Space>"                      " remap leader key from '\' to Space
map <leader>cd :cd %:p:h<cr>:pwd<cr>            " CWD to the dir of the open buffer
nnoremap <esc><esc> :noh<return><esc>           " 2xESC clears search highlights

nnoremap <C-J> <C-W><C-J>                       " switch splits with CTRL+hjkl
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

nmap <leader>l :bn<CR>                          " next buffer by Space+l
nmap <leader>h :bp<CR>                          " previous buffer by Space+h
nmap <leader>q :bp <BAR> bd #<CR>               " close buffer by Space+q

vnoremap < <gv                                  " leave txt selected after <>
vnoremap > >gv

set t_ku=OA                                   " fix arrow keys
set t_kd=OB
set t_kr=OC
set t_kl=OD

nmap <leader>f1 :set foldlevel=0<CR>            " change folding levels
nmap <leader>f2 :set foldlevel=1<CR>
nmap <leader>f3 :set foldlevel=2<CR>
nmap <leader>f4 :set foldlevel=3<CR>

nnoremap <silent> <leader>gs :Gstatus<CR>       " GIT shortcuts
nnoremap <silent> <leader>gd :Gdiff<CR>
nnoremap <silent> <leader>gc :Gcommit<CR>
nnoremap <silent> <leader>gb :Gblame<CR>
nnoremap <silent> <leader>gl :Glog<CR>
nnoremap <silent> <leader>gp :Git push<CR>
nnoremap <silent> <leader>gr :Gread<CR>
nnoremap <silent> <leader>gw :Gwrite<CR>
nnoremap <silent> <leader>ge :Gedit<CR>
nnoremap <silent> <leader>ga :Git add %:p<CR>

set backspace=eol,start,indent                  " esoteric backspace fix
set whichwrap+=<,>                              " move to another line with <- ->

if bufwinnr(1)                                  " resize splits with +-
  map + <C-W>+
  map - <C-W>-
endif

" NeoComplete
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
    " return neocomplete#close_popup() . "\<CR>"
    " For no inserting <CR> key.
    return pumvisible() ? neocomplete#close_popup() : "\<CR>"
endfunction

" <TAB>: completion.
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"


" Macros ---------------------------------------------------------------------

" Emulate any other editor with tabs
try
 set switchbuf=useopen,usetab,newtab
catch
endtry

" Close vim if NerdTree is the only buffer left
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

" Return to last edit position when opening files
autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

" Python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
  project_base_dir = os.environ['VIRTUAL_ENV']
  activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
  execfile(activate_this, dict(__file__=activate_this))
EOF

" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags

" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
  let g:neocomplete#sources#omni#input_patterns = {}
endif

" format JSON code
com! FormatJSON %!python -m json.tool

" BG fix for tmux
set t_ut=
2
  • 1
    Probably not the solution but to avoid some unexpected side effects in your mappings you should use inoremap ii <Esc>. I don't think that will solve your problem but that's still a best practice. Also could you please post your complete .vimrc: that could help us to help you ;-)
    – statox
    Commented Mar 18, 2016 at 13:20
  • @statox, Changed to inoremap, same effect. Added link to the vimrc. Thanks :]
    – user6649
    Commented Mar 18, 2016 at 13:29

1 Answer 1

19

Your problem is that you put comments at the end of your lines separated by whitespaces. Vim interprets these whitespaces as part of your commands and mappings.

If you replace:

inoremap ii <esc>                               " ii to go back into command mode

By

" ii to go back into command mode
inoremap ii <Esc>

You will solve your problem.

As a general rule don't put comments at the end of your lines in your .vimrc


And as a bonus Here is a method to transform your .vimrc in a proper format.

Edit Use this command. (Compared to the original one, the new line character \r can be directly copied and you don't have to use ^M. Thanks @Sato!)

 :%s/\(^.*\)\s\+\(".*\)/\2\r\1

Original command

 :%s/\(^.*\)\s\+\(".*\)/\2^M\1

(To insert the ^M properly use Ctrl-vEnter to insert a real new line character)

This command will capture the beginning of lines containing a comment on the end of the line and replace the full line with two lines containing the comment and then the command.

(Note that the command seems to mess with the function my_cr_function so you might want to check that it doesn't create to much trouble in your .vimrc maybe replace % by some ranges and change your .vimrc step by step)


@Sato also suggested this link about how comments and multiline works it is worth reading it.

8
  • 2
    @fruglemonkey you're right but I don't think it is a good practice to recommand: using bar this way is -in my opinion- a potential source of bugs hard to spot. It is easy to forgot a bar and to spend a lot of time trying to figure out what is causing the problem. I think that putting comments on separate lines is safer :-)
    – statox
    Commented Mar 18, 2016 at 14:16
  • 3
    For what it's worth, this post explains explains exactly what's going on with comments in VimL. Commented Mar 18, 2016 at 14:54
  • 4
    Yon can also replace ^M in replacement strings by \r. Commented Mar 18, 2016 at 14:56
  • 4
    Sadly \r doesn't work in all contexts, f.i. you have to use \n in search patterns. But it does work here. Commented Mar 18, 2016 at 15:02
  • 1
    If you read Sato's link you'll see "Some command definitions allow comments in their context so set ai " Set &autoindent works, treating " just like newline or bar, but this does not apply to :let."... In some cases it is possible to add comments at the end of the line but I think I've never seen a good .vimrc using them, so I would advise you not to use them.
    – statox
    Commented Mar 19, 2016 at 7:48

Your Answer

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