23

The only difference between single and double quoted string is related to backslash. To display special characters like newline, bells, tabs, etc, you need to use double-quotes -> "\n". Within a single-quoted string, '\' is itself => '\n' is a two-characters string (a backslash + n). Within double quotes, you have to double it -> "\\", which makes them un-...


12

The function you are looking for is fnameescape(). It will escape all special characters in a given string containing a path to a file to match the standard of the current operating system. For more on this see :help fnameescape()


11

To repeat a string you want to use the (appropriately named) function repeat() The doc is here :h repeat() And you can use it like that: let foo = repeat("abc", 3)


9

Your solution is very elegant! An alternative if you are in Unix based env: !!rev


8

str1 < str2 should be enough. From :h expr-<: use 'ignorecase' match case ignore case equal == ==# ==? not equal != !=# !=? greater than > ># >? greater than or equal >= >=# ...


6

It is not exactly clear what you would like to happen when e.g. one register contains a linewise selection and the other one contains a block selection. But for the easy case, you can always do (as noted in a comment) :let @c=@a.@b and have the concatenation of register a and b in register c. But note, this might have funny effects, if the registers ...


6

The reason your example attempts don't work is that in many locations text is simply seen as a literal string, rather than VimScript. So functions, variables, and the like don't work. For example, if you do: :let var='value' :set option=var Then Vim will simply set the value of option to the literal value var, since it doesn't recognize VimScript in :set. ...


5

Somewhat unsurprisingly, it's printf(). I wasn't 100% sure what the name was from the top of my head; I found this by just entering :help printf :-) I also find :help function-list to be invaluable when VimScript-ing. Also see: How do I navigate to topics in Vim's documentation?.


5

Where does this extra byte prefix come from? literal holds an UTF-8 encoded string. <80> is encoded in two bytes according to UTF-8 standard specification. Here bold bits are used by UTF-8 decoder only. The remaining 11 bits are the value of 0x80 prefixed with 3 zero bits. 1 1 0 0 0 0 1 0 | 1 0 0 0 0 0 0 0 1 1 0 --- the next char is encoded in ...


4

Vim's comment formatting only handles comment characters that appear at the start of the line. However you could make use of the list formatting facility (:help 'formatlistpat') that kicks in when n is in 'formatoptions'. So, define an appropriate pattern: :set flp=^.*::\\s\\+ (You may need to adjust this: I don't speak Python.) Then add n to '...


4

Pressing <C-v>ude90 in insert mode should work. The problem is probably: let g:indentLine_char = <de90> which is missing quotes; it should be: let g:indentLine_char = "<de90>" (where <de90> is entered with <C-v>, and not 6 separate characters). See :help i_CTRL-V and :help i_CTRL-V_digit.


4

You are close. You need to use this form: :let foobar="\u1234" Using "\u" allows to use up to 4 hex digits. Until recently, it was not possible to use more, but with newer Vims you can now use "\U" plus up to 8 hex numbers. The details are explained at :h expr-quote


4

Using ex Ex is the command-line successor to the venerable ed, a line-oriented editor. You can access ex-mode from vim by typing Q (unless you have it mapped). gQ gives an improved ex-mode. See :help Ex-mode. You can also start ex from the command line, just like vim: ex {file} Then you type your commands, and ex does them. All the :-style commands ...


3

ex -s +'norm! gg"adiwdd' +'exec printf("%%s/^/%s : /", @a)' +'x' ex_txt norm! gg"adiwdd delete black in 1st line to register a, delete first line exec printf("%%s/^/%s : /", @a) add content of register a to start of every line. You can get content of register a via @a or getreg('a') in ex mode . check :h printf() if you have problem with %%. x save and exit ...


3

In vim dot is a concatenation operator: let repo = $Project . '/cfora' To "refer" variable in the string, well, in your case it is just a concatenation again: exe '!cmake ' . repo PS I would suggest to use built in make facilities for this. And vim lcd instead of exe '!cd ...


3

@D.BenKnoble has already given you a terrific answer explaining all the ins and outs of batch mode, but in case you were looking for a one liner similar to the one you already tried, here's one that I think is a bit simpler than the existing ones in the current answers: ex -sc 'norm!ggy$dd' -c '%norm!i^R0: ' -c 'x' file The first :normal command moves to ...


3

I think your solution might work, but I think this is a slightly cleaner and more readable version: function ProjectName() let l:path = expand('%:p') return (l:path =~# '^/home/karl/source/.\+') \ ? substitute(l:path, '^/home/karl/source/\([^/]*\)/.*', '\1', '') \ : '...' endfunction Also, it seems you add the brackets [...] both ...


3

From wikia vnoremap <Leader>r c<C-O>:set revins<CR><C-R>"<Esc>:set norevins<CR> For more see: :h revins


3

When registers only contain strings, we can do it with the old :let @c = @a . @b If you want to handle the registers as lists (one element per line), then you'll need to use the new functions described by @statox, but beware, lists are concatenated with +, not .. :call setreg('c', getreg('a', 1, 1) + getreg('b', 1, 1))


3

Let's say you want to merge "a and "b into "c: call setreg('c', getreg('a').getreg('b')) You can of course replace a, b and c by whatever register you want. For a bit more of details: getreg('x') will return the content of the register x as a string. In vim you can concatenate two strings with . like this: let str1 = 'foo' let str2 = 'bar' let result = ...


2

You could use external commands to do that. Take for example, giving that the buffer has only the content you share the following commands: %!awk -F ',' '{print length($1) "|" $0}' %!sort -nr %norm df| would result in this contents: "Be(C<sub>5</sub>H<sub>7</sub>O<sub>2</sub>)<sub>2</sub>","Be ...


2

^ in s/^/.../ is a regexp, not a visual mode command. I suggest the following mappings: vnoremap <expr> <Leader>c ':s/^\s*\zs/'.escape(g:CommentChar, '/\').'/<CR>:noh<CR>' vnoremap <expr> <Leader>C ':s/^\s*\zs\V'.escape(g:CommentChar, '/\').'//<CR>:noh<CR>' Better yet, you should consider using one of the ...


2

If you are using a unix-like system, in vim, type ex-command :%! rev


2

Thanks to @romainl's comment for pointing me in the right direction. Here's my solution: function ProjectName() if expand("%:p") =~ "^/home/karl/source/[^/]*/" return "[" . fnamemodify('', ':p:s?/home/karl/source/\([^/]*\)/.*?\1?') . "]" else return "" endfunc


2

For this there is the function stridx(). let a = "Vi and Vim" let b = "and" echo stridx(a, b) " echos 3 If the substring is not found stridx() returns -1. The function also supports a third argument to specify the start index to search from. See :help stridx().


2

Note that you don't need to execute external processes with system() which adds trailing newlines & all. let os = matchstr(filter(readfile('/etc/os-release'), 'v:val =~ "^NAME"')[0], '.*"\zs.*\ze".*') with: readfile() to read the system file filter() to keep only the line with NAME= matchstr() with extract the content of the name field (in the first ...


2

It's not working, because what you have inside operating_system variable is a bit more, than just CentOS Linux. First of all, those quotes " are part of the string. Checkout contents of that file. If you use = as a separator, second field actually contains " characters (at least that's the case on my system). Also, there probably is some invisible magic ...


2

To answer my own question: 1) There is no internal function to get a character at a byte offset. 2) How is the performance of the script function? Surprisingly: Very good. I hacked Vim and added a new function called strcharatbyte(str, index) that returns the same list as the script function s:GetCharAtByteIdx in my question. Then I ran the tests for my ...


2

The problem is that you can't really use :normal in terminal mode, since that mode is special, it doesn't really behave like Normal/Insert mode in a normal vim buffer. Instead, you can use the term_sendkeys() function to send the buffer to the terminal. This should work: :execute "normal yaw\<c-w>j" | call term_sendkeys('', @0) Or: :execute "...


2

A little experiment: Go to your fresh opened terminal, and do an echo: echo 1 Leave it in terminal job mode, go back to your original window, execute: exec "norm! \<c-w>pggyy\<c-w>pp" You should see a new line in your current buffer, it's copied from first line of terminal buffer. As ggyy are normal mode commands, it tells us that when you ...


Only top voted, non community-wiki answers of a minimum length are eligible