We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [string-manipulation]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
5
votes
1answer
504 views

What is the difference between <C-V>x and \x?

Run the following commands, where <80> is a literal byte entered by typing Ctrl-Vx80: let literal = "<80>" let quoted = "\x80" echo(literal) and echo(quoted) will now both output <80&...
3
votes
1answer
45 views

How do I use a variable or return value in option, command, or mapping?

I have a variable foo with let foo='value', and a function F like function F() return 'value' endfunction and I want to use them in an option: :set option=foo, :set option=F(); or in a command: :...
1
vote
2answers
71 views

Insert text in the middle of a string vimscript

I'm trying to make a function in vimscript that converts markdown to html files using pandoc and putting that converted file in a specified directory. Currently i am putting the file in a directory ...
1
vote
1answer
55 views

How to assign a Python list to a vim variable and escape its strings correctly

Here is a Python list that I'm trying to assign to some Vim variable. lines = ['"""Something foo\'s thing."""', '', 'foo = "asdfasdf" \\', 'bar'] command = 'let l:corrected_lines = {lines}'.format(...
1
vote
3answers
143 views

Command to copy from current window and paste the text into terminal buffer

I am having trouble crafting a command that would copy the text from the current window and paste this text into a terminal buffer opened in the split below. Here are a few things I tried: normal ...
1
vote
0answers
40 views

What is the correct character for splitting a string on line breaks in Vimscript?

Consider the following text file. line1f line1n line2 Suppose I visual select this, yank it into register a, and then pass it to the following vimscript function: function TestSplit(block) for x ...
3
votes
1answer
119 views

Reliably get the character at a byte index in a string

I'm doing some string processing in vimscript. I obtained a byte index for a character in the string and now want to obtain the character at that byte index. For single-byte charsets (like latin1) ...
1
vote
4answers
175 views

In Vim ex mode how to re-use a string from the default buffer in the command

I'm trying to modify this file, by extracting the very first line in the file and prepend it to each of the consecutive lines until end of the file black widow card Friday berry I used ex command (...
1
vote
1answer
130 views

How to check if a string is a substring of another string

I was wondering what is the proper way to test whether a substring is included in some other string. If I want to check if string a is part of string b, I'm currently using matchstr(b, a) != "" to ...
0
votes
1answer
43 views

How to generate a string by concatenating another string with an environment variable

I need to create a variable with a fool folder direct which need to concatenate from a environment variable and the end notes function! MyFoo(arg) let repo=$Project + "/cfora" #Q1 ...
2
votes
1answer
143 views

How to autoformat a multi-line string

I want to format a multiline string according to a textwidth of 32. group: - normal: scalar - multiline: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor ...
1
vote
2answers
108 views

String comparison not working as expected!

So I want to figure out the Operating System and execute a piece of code based on the operating system in my .vimrc. However, I'm not able to understand where I'm going wrong. let operating_system = ...
1
vote
1answer
70 views

Get <Leader> value as <Space> and not ' '

Given that I defined let mapleader="\<Space>", I would like to get in the vimscript the value of the leader as <Space> and not as ' '. The latter may be obtained by using get(g:,"mapleader"...
2
votes
1answer
2k views

How can I extract text between two parts in a single line in Python? [closed]

Let's say the lines in words.txt look like this, for example: Cute Stack 10 Dog Fire 384 Phone Real 485 I want to check if the middle text in each line (stack, fire, real) is equal to a ...
4
votes
1answer
2k views

vimscript: how to repeat a string N times?

I know . operator concatenate strings. But how to repeat a string N times, similar to "abc" * 3 in python?
4
votes
4answers
1k views

How to concatenate two registers?

Is there some built in functionality in Vim to merge the contents of two registers into a single register by appending the two?
0
votes
1answer
2k views

What is the vimscript version of sprintf?

I'm trying to create a dynamic line to execute, currently I have execute a:modes[i] .'noremap <silent> <buffer> '. l:key .' <Esc>:call HardModeEcho(g:HardMode_hardmodeMsg)<CR>...
0
votes
1answer
105 views

How do you sort lines by longest substring to shortest substring?

Here are some sample strings, sorted by longest string to shortest sting: "Bi(NO<sub>3</sub>)<sub>3</sub>·5H<sub>2</sub>O","bismuth nitrate pentahydrate"); "Be(C&...
6
votes
1answer
1k views

How do I alphabetically compare two strings

Is there a standard way to compare two strings in vim so that I can quickly determine which string is sorted before the other. Something like strcmp(str1, str2) to return 0 if str1 == str2, 1 if ...
18
votes
1answer
2k views

What is the difference between single and double quoted strings?

What is the difference between single and double quoted strings? Is there a way to get a variable expanded inside a string, or do they always need to be joined like: 'Hello, ' . s:name . '!'
4
votes
1answer
269 views

Align code functions documentation

Is there an easy way to align a function documentation (I'm using Python) from this: arg1 :: Some text arg2345 :: Some very long text text text text arg3:: Other text to something like: arg1 ::...
2
votes
1answer
62 views

Running find-and-replace in Visual Mode :'<,'>s/^/string/g inserts “string” at 0 position instead of ^ (first non-whitespace) position

I have some visual-mode commenting macros that should place a comment character g:CommentChar before the first non-whitespace character of each line in the selection. However, it places it right of ...
2
votes
2answers
154 views

How to extract part of the current working directory to the statusline?

I have a lot of projects of the form: /home/karl/source/project-name/further/hierarchy/... I would like to extract just the project-name to put into my statusline. I use autochdir, so I know I can ...
4
votes
3answers
359 views

How can a character be inserted during an edit session by its Unicode numeric value?

I'm trying to set up a plugin to enable indentation guides, following an answer to this question. The plugin is Yggdroot/indentLine. It has instructions to set up a custom glyph to be shown instead of ...
6
votes
0answers
36 views

Expand strings into multiline strings on line wrap [duplicate]

This is a feature in Eclipse that I would love to find a solution for in Vim. I have Vim set up with tw=80 so that the lines wrap at 80 columns. When I'm in the middle of a string, and the line ...
8
votes
2answers
4k views

How to deal with string containing spaces in Vim script?

I have the following command in my vimrc: execute "set path+=".getcwd()."/**" It works well if current working directory is like /home/tamlok/my_work/. However, if the directory contains spaces, ...
10
votes
3answers
2k views

How do I reverse a string with Vim script

I am trying to reverse a string, so that 'abc defg hij' becomes 'jih gfed cba'. The solution I came up with is join(reverse(split(l:text, '.\zs')), '') Is there a more elegant solution or should I ...