How can I call the editor command from vimscript?

I want to remove an unwanted scrollbar from a taglist. I created a function and command like this:

function s:TlistWaToggle() normal :TlistToggle<cr> " <- this does not work set guioptions-=r endfunction command! -nargs=0 -bar TlistWaToggle call s:TlistWaToggle() 

I want to wrap a call: TlistToggle along with the command to remove the right scrollbar (I have this option, of course, but it always appears again, so this is a workaround). Currently mine: TlistWaToggle does nothing. How can I make it work?

+4
source share
2 answers

Vim script uses ex commands, and apparently :TlistToggle is an ex command ...

 function! s:TlistWaToggle() TlistToggle set guioptions-=r endfunction 
+4
source

In addition to @sidyll's answer:: :normal not :*map , it only accepts raw character strings. The correct command would be execute "normal! :TlistToggle\<CR>" (or execute "normal! :TlistToggle\n" ). Please note that you should not use the version without changes in your scripts.

I do not think you have ever used :normal! to execute the ex command, but my answer would be useful when you want to pass any other special character. This also applies to calling feedkeys() .

By the way, comments and other commands will be considered part of the line passed to the command :normal .

+3
source

All Articles