One option is to take the current line, then the substring starting at the current position, split it into multiple words and take the first one. Or, in Vimscript:
let word = split(getline('.')[col('.')-1:])
One alternative is to use a normal mode command such as yW and then access the contents of the default register (or, better, use a named register.) ...
what's up with those 5 empty strings at the end?
matchlist() always returns the list of 10 items (the matched string and nine submatches - just like \0, \1, ..., \9 in :h sub-replace-special). The last five weren't used, so they are set to empty strings.
universal-ctags provide readtags to filter tags:
Read all members of a struct:
readtags -Q '(and (eq? $kind "member") (eq? $scope-name "struct_name") )' -l
(and (...) (...)): (...) and (...)
(eq? $kind "member") restrict kind to member
(eq? $scope-name "struct_name") restrict scope-name to struct_name, your tag fields must include Z for this to ...
@Matt is absolutely right; you might use double backslashes:
let s:os = system("sed -n 's/^NAME=\\(.*\\)/\\1/p' /etc/os-release")
or switch to a single-quoted string:
let s:os = system('sed -n "s/^NAME=\(.*\)/\1/p" /etc/os-release')
But here's a tidbit: Here documents are also available as of vim 8.1.1362:
let s:command =<< trim END
sed -n "s/^...
Why don't you disable the wrapping momentarily while the function is executing?
function! CountAll() abort
let ws = &wrapscan
keepjumps normal! gg
" FIXME: If the first word is an error, count it
" - may be with a reverse search?
" - Or by testing the syntax highlighting under the cursor
let nb = 0
let p ...
As it has been explained, this function will always assume 9 submatches can exist and it will return an entry in the result list for all possible submatch. Hence the 5 extra elements returned.
On a practical note, this means that we cannot call it this way
let [all, a, b, c, end] = matchlist('acd', '\v(a)?(b)?(c)?(.*)') " fails
But we don't have to fill 5 ...
:noh is executed automatically
Well, that's kind of prohibited.
The last used search pattern and the redo command "." will not be changed by the function. This also implies that the effect of |:nohlsearch| is undone when the function returns.
Note that internally all autocommands are functions, so :noh inside an autocommand ...
As a first resource on files, buffers, tabs, etc., I recommend this QA and the many links to be found there.
As for autocommands, they are indeed an advanced topic, so having a good grasp of the fundamentals is crucial. In particular, when you start editing a file in a new tab (such as via :tabedit), either BufRead or BufNewFile should fire (Learn Vimscript ...
The usual way to get the printed output of an Ex command such as :pwd is to use the execute() function.
However, in this specific case, you can get the current directory in a more straightforward way by simply calling getcwd():
let b:projectroot = getcwd()
The issue with execute() in this particular case is that you get leading whitespace in your result, ...
The trouble you're having is with the backslashes inside the string (as @Matt correctly pointed out in the comments.)
Vim strings (using double-quotes as delimiters) interpret the backslash as a special character, so you need to escape them with an additional backslash if you want to use them in a double-quoted string.
let s:os = system("sed -n 's/^NAME=\\(...
At this time, I have something extremely similar in my lh-cpp plugin for C++. Within a class context, I type :Constructor init, and my plugin will fetch all the member data (thanks to the API of two other plugins of mine: lh-dev + lh-tags) and generate the constructor. We aren't far from what you wish to accomplish.
The first step will be to extract the ...
I'm just going by the help doc in github but it appears that 'NERDCreateDefaultMappings' does exactly what you want for the first part, ie. toggle on/off all mappings (bindings)...
If set to 0, none of the default mappings will be created.
Then you can manually bind to your heart's content. The help for NERDCommenterMappings has a bit of advice for that:
I think the main problem is that the search() function is moving your cursor. You can fix this by passing the 'n' flag:
let newBG = search(searchString, 'n') != 0 ? "green" : "red"
Then you have the problem that when you first type / the code highlights the status line according to the previous search. The cleanest way to fix is this not to run the code if ...
You can get a workflow that's close to what you want without configuring vim at all.
You can jump to the nth buffer using <C-^> (ctrl + 6).
If you type a digit while viewing the output of ls, then that digit is stored and can be passed to the next command.
In order to produce the fake vim screenshots, I increased the font size so I can only see a ...