Tuesday, December 1, 2009

Re: ctrl+J without adding a space

Gary Johnson schrieb:
> On 2009-11-30, KKde wrote:
>>> :help J
>>> :help gJ
>>>
>> gJ doesn't remove the indentation space whereas J removes the
>> indentaion space and add's up to two spaces. Is there any command to
>> join two lines without any white space added in between?or a function
>> needs to be written to acheive this?
>
> There's no built-in command to do that, but you could create a
> mapping such as this one that redefines the behavior of gJ, taking
> advantage of the observation that J moves the cursor to the
> whitespace joining the two lines:
>
> :nnoremap gJ Jdiw
>
> HTH,
> Gary

Unfortunately, it doesn't accept a count and won't work for Visual mode.
Maybe these mappings can help out:

" <Leader>j join without gap
" [count]<Leader>j and {Visual}<Leader>j

nn <expr> <Leader>j ':<C-U><BS>'
\. repeat('Ji <Esc>"_diw', v:count<=2 ? 1 : v:count-1)
xn <script> <Leader>j <Esc><SID>(NoGapJoin)

nn <expr> <SID>(NoGapJoin) (line(".")>line("'<") ? "'<" : "")
\. repeat('Ji <Esc>"_diw', max([line("'>")-line("'<"), 1]))


It needs quite a current Vim for the expression map to accept a count.

One remaining problem is: the dot command will repeat "_diw

--
Andy

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: