Hot answers tagged

13

You might want to use an autocommand that runs after VimEnter is triggered. The autocommand can look something like this: autocmd VimEnter * echo 'foo' When vim starts up, it runs the command, and 'foo' is visible in the bottom left, as it would if you had just run the command. You would put this autocommand somewhere in your .vimrc


7

This should work: function! EchoWarning(msg) echohl WarningMsg echo "Warning" echohl None echon ': ' a:msg endfunction call EchoWarning('test') This defined a simple function that you can call with the warning message as the argument. As you see, the key is the echon command, which is similar to an echo except it does not add a newline at the end....


5

You originally mention :echo but based on your example it's :echom that is causing you issues so assuming that's right... Some choices depending on your specific needs (e.g. do you care about the message being saved to the message history)... :echo "foo\nbar" :echon "foo\nbar" :echom "foo" | echom "bar" All of these will produce foo bar Likely due to ...


4

Try combination of :h echohl and :h echon: :echohl Statement | echon "Hello " | echohl Identifier | echon "World" | echohl None | echon "!!!" echohl will apply highlight group to the next echo, echon or echomsg, but if you want to apply highlighting to a part of your message you should use echon. To have all your message in ...


4

you got a small version of Vim installed. That means, many functions are not supported, you can read about, what each flavor supports at :h +feature-list (link). So among the features not supported are multibyte, eval (plugins), diff, folding and quickfix. The easiest solution to get a better full-working Vim is to install vim-gtk (full version with GTK ...


4

you can use the strtrans() function, which translates unprintable characters. strtrans() The result is a String, which is {expr} with all unprintable characters translated into printable characters 'isprint'. Like they are shown in a window. Example: echo strtrans(@a) This ...


4

I looked into this, and I could not find a direct way of doing it. However, one possibility is to create an auxiliary function, that is: function! Range() range abort return RangeAux(a:firstline, a:lastline) endfunction function! RangeAux(lnum1, lnum2) abort echo a:lnum1 echo a:lnum2 endfunction 1,3call Range() call RangeAux(1,3)


3

@Karl's answer is pretty good but you can also use execute(): echo execute("1,2call Range()") You can even use variables for the range: let l1=1 let l2=2 echo execute(l1 . "," . l2 . "call Range()")


3

From the documentation of execute, i.e. :h execute(): execute({command} [, {silent}]) Execute {command} and capture its output. If {command} is a String, returns {command} output. If {command} is a List, returns concatenated outputs. execute() returns the output of whatever is executed, not the return value of any function that may (or may not) be ...


3

I often add characters around like in :echo '###'.xyz.'###'. It's simple enough, and more readable, IMO, than :echo split(xyz, '\zs')


2

Ubuntu comes packaged with a tiny version of vim. It is nearly vi. To install the real version of vim, run sudo apt-get install vim Personally, I prefer: sudo apt-get install vim-gnome since this comes with things like python and clipboard support, and gvim, but installing the default vim version should be enough to get echo working. I don't remember ...


2

It sounds like you've overridden some of the settings used to invoke external programs. Is your Vim set up so programs run in either Cygwin or Windows Linux Subsystem by any chance? Try starting vim with -u NONE -i none. Alternatively run these after starting vim: :set shell& :set shellxquote& :set shellxescape& :set shellcmdflag& :set ...


2

this is because call Example() alone wouldn't print anything. You need :echo execute("echo Example()") for execute() to print anything.


2

Replace echo with set in your script, and your command works fine. See :help -s-ex: The output of these commands is displayed (to stdout): :print :list :number :set         to display option values. (...


2

The provided code seemed to be working when I tried it and we established that OP is seeing the same behavior as I am. So that leaves a difference in expectations, I think, about what the correct behavior is. Three important pieces of information: Text colored by syntax highlighting is selected by rules, often regex patterns, and they specify where a ...


2

From :help :!: A '|' in {cmd} is passed to the shell, you cannot use it to append a Vim command. See :bar. An alternative would be to use the system() function, like so: :call system('pbcopy', getline(1, '$')) The second argument is the stdin; in this case all all lines (like the % range). In a mapping, it might look like: nnoremap <localleader>...


1

I'm sure there are at least a few third party alternatives for this. One I'm familiar with is Decho which is used by netrw. You can enable/disable logging, indicate function enter/leave and depth and other useful things with any one of the following as the message destination: Appended to separate window Uses :echomsg Appended to a variable (default g:...


1

As @dedowsdi said in a comment: Log into a list. The following is derived from stuff I have in one of my plugins: function! DebugMsg(msg) abort if !exists("g:DebugMessages") let g:DebugMessages = [] endif call add(g:DebugMessages, a:msg) endfunction function! PrintDebugMsgs() abort if empty(get(g:, "DebugMessages", [])) echo "No ...


1

After seven hours of fiddling with the documentation and searching, I was able to write a function that takes a filetype, an array of strings and show a dummy buffer based on that. function! showInPreview(name, fileType, lines) let l:command = "silent! pedit! +setlocal\\ " . \ "buftype=nofile\\ nobuflisted\\ " . \ "...


1

So my question was quite stupid actually. It sufficed to add: echo execstr just before exec execstr Now if I could also capture the shell stdout and display it too, it would also be nice.


1

Using call you are not able to get the return value of the function, regardless whether range is used or not. Aside from @Karl's answer, you can set some variable instead of using return. Such as function! Range() range abort let toreturn = 'my value' let s:retval = toreturn endfunction


1

In my lh-vim-lib library plugin I provide a framework for logging (among many other things) . Unlike other frameworks (like maktaba) I don't try support several modes (error, warning, info, debug). Instead, I can choose to enable logs independently on each autoload plugin. Then, I can chose where the logs go (:messages, quickfix/loclist window, file, ...


1

The echo command depends on the eval feature. The eval faeture is compiled in only in models normal and larger.


Only top voted, non community-wiki answers of a minimum length are eligible