Wednesday, August 22, 2012

Re: gedit to gvim/vim teething issues

naphelge, Wed 2012-08-22 @ 12:26:36-0700:
> two of the great things about gedit I find indispensable is the
> snippets and ext tools plugins. Discovered UltiSnips plugin for vim
> and it is ok, far from ideal. I can't seem to enter snippets without
> preceding them with a space first, even though the previous character
> is generally a <> bracket. Are there any snippet managers available
> that work more like gedit's, that allow a snippet to tab forward
> immediately after a > bracket?

snipMate [1] is a popular snippets plugin that lets you use the <Tab>
key (or whatever you want) for expansion.


> gedit's ext tools is great for entering little bash scripts, but I
> cannot seem to figure out how to do similar with vim. Do I need to
> port all of my gedit ext tool scripts into individual bash scripts and
> run them from my ~/bin dir? Because I have too many to remember and
> the menu in gedit listing all of the scripts has always seemed rather
> convenient. Plus, running scripts from within gedits ext tool menu,
> the script acts on the current file without any need to bother
> specifying paths.

I can't say that I know exactly what you mean by "ext tools", but if
you're wanting to filter the text in a Vim buffer through an external
program, you can do that with the `:{range}!` command. See `:help
:range!`

If you want to add your external scripts to a drop-down menu in GVim,
there are commands for doing that as well (creating new menus, adding to
existing menus, etc.), though I won't be able to help you much there as
I personally use Vim in the terminal and avoid the mouse as much as
possible, so I never use menus.


> Like I said I hope most of my issues are simply teething probs. But I
> generally edit a lot of text using sed from the terminal and somehow
> the :%s option in vim seems less than adequate. I can't seem to figure
> how to invoke the -r option for regex. Is that possible.

`sed -r` switches between POSIX BRE syntax and ERE syntax. Vim's regexes
are neither; Vim has its own regex syntax. However, you may be
interested in the various "magic" settings and their effects. See `:help
/magic`.

In short, you can put a \v in your regex pattern to turn on "very magic"
mode, reducing the number of characters that need to be escaped, so you
don't have to type so many backslashes.


> I would be just as comfortable, actually perhaps more so if I could
> just open a terminal in the current dir of a file I am editing and run
> sed/perl scripts that way. In gedit I have always remapped C-t
> (ctrl+t) to open a terminal in the current directory of the current
> file. Is there any way to do that using gvim?

`:shell` starts a shell in your current working directory. Also, `:!`
can be used to run shell commands directly from Vim's ex command line,
which is usually faster.

If you want the <Ctrl+T> mapping you're used to, you can put this in
your .vimrc:

nnoremap <C-T> :shell<CR>

but keep in mind that <Ctrl+T> already means something in Vim (pop the
tag stack), so you're overwriting that existing command if you do that.
You may want to choose a different mapping instead.


> Oh yeah, one other thing. I got tabs sort of working in gvim...but,
> for some reason, if I open a new nautilus/thunar session to open a new
> file then it opens in a new gvim window and does not open in a new tab
> of the already existing gvim window. Any ideas on that would be great
> also. I love tabs!

It's more common to use buffer management to accomplish in Vim what you
would use separate tabs for in other editors. In the long run, you'd
probably benefit from learning more about Vim's buffers instead of
relying on tab pages.

But in any case, if you want to send files to an existing Vim session in
a new tab page, first start Vim with:

vim --servername YourServerNameHere

(use whatever you want for the server name). Then send files to it with:

vim --servername YourServerNameHere --remote-tab foo.txt

If you use the same server name frequently, you may want to define a
shell alias that always launches Vim with the same server name option,
to save yourself some typing.


> I also forgot to ask about vim's clipboard. I seem to be getting it
> confused with buffers. Does vim have a clipboard that stores multiple
> copy/yanks and cuts? I use parcellite precisely because I like to keep
> a long buffer of copy/cut stuff that I tend to need later on.
> Everytime I try to find info on any functionality like this in vim I
> seem to get pointed to buffers, which seem to be alternate
> simultaneously being managed by vim.

Buffers are the term for Vim's in-memory representation of a file that
you have opened. They have nothing to do with yanking and pasting,
really.

Vim's equivalent of a clipboard is referred to as "registers". Registers
are identified by a single character. There are a lot of registers
available, some of which are general-purpose (registers a-z), and some
have special purposes (using non-alphabetic characters). See `:help
registers` for lots of details.

When you use the yank command, by default text is yanked into the
default register, identified by the " character. You can yank into a
different register by prefixing the yank command with "<char>, where
<char> identifies the register to yank to. For instance,

"ayy

yanks the current line into the 'a' register. Pasting works the same
way.

If your Vim is compiled with the right configure flags for clipboard
support, then the * and/or + registers can be used to yank/paste to/from
the OS-managed clipboard or X primary selection instead of an internal
Vim register. See `:help clipboard`.


In general, it really pays to get used to navigating Vim's built-in help
system. Virtually every aspect of the editor is painstakingly documented
there. If you can learn how to use help, everything else you might want
to know will follow. There is a table of contents available at `:help
user-manual` that might serve as a good jumping-off point for finding
out about Vim's features.


Hope that gets you on the right track. Feel free to ask if anything
needs further clarification.


[1] http://www.vim.org/scripts/script.php?script_id=2540

No comments:

Post a Comment