Apologies if this has been asked before, but I feel overwhelmed with the Vim docs and I can't seem to figure this out.
I want to map the F5 key in Vim to accomplish the following actions:
Yank text from the visual selection in Vim.
Execute the yanked portion of the text in another GNU Screen session named ipython.
The second portion could be achieved by issuing the following command line argument (via :!), if only I was able to find a way to paste the register content between the double quotes of that line (but I can't figure out how):
map <F5> :!screen -x ipython -X stuff "[REGISTER 0 CONTENT]"<CR><CR>
Any help would be much appreciated!
For the second part, you can use
:execute "!screen -x ipython -X stuff " . shellescape(#0)
Here I copy my previous answer:
Maybe one of these two plugins is what you need:
slime is screen-based.
tslime is a tmux-based version of slime.
Given the nature of your question - I encourage you to take a look at vim-ipython. Using this plugin, you can send lines or whole files for IPython to execute, and also get back object introspection and word completions in Vim, like what you get with: object?<enter> and object.<tab> in IPython.
If you follow that github link, there are a few screencasts demonstrating what you can do with it. It requires IPython 0.11 or later, though, with ZeroMQ enabled.
Related
sorry if this isn't exactly a programming question.
I mainly use Vim to edit my programs. So my question to all the Vim experts out there is:
is there a way to select and scroll in Vim? I want to copy a bunch of code, and in the pass I have always copied everything I can view on the vim screen then paste it to where-ever, then scroll down then copy and paste..repeat..until done. Is there a way I can efficiently copy a large block of code?
Formatting lines of code- you know when you copy and paste some code sometime 10 lines of code turn into 30 really messy lines of code? well, is there a command to reformat the code? In the pass I manually go back and properly indent everything which sometime is super repetitive when you got 500 lines. I saw on other sites something about the command being 1G = G can someone confirm that? when I try it in my command line, I get a error E464: ambiguous use of user-command line which I have no idea what that even means.
I do know there is a help command in Vim,but I have no idea where to even start when there is something like 200 txt files and frankly this is faster :)
Your questions are around basic use of vi / Vim. Do yourself a favor and go through a Vim tutorial; you'll find many on the web, and Vim comes with it's own introduction, vimtutor.
On Unix, if Vim has been properly installed, you can start it from the shell:
vimtutor
On MS-Windows you can find it in the Program/Vim menu. Or execute
vimtutor.bat in the $VIMRUNTIME directory.
Also, learn how to look up commands and navigate the built-in :help; it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor.
The vim way is to entirely forget selection using the mouse for more than a screenful, but to set a mark, move to the other end of the desired text, then yank to mark:
Set mark m at beginning of text with mm
Move to end of text
Yank to mark with y'm
Paste with P or p
This whole answer is only helpful if you can use register + as clipboard. Try "+yy in VIM, try to paste it in another application to see if you can use the clipboard, if you can:
You should really read the manuals and other help:
To yank lines (simple) : http://vim.wikia.com/wiki/Moving_lines_up_or_down
To address lines: Addressing in VIM
That is to start with.
Some examples of what you can do:
:.,+50y a yank 50 lines from current and 50 ahead to register a, use A instead to append to register A.
:.,/some pattern/y A yank (append) from current to first line that match /some pattern/ to register a.
"Ay/some pattern<CR> will do the same thing.
Once you learn how you should address, it's easy to combine commands with addressing, e.g. the "indenting command" =:
=} auto indent to the end of current paragraph
=/some pattern<CR> auto indent to line matching /some pattern/
Mark something in Visual mode and type = it will auto indent the selected text.
And so on... So read manuals, you will have a great use of it.
In the above examples you can use register + to "yank" to the clipboard instead of register a.
I am using RedHat EL 5. I use gvim 7.1 compiled using GTK. What I want is to be able to do an svn commit (which uses vi/vim) from within gvim. Currently the only problem is that I get output which is garbled.
For example, calling :!vi produces this from within gvim:
[7;1H~
[8;1H~
[9;1H~
[10;1H~
[11;1H~
[12;1H~
[13;1H~
[14;1H~
[15;1H~
[16;1H~
[
17;1H~
[18;1H~
[19;1H~
[20;1H~
[21;1H~
[22;1H~
[23;1H~
[24;1H~
[25;1H~
[26;1H~
[27;1H~
[28;1H~
[29;1H~
[30;1H~
[31
;1H~
[32;1H~
[33;1H~
[34;1H~
[35;1H~
[36;1H~
[37;1H~
[38;1H~
[39;1H~
[15;42HVIM - Vi IMproved[17;43Hversion
7.0.237[18;39Hby Bram Moolenaar et al.[19;29HVim is open source and freely distributable[21;36HHe
lp poor children in Uganda![22;28Htype :help iccf<Enter> for information [24;28Htype :q<En
ter> to exit [25;28Htype :help<Enter> or <F1> for on-line help[26;28Htyp
e :help version7<Enter> for version info[1;1H
How do I configure vi/vim/gvim to solve this problem and thereby enable my svn commits to look proper when called from gvim.
Thank you,
Nachum
Don't use vi as the command, use gvim -f instead.
The problem is that vi (or vim in a console) requires a terminal that can do stuff like move the cursor around, etc. gvim's pty is a very basic ASCII-only terminal.
Plain old vim doesn't have this issue because it just pipes the subporcess directly to your terminal, hence all of the escape sequences still work.
You can use gvim -f instead, so that a new gvim window will pop up for your commit message. (the -f prevents backgrounding) This isn't exactly what you asked for (since you get a new window) but it's the closest you can get to what you asked for without adding full terminal support to vim.
I use VCSCommand, a nice VCS wrapper that works with SVN, GIT and others. :VCSCommit or ,cc opens a new window under the current one, lets you type your message and does the actual commit on write. Sure that's one more plugin in your setup but the conveniance may be worth it. It is for me.
This may be an odd question, but still. I use cat to display a file in bash (KDE Konsole),
cat foobar.rb
Now, I would like to use Vim to colourize that foobar.rb file according to what you would get when you start foobar.rb in Vim. Edit: But only for display purpose, on the terminal.
I am not sure this is possible, but I thought it would be neat if I could use Vim for that.
I really just want colourized keywords, and Vim has the perfect colour definitions.
So I thought combining this would be great.
Is this possible in Vim out of the box though?
One approach would be to use a library such as Pygments, which is a general purpose syntax highlighter. You could write a wrapper called ccat or something that would apply syntax highlighting to an input file and write to stdout.
If you want to page up and down in a highlighted file, you can use less with the -R switch, which passes control characters through to the terminal directly, preserving colours. So:
ccat file.rb | less -R
But at that point, you're pretty much at the capabilities of view.
I'm not sure if I understand your question correctly, but if you are only looking for a command that will give you a read-only view of the input file (like cat) but with coloured keywords, use view. view is an alternative way to start vim in read-only mode, so you have all syntax highlighting possibilities. From the vim man page:
view Start in read-only mode. You will be protected from writing
the files. Can also be done with the "-R" argument.
gvim gview
The GUI version. Starts a new window. Can also be done with
the "-g" argument.
evim eview
The GUI version in easy mode. Starts a new window. Can also
be done with the "-y" argument.
rvim rview rgvim rgview
Like the above, but with restrictions. It will not be possi-
ble to start shell commands, or suspend Vim. Can also be
done with the "-Z" argument.
I have always seen view on systems that have vim installed.
Closest is the less script that comes with vim:
cat myfile | vim -u /usr/share/vim/vim72/macros/less.vim -
Note the - argument to vim. You may need to change the vim72 to your version (and the whole path if you have it installed elsewhere)
Now, this isn't exactly what you want, because its behaviour is less-like, in that you have to press keys to make it scroll down or complete. However, they are briefer than usual vim. For example, space to scroll down; and q to quit (not :q).
You want a cat-like version; me too. But there doesn't seem to be one.
EDIT uh, there's also a vimpager project, that includes vimcat - exactly what you want. But it doesn't come with vim, and I haven't tried it yet.
vim.org: http://www.vim.org/scripts/script.php?script_id=1723
github: https://github.com/rkitover/vimpager
How can I create a Vim command and copy it's results to clipboard?
I want to convert Markdown to HTML and copy the result to the clipboard. So far I got:
nmap md :%!/bin/markdown/Markdown.pl --html4tags
But this will substitute my opened file on Vim to the result of Markdown.
You didn't say which system you're using, but generally saving it in the +
register should work. You can call system():
:let #+=system("markdown --html4tags", join(getline(1,line("$")), "\n"))
The system() function takes the second parameter (optional) as input to the
command, and here I'm using a chain of other functions to retrieve the contents
of the current buffer. Not sure, but there should be a better way to do it (if
someone knows, please let me know).
Alternatively, you can pass markdown your file name as input directly:
:let #+=system("markdown --html4tags " . shellescape(expand("%:p")))
But keep in mind that you'll need to write the file before calling this.
Two important notes:
I didn't type your full path to markdown. Use it.
I didn't use maps here, the final result would be something like:
nnoremap md :let #+=system(...)
get the xsel package
and pipe stdout to xsel --clipboard
For instance:
cat /etc/passwd | xsel --clipboard
Is that what you're looking for?
Filling in a missing piece (2+ years late). With the clarification that the user was on a Mac and since the asker's "why doesn't it work for me?" question was not answered.
To redirect the output of a command to the system clipboard from within MacVim (GUI version) you need to set the '*' to be the "clipboard register" you need to change the clipboard setting to 'unnamed':
set clipboard 'unnamed' # 'cb' can be substituted for 'clipboard'
Then sidyll's answer should work except specify the '*' register and not the '+' register:
:let #*=system(...)
The clipboard feature is likely not compiled into the "terminal version" of MacVim and when it is available option setting is different from 'unnamed'. To see more details regarding what works where and how, see the documentation in MacVim using the Vim help command:
:help 'clipboard' (include the single quotes since it's a set option!)
(I'll skip the command mapping issue since it always takes me several tries and I still have to look it up; finding the help for the mapping commands should be easier than finding it for the * register.)
I have a vim function set up where I can highlight a line of text and execute in clojure. Here's the function:
function! Clojure_execline()
let cl = (getline(line(".")))
// ...
exec 'clojure -e "' . cl . '"'
endfunction
The problem with this is that it's slow to start and because it spawns a new clojure session every time I run it, I can't call a function I ran previously. Ideally, I'd like for a hidden repl to be running where I could send input from vim and retrieve the output from as well. I learned about gnu screen and thought it could help me, but I don't know how to send input from one screen window to another.
To clarify my problem, take this line of clojure:
(defn add2 [x y] (+ x y))
I'd like to be able to highlight this line in vim and execute in a running repl. I want to be able to call the line below and have it execute in the same repl:
(add2 4 5)
Afterwards, I'd like to be able to get the output of the function.
So, basically, my question is, how do I send input from one screen window to another?
Jake McCrary's suggestion is a good one. There are also a couple other scripts available, probably based on same idea:
VimClojure, which says it does "repl in a vim buffer"
and
slimv, specifically supports Clojure
and
Gorilla, I think VimClojure, above, is based on Gorilla
I don't know whether VimClojure actually does what you want, sending result back from Screen to buffer in Vim. One way to do that, I think, would be to finagle something using Vim's client-server functionality, possible with the --remote-send flag. See:
:h client-server
:h --remote-send
I don't have an exact answer, but it might be worth taking a look at slime.vim and seeing if anything can be learned from it.
blog post about it
script at vim.org
Found what I was looking for. You can execute this from a terminal to send a string directly to the stdin of a screen window:
$ screen -X stuff "ls -l\015" # \015 sends a carrige return.
You might also be interested in Conque http://code.google.com/p/conque/
I use it for Scala