Control-V :w <fname> : how to write single character?

9 views
Skip to first unread message

L A Walsh

unread,
Nov 3, 2021, 3:37:09 PM11/3/21
to Vim Users
I wanted to write out an unclear character that my
cursor was over, so I tried to go into character VISUAL
selection mode by pressing Ctl-v, then ':w! /tmp/ch'.
Instead of the single character at the cursor, I got
the whole line. I also tried with a lower case 'v'.

When interactive, selecting with either 'v' or 'ctl-v'
and hitting 'y', then pasting it somewhere, only 1
character is selected.

How would I write out only the 1 character I had
selected?

thanks,
-linda

Tim Chase

unread,
Nov 3, 2021, 3:54:52 PM11/3/21
to vim...@googlegroups.com
On 2021-11-03 12:36, L A Walsh wrote:
> I wanted to write out an unclear character that my
> cursor was over, so I tried to go into character VISUAL
> selection mode by pressing Ctl-v, then ':w! /tmp/ch'.
> Instead of the single character at the cursor, I got
> the whole line. I also tried with a lower case 'v'.

The ex ":w" command is linewise, regardless of what visual-mode you
were in, so you'll get the whole line.

> How would I write out only the 1 character I had selected?

You might try yanking it and then using the writefile() command

:help writefile()

to write that register out to a file:

:call writefile(@", '/tmp/ch', 'b')

As a further alternative, you might investigate the "ga" &
"g8" commands

:help g8
:help ga

which will tell you further information about the particular
character under the cursor.

Hope this helps,

-tim








c.willis111

unread,
Nov 3, 2021, 4:01:44 PM11/3/21
to vim...@googlegroups.com
Hi Linda

having yanked your character (as in your last paragraph), open a fresh file

:e a
insert the character
P (or p)
and write it out
:w

regards - Chris


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/6182E4DB.3040904%40tlinx.org.
Reply all
Reply to author
Forward
0 new messages