Ethan
Ethan

Reputation: 60179

How can I enter a line break in the middle of a line?

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


$('.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>

Upvotes: 2

Views: 2023

Answers (3)

gerard
gerard

Reputation:

I don't know VIM but Ctrl+M works in Notepad -- you might try it.

Upvotes: -1

hobbs
hobbs

Reputation: 240639

Your problem is the imap <C-m> mapping -- control-M is logically equivalent to enter on the terminal.

Upvotes: 6

zigdon
zigdon

Reputation: 15073

Seems like the imap lines you have in your .vimrc are messing you up. It seems odd to make a mapping to work in insert mode just to make it do what the normal mode mapping does. Are you sure you actually want that to happen? I'd suggest considering removing the last two imap lines (c-j and c-m), and see if you even notice they're gone.

Upvotes: 1

Related Questions