1

After I do a :sp or :vsp I find myself always turning off wrapping in the resulting window.

My first attempt at automating this action looks like this (for the vertical situation):

function! VerticalSplit()
  vsplit
  setlocal nowrap
endfunction
nnoremap <silent> :vsp :call VerticalSplit()<CR>

This seems to work, but a negative is that when I type :vsp it doesn't show my typing in the :ex console at the bottom of the screen. This becomes more noticeable when typing other commands such as :vimgrep.

Is there a way to still show my typing in the ex window, or perhaps a better approach to tackle this problem?

1
  • 2
    perhaps :cabbrev would be better for your case? Jul 24 '17 at 20:07
1

With :cabbrev you can achieve what you want so Christian Brabandt has made a great suggestion. Now you have two different approaches, on one hand you could try Christian's suggestion and type in:

:cabbrev vsp vsplit <bar> set nowrap
:cabbrev sp split <bar> set nowrap

or, on the other hand, you could map Enter in command mode, check if you typed in either sp or vsp and if so set nowrap as follows:

function! WrapIfSplit()
   let cmdline = getcmdline()
   if cmdline == "vsp"
      return "\<C-U>vsplit \<bar> set nowrap\<CR>" 
   elseif cmdline == "sp"
      return "\<C-U>split \<bar> set nowrap\<CR>" 
   endif
   return "\<CR>"
endfunction

cnoremap <expr><silent> <CR> WrapIfSplit()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.