The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

6

You can use the atom /\&. This is like forcing two different regular atoms to match at the same position. Now it becomes a bit complicated, since the cursor position can be anywhere inside the <<..>> and then you also want to allow whitespace inside those <<..>>. This makes it a bit complex to match the correct item if there are ...


5

Can it be written? Yup. command! -nargs=* -complete=command KeepCursor \ let [s:view, s:win] = [winsaveview(), win_getid()] | \ try | \ execute <q-args> | \ finally | \ if win_id2win(s:win) | \ call win_gotoid(s:win) | \ endif | \ keepjumps call winrestview(s:view) | \ endtry Can it ...


4

One solution is to use a lookahead before the regex and a lookbehind after the regex. That ensures the cursor is after the start of the match, and before the end of the match. One issue with the regex you're using is .\{-} which is a non-greedy operator. If you add anchors for the cursor position, this will end up matching from the beginning of <<one ...


3

Can it be written? Possibly, but it might be a lot harder than expected. Because, what do you do with commands that close the current window? Or commands, that add lines above the current cursor position? One problem you are running into is described unter :h function-search-undo. The last used search pattern and the redo command "." will not be changed ...


2

Currently, only marks are automatically adapted to changes in the buffer by Vim. You can record arbitrary positions via getpos(), but these would have to be adapted to changes on your own (and that is not generally possible if you have no control over the changes that are done). Plugins usually "reserve" some marks for their use, either by documenting it ("...


2

The following works and is faster than the matchstr() solution: fun! Getchar() return strcharpart(strpart(getline('.'), col('.') - 1), 0, 1) endfun nnoremap GG :echo Getchar()<CR> See my question Reliably get the character at a byte index in a string.


2

I would get the characters on the current line from the cursor and on and check if they match the end-of-word atom, i.e. something like this: map <silent> q :call Test()<cr> function! Test() abort return strcharpart(getline('.'), virtcol('.')-1, 3) =~# '^\w\>' endfunction Here I've added a map for making it easy to test. You can adjust ...


2

See :h getcurpos() Basically there is an example: This can be used to save and restore the cursor position: > let save_cursor = getcurpos() MoveTheCursorAround call setpos('.', save_cursor) So you can try it with smth like (untested): nnoremap <C-f> :let save_cursor=getcurpos() <bar> %!clang-...


2

How do I get the column of the cursor independently of how the selection was made? Let's make it clear: at this point you're already in the normal mode. All you can get is the selection range, not the cursor position at the time it was made. And so col('.') correctly returns the current cursor position, not the previous one. Your confusion is based on an ...


2

See :h t, :h T, :h f, :h F and :h ; For a brief overview: You can jump to the next {char} with f{char} or jump to previous {char} with F{char} You can jump just before the next {char} with t{char} and jump just after the previous {char} with T{char} You can repeat last f, F, t or T with ; All of the above commands take [counts] as an argument. So, you ...


1

I'd take a more experimental approach that @Karl Yngve Lervåg does in his answer: This works by moving the cursor back a word and then forwards again and then seeing if the cursor is in the same place. If it is, then the cursor was on the end of a <word>. Using this technique saves you having to reverse-engineer and reimplement Vim's <word> ...


1

Okay, so in my case disabling thaerkh/vim-workspace solved the issue. If it's the fault of the plugin or a combination of plugins and settings, I don't know. I might investigate that further at a later point and post my findings here. I really love that plugin, it's like vim-obsession, but fully automated...so yeah...disabling it is somewhat annoying. :/ ...


1

I can't tell what machine your using, but on my iMac I had the exact same issue and I've finally fixed it. The solution was to go to preferences and uncheck "Use Core Text renderer". I no longer have the issue and as far as I can tell, there hasn't been any adverse affects from doing this.


1

For your cursor in insert mode and command-line insert mode use the following: set guicursor=i-ci:hor10-Search i-ci : insert and command-line insert hor10: Horizontal bar, 10% of height Search: Yellow, the background color from the "Search" highlight group.


1

:nnoremap <Down> <Nop> :nnoremap <Up> <Nop> does the trick (in conjunction with :set mouse=). Of course, you can't use the arrow keys any more, but if you're using vim, you didn't care anyway. Edit: Need to this in insert mode too, so add the following: :inoremap <Down> <Nop> :inoremap <Up> <Nop>


1

I have been using this in my plugin. let char = matchstr(getline('.')[col('.') - 1 :], '^.')


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