In Vim, how do I break a line of text with a newline?
For example, I'm in INSERT
mode and I'd like to get from here...
$('#toggle_contact_search_mode').click([CURSOR IS HERE]);
To here...
$('#toggle_contact_search_mode').click(
[CURSOR IS HERE]
);
The result I'm getting is that when I'm in insert mode and I have the cursor in the first position above and I hit return...
- Vim goes to normal mode.
- The line with the cursor scrolls to the bottom of the screen.
- Code throughout the file is reformatted incorrectly. For example, in another part of the file the code is reformatted like this:
$('.edit_phone_number').ajaxForm({
success: function(response) {
$('input, select, textarea', '.edit_phone_number').removeClass('updating');
}
});
$('input, select, textarea', '.edit_phone_number').focus(function(event) {
$(event.target).removeClass('updating').addClass('focussed');
});
I don't want any reformatting at all. I just want Vim to just enter a newline and remain in insert mode.
UPDATE
When I temporarily remove my .vimrc
file, the Vim behaves as expected. My .vimrc
:
" ==================================================================================
" Global stuff
" ==================================================================================
" Prevent Vim from emulating vi bugs and limitations
:set nocompatible
" Custom status line based on one from here:
" http://www.linux.com/archive/feature/120126
:set statusline=\ \ %f\ \ [FORMAT=%{&ff}]\ \ [TYPE=%Y]\ \ [POS=%04l,%04v][%p%%]\ \ [LEN=%L]
" Set status line colors
highlight StatusLine term=reverse ctermfg=DarkBlue ctermbg=Grey
" Set status line to be shown above the command buffer.
:set laststatus=2
" Enable syntax highlighting
:syntax on
" Enable line numbering, taking up 6 spaces
:set number
" Allow <BkSpc> to delete line breaks, beyond the start of the current
" insertion, and over indentations
" set backspace=eol,start,indent
" ==================================================================================
" Searching
" ==================================================================================
" Highlight matches as you type in the search string
:set incsearch
:set showmatch
" When searching ignore case (except explicit caps)
:set ignorecase
:set smartcase
" ==================================================================================
" Indenting
" ==================================================================================
" Copy indent from current line when starting a new line
" :set autoindent
"
" :set smartindent
" :filetype plugin on
" indent depends on filetype
" :filetype indent on
:set tabstop=2
:set softtabstop=2
:set shiftwidth=2
:set expandtab
" ==================================================================================
" Mappings
" ==================================================================================
" ESC
imap <C-k> <ESC>
" Go to the next tab
nmap <C-j> gt
imap <C-j> <ESC>gt
" Auto indent entire file.
" Sets a mark ("mt""), moves across the whole file to indent it ("gg=G"),
" then returns to the mark ("'t").
nmap <C-m> mtgg=G't
imap <C-m> <ESC><C-m>