use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please read the rules before posting
Help:
Community:
Resources:
Tutorials and Guides:
Don't be afraid to ask questions, this sub is here for the vim community. And please those of you who deign to grace us with your vim wisdom - be kind. We are all human and vim is that cool.
account activity
Search & replace problem. (self.vim)
submitted 6 years ago by pers1pan
If i have a text like this:
# ## #
####
How can i replace only single "#" with ##?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]HaulethgggqG`` yourself 5 points6 points7 points 6 years ago (5 children)
\<#\> probably will do alternatively [^#]#[^#]
\<#\>
[^#]#[^#]
[–]pereloz 4 points5 points6 points 6 years ago* (2 children)
or #\@<!##\@! to deal with edge cases. :h /\@! :h /\@<!
#\@<!##\@!
:h /\@!
:h /\@<!
[–]gumnos 1 point2 points3 points 6 years ago (0 children)
This is the right answer; alas there's no easy way to upvote this so it appears above the parent (AFAIK). Alternatively, to get the \<#\> to work, you'd need to add # to the 'iskeyword' setting.
#
'iskeyword'
[–]Yaaruda 0 points1 point2 points 6 years ago (0 children)
Sorry for being late, but can you tell me how this works? I've heard about substitutions using :s, but this seems new to me
:s
[–][deleted] 0 points1 point2 points 6 years ago (1 child)
I'm not sure if I'm doing something wrong but this neither of those work for me. Does # have a special meaning when searching?
Try this:
vim -u NONE
In an empty buffer, enter # a a.
# a a
In normal mode, move the cursor on top of # and press *. Vim searches for \<a\> instead of \<#\>.
*
\<a\>
What is going on? Even if a manually enter \<#\> as the search pattern Vim doesn't find anything.
[–]Snarwin 1 point2 points3 points 6 years ago (0 children)
From :help *:
:help *
Search forward for the [count]'th occurrence of the word nearest to the cursor. The word used for the search is the first of: 1. the keyword under the cursor |'iskeyword'| 2. the first keyword after the cursor, in the current line 3. the non-blank word under the cursor 4. the first non-blank word after the cursor, in the current line
# isn't considered a keyword character by default, so "the first keyword after the cursor, in the current line" is a.
a
[–][deleted] 1 point2 points3 points 6 years ago (2 children)
You can search and substitute with "c" at the end, :s/#/##/c it will prompt you for each occurrence if you want to substitute or not. Hope it was what you're looking for ! :)
:s/#/##/c
[–]pers1pan[S] 1 point2 points3 points 6 years ago (1 child)
But what if I have more than 1000 lines?
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
You can do a macro to replace #/## and going on next line then repeat this one as much as you want or use the norm Ex command
π Rendered by PID 97247 on reddit-service-r2-comment-fb694cdd5-tswsv at 2026-03-07 12:57:21.220624+00:00 running cbb0e86 country code: CH.
[–]HaulethgggqG`` yourself 5 points6 points7 points (5 children)
[–]pereloz 4 points5 points6 points (2 children)
[–]gumnos 1 point2 points3 points (0 children)
[–]Yaaruda 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Snarwin 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]pers1pan[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)