vim on mac /V stops at the first occurrence of /abc
e.g.
/\Vthis/is/a/path
would stop searching/matching after /
Any clues?
I am not looking to d
:let #/="this/is/a/path"
if searching string with / is your question, you could
use /, and escape the / -> \/
use ?, like ?this/is/foo/bar then N
usually I would take the 2nd option.
Related
I have multiple lines of plain texts and each line is mixed with phrases with/without double quotes. I want to delete everything including quotes but keep what's in double quotes.
Example:
this is some test = "key.properties";
properties = "value.properties";
Result should be:
key.properties
value.properties
:%s/.*\"\(.*\)\".*/\1
Explanation
REPLACE, ANY_STRING, QUOTES, CAPTURE_ANY_STRING, QUOTES, ANY_STRING WITH
:%s/ .* \" \( .* \) \" .* . /\1
If your cursor is at the start of the line, you can do:
f"lyi"Vp
f"l move cursor to first " then left one more space
yi" yank everything within the "s to the anonymous register
Vp select the whole line in visual mode and paste the anonymous register over it
To apply to multiple lines, use the normal command.
:%normal 0f"lyi"Vp
: enter command mode
% set the range as the whole file
normal execute the following key strokes as if they were entered in normal mode
0 move cursor to start of line
f"lyi"Vp see above
I have lines that I want to convert from
(variable=value)
to
((variable=value))
How should I go about doing that from the vim command line?
May be you can use following substitute command
:%s/(.*)/(&)/g
where
.* - all strings of characters of any length and
& - the whole matched pattern
This is commonly done with the surround.vim plugin: First select the single-parentheses block with va(, then surround with another set of parens via S(.
One possible solution (if you have only this pattern in the line):
:.s/.*/(&)
.s ................... current line substitute
.* ................... everything
( .................... open paren
& .................... all pattern searched
) .................... close paren
Or
:norm! I(^[A)
OBS: The simbol ^[ should be typed with Ctrl-vCtrl-[.
Don't forget you can repat the last command : in the current line by typing #: and in the subsequent lines ##.
In normal mode With no plugins you can do this (if the pattern does not repeat a lot):
ca( ................ start changing the pattern (text goes to default register ")
( .................. start typing open parenthesis
Ctrl-r" ............ insert default register
) .................. close parenthesis
OBS: This action is repeatable by typing .
I would like to move between the command line arguments in a fast way. For example, if I have the following command line:
> do_something_with /very_long_path/to_a_very_long_directory/ more_args
^ ^
I would like to skip the whole path (jump between the ^ symbols). I'm already familiar with word mode (Alt+B and Alt+F) but in some scenarios it's not enough to navigate quickly between the arguments.
In bash, you can set the cursor to the previous given character using the following features:
character-search and character-search-backward features.
ctrl+], (resp. alt+ctrl+]) + searched_character
In your example, you can search backward for a space.
> do_something_with /very/long/path/\ with_spaces\ directory/ more_args
^ ^
Unfortunately, this will not work so well with paths like:
> do_something_with /very_\ long_path/to_a_\ very_long_directory/ more_args
As a sidenote, you can use ctrl+a and ctrl+e to go at the beginning / end of a line.
There are (quote from manual)
shell-forward-word ()
Move forward to the end of the next word. Words are delimited by non-quoted shell metacharacters.
and
shell-backward-word ()
Move back to the start of the current or previous word. Words are delimited by non-quoted shell metacharacters.
I have bound them to Ctrl+Alt+F and Ctrl+Alt+B by adding this to my .inputrc:
"\e\C-f": shell-forward-word
"\e\C-b": shell-backward-word
For vi/vim users ctrl+] + char can be used to quickly navigate to the first occurance of a given char. Which is equivalent to f + char in vi/vim.
how do i do this in vi?
awk -F"," awk '{print substr($1,1,10)}'
I only want to keep the first 10 characters of my date column (example 2014-01-01) and not include the timestamp.
I tried to do it in awk but i got this error:
sed: RE error: illegal byte sequence
I believe it is a bash_profile setting error.
This is what i have in my bash_profile:
#export LANG=en_US.UTF-8
#export LOCALE=UTF-8
export LC_CTYPE=C
export LANG=C
in vim, do:
:%norm! 11|D
this will affect all lines in your buffer.
If you like, :s could do this job too.
:%s/.\{,10}\zs.*//
:%s/: apply the substitution to all the lines
.\{,10}: match anything up to 10 times (greedy)
\zs: indicates the beginning of the match
.*: match the rest of the line
/: end of the first part of :s
/: end of the second part of s (since there's nothing between the two /, replace with nothing, ie delete)
For editing blocks of text there is a -- VISUAL BLOCK -- mode accessible via CTRL-V (on Windows ussually CTRL-Q). Then you can press d to delete your selection.
Or with a simple substitute command
:%s/\%>10c.*//
\%>10c - matches after tenth column
. - matches any single character but not an end-of-line
* - matches 0 or more of the preceding atom, as many as possible
Or you can use range
:1,3s/\%>10c.*//
This would substitute for the first three lines.
I'd like to map vim's 'keywordprg' to Dash, namely, use K to do !open dash://word-unser-curse.
Currently, I'm doing this:
:let &keywordprg '!open dash://'
but it says E34: No previous command.
from :h E34:
Any '!' in {cmd} is replaced with the previous
external command (see also 'cpoptions'). But not when
there is a backslash before the '!', then that
backslash is removed. Example: ":!ls" followed by
":!echo ! \! \\!" executes "echo ls ! \!".
Thus you have to escape ! in order to have vim treat as it is, otherwise vim tries to replace it with the "previous command", resulting in the error.
Additionally, I don't think you need that ! in your keywordprg. Vim calls it as an external command anyway (the default value is man, not !man).