Changing Vi/Vim cursor style on active editor without vimrc - vim

It is not always applicable to prepare such resource/config files as they are out of control (docker, remote, or someone else's system), so I need to do this inside the editor.
With all the information pile made for "add this to vimrc/shell", I am having a difficulty to find a solution.
Is it possible to change the cursor style for the active session/editor without touching any resource/config file? If so, how?
What have I tried:
My attempts lead me to solutions made only for resource/config files for vi/vim and/or shells.
I don't know what exact search terms shall I use to get close to a result if any.
EDIT: Knowing how to "use Vi(m) to edit" files does not necessarily mean/imply you know how to set it up. Settings are some whole new level to learn advanced Vi/m. "Copy-paste" resources show one way, but fail to explain the WHY part.
EDIT: Thanks to commenters, I got the courage to try with more keen eyes and got my solution posted. Better explanations are welcome.

Until today, I believed it is guicursor that changes cursor style. I still do not know what it changes but this explains why I was failing.
Yet, it seems the cursor is directly related to the shell used, and then t_SI, t_EI, and t_SR are responsible to tell the shell which one to use and when.
With "my preference" explained on the right side comments, these 3 are the way to set cursor style.
:let &t_EI="\e[1 q" " normal mode - blinking block on character
:let &t_SI="\e[5 q" " insert mode - blinking bar on left(i) or right(a)
:let &t_SR="\e[2 q" " replace mode - no-blink block on character
The \e part of the commands might need to change depending on the shell. some require it to be \<ESC> as in "\<ESC>[1 q"
The numbers here are: 1/2 for blinking/steady block, 3/4 for blinking/steady underline, and 5/6 for blinking/steady vertical bar
Also, as an extra, if the selection in visual mode is not readable, this should help:
:highlight Visual cterm=reverse ctermbg=none ctermfg=none
#romainl, thanks for "Everything you can do in your vimrc can be done manually in Vim's command-line"

Related

How Do You Split the Neovim Spell Suggestion Window Horizontally?

In Neovim, with the spell checker enabled by set spell, if you hover over a word which is underlined to indicate improper spelling and type z= a window will open which obscures the entirety of your work to list all of the suggested words. I would like for this window to be split horizontally, above, or below the the current buffer so that I can select the properly spelled word while still being able to see my work.
I'm not sure if this is possible. I can't find a setting that would change this functionality.
While not an exact answer to your question, you can just make a remap to display a drop-down list of suggestions like so (see image below - just Tab to traverse the list and press <Esc> to choose and be returned to normal mode):
" move to insert mode with drop-down menu of spelling suggestions for word under the cursor
nnoremap <Leader>sp a<C-X>s
I found that 99% of the time I chose the first spelling suggestion, so I made the mapping to do that and return to normal mode - with no window/drop-down list appearing - hence all you see is the word instantly change.:
" instantly go with first spelling suggestion for word under the cursor
nnoremap <Leader>sp a<C-X>s<Esc>
N.B. The above remaps work better than:
nnoremap <Leader>sp z=1<cr><cr>
since with this one there's a brief flash as the suggestion window appears and is quickly closed again.
Yes, there is an options called spellsuggest. You can use the following setting:
" use only 9 suggestions
set spellsuggest=best,9
After that, the spell suggestion will take only a small portion of the window:

Neovim: How do I set guicursor to make the cursor blink?

The cursor blinking is off by default in Neovim and I want it back. I have tried to apply different arguments to guicursor, but didn't succeed. Since I want it to blink the same way in every mode, I think, I need something with the letter 'a' in it.
Here's what I have tried so far:
:set guicursor=a:blinkwait700-blinkon400-blinkoff250 (I also tried with 'i')
:set guicursor=a:blinkon100 (as the opposite of a:blinkon0 which switches it off)
I've already looked into the help but it didn't help me unfortunately.
Update:
What is peculiar is that :set guicursor=a:blinkon100 enables the blinking in gVim, but not in Neovim.
From neovim 0.2 onwards, setting guicursor does achieve the desired effect:
" Enable blinking together with different cursor shapes for insert/command mode, and cursor highlighting:
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
\,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
\,sm:block-blinkwait175-blinkoff150-blinkon175
Find more by typing :help 'guicursor' from inside nvim.
For more info, see the official wiki
Finally, if you use st, you can patch it to get this working:
https://st.suckless.org/patches/blinking_cursor/
EDIT: I noticed from the comments of the first answer that OP was talking about nvim-qt, for those interested in that, a fix for it has been merged at the beginning of this year.
If you are using the st terminal by Suckless then that does not support cursor blinking I belive, otherwise if your terminal does support it try setting the option let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 in your init.vim file. You could also pass that on the command line such as NVIM_TUI_ENABLE_CURSOR_SHAPE=1 nvim.

GVIM : in /root/.vimrc i have ":colorscheme desert" which worked, but where would i have found this value if someone hadn't told me?

So in GVIM i changed the color-scheme to
desert
but i never understood how to find this line
:colorscheme desert
so i could place it in
/root/.vimrc
file.
where would i have found out about " :colorscheme desert " ?
You could read the help (it is quite long and very detailed)
:h
Opens up to the main help for vim. Under getting started you will see the following. You might have to scroll down a bit (Use Control+f to page down)
usr_toc.txt Table Of Contents
Getting Started
usr_01.txt About the manuals
usr_02.txt The first steps in Vim
usr_03.txt Moving around
usr_04.txt Making small changes
usr_05.txt Set your settings
usr_06.txt Using syntax highlighting
usr_07.txt Editing more than one file
usr_08.txt Splitting windows
usr_09.txt Using the GUI
usr_10.txt Making big changes
usr_11.txt Recovering from a crash
usr_12.txt Clever tricks
It seems the that usr_06.txt is related to syntax highlighting so that might be worth reading. So type :h usr_06.txt or <c-]> (Control+]) to jump to that file when your cursor is on top of it.
Once you are in there you can look at the table of contents again.
06.1 Switching it on
06.2 No or wrong colors?
06.3 Different colors
06.4 With colors or without colors
06.5 Printing with colors
06.6 Further reading
Different colors seems to be what you want. So type :h 06.3 (or <c-]>) and the first paragraph talks about changing the colorscheme.
Control+] jumps to a tag and is talked about in :h tagsrch.txt (And on the line "Jump to a subject" immediately as you open :h)
The help have an auto completion feature.
So you can type, :help color followed by Ctrl+d. You won't necessary find the good entry right of the bat but it should put you on the right track. It would have shown you a colorscheme option.
An alternative is to use :helpgrep. :helpgrep color should give you a list of help file wich contains the string color.
On Debian Linux, it's part of the the vim-runtime package and sits in /usr/share/vim/vim73/colors/desert.vim. You can list contents of this direcory for more options. I don't think they have hard-coded color schemes in vim itself, so vim help will not list them for you.
I suppose like most other vim plugins, customized color schemes can also be put in ~/.vim directory.

Vim function hints for C

I'm trying to achieve something simple, usually called "function hints". For example, scintilla-based editors have it:
You type a name, and just get the prototype. There are a few problems with that in vim:
You have to rebuild the ctags to keep it up to date
You can't type C-X C-O after the (, you'll just get "Pattern not found"
You can't type C-X C-O in normal mode, the cursor will just jump around
You get the annoying preview window at the top
I've tried a few plugins; most of them mess things up even more [^1].Can anyone recommend a simple way to get just that ? A simple rectangle containing the function prototype and nothing more.
[^1] It's really mind-numbing how idiotic some of these plugins are. One plugin (I won't mention it) actually contained in the .vim file a list of functions from libc.
ctags for autocompletion is a mess. I suggest you try a compiler based plugin such as clang-complete or gcc-sense (haven't tried this one). Advantages are:
more accuracy as what they do is pretty much compiling
compile errors are marked on the fly over the source code
You have to rebuild the ctags to keep it up to date
you don't need to deal with ctags (they are still useful to jump around though)
You can't type C-X C-O after the (, you'll just get "Pattern not found"
what would you expect?
You can't type C-X C-O in normal mode, the cursor will just jump around
you can always remap that sequence if you think it's a frequent mistake (something like nnoremap <C-x><C-o> a<C-x><C-o>)
You get the annoying preview window at the top
You can disable this by removing preview fromcompleteopt option. see :help completeopt
I'm using the following setup:
clang-complete for completion
supertab to complete with tab key
ultisnips for function signature placeholders. (also works with snipmate)
and some vimrc settings:
set pumheight=10 " so the complete menu doesn't get too big
set completeopt=menu,longest " menu, menuone, longest and preview
let g:SuperTabDefaultCompletionType='context'
let g:clang_complete_auto=0 " I can start the autocompletion myself, thanks..
let g:clang_snippets=1 " use a snippet engine for placeholders
let g:clang_snippets_engine='ultisnips'
let g:clang_auto_select=2 " automatically select and insert the first match
Enjoy!
Try to use eclim (plugin for integration with Eclipse).
This solution is overheaded a lot but it works in all cases.

Is there a way to emulate ReSharper's "extend selection" feature in Vim?

ReSharper has a nice feature called "extend selection": by pressing CTRL+W (I think this is the default) repeatedly, you select more and more from your current caret location. First it's a word, then more and more words, a line, inner then outer block of lines (for example an if-block), then a function, etc...
Basically, by pressing the key combination repeatedly, you can end up selecting the entire file. I'm sure at least some of you will be familiar with it.
I have just started learning all the intricacies of vim and I don't have enough experience to see how something like this could be implemented in Vim (although I assume it's possible). So my question is meant for Vim gurus out there: can this be done and how?
Update: a bit of a background story. I've been talking to my ex-boss about all the benefits of Vim, and he thinks it's all great. His only question/problem was: does it have "extend selection"? My question so far has been no. So, if someone knows the answer, I'll finally win a discussion :P (and maybe create a new Vim convert:-))
I had a quick go at this problem. It doesn't work as is. Feel Free to make edits and post on the vim wiki or as a plugin if you get it refined.
chances are you'd want to make a g:resharp_list for each language (eg. one for paranthesised languages, etc.)
All that is needed is a marker for the original cursor position :he markers and a timeout autocommand that resets the index.
"resharp emulator
"TODO this needs a marker
"also c-w is bad mapping as it has a lag with all the other-
"window mappings
"
let g:resharp_index = 0
let g:resharp_select = ['iw', 'is', 'ip', 'ggVG']
func! ResharpSelect()
if g:resharp_index >= len (g:resharp_select)
let g:resharp_index = 0
endif
exe "norm \<esc>v" . g:resharp_select[g:resharp_index]
let g:resharp_index = g:resharp_index + 1
endfun
nnoremap <c-w> :call ResharpSelect()<cr>
vnoremap <c-w> :call ResharpSelect()<cr>
"Something to reset on timeout. TODO this doesn't work
au CursorHold :let g:resharp_index = 0<cr>
The answer is yes. Once in Visual mode you can use all the regular navigation methods as well as some extra ones.
Some of my favourites? First hit v while in normal mode to get to visual mode then hit:
iw - to select the inner word. Great for selecting a word while excluding surrounding braces or quotes
w - hit multiple times to keep selecting each subsequent word.
b - select wordwise backwords
^ - select all from current position to beginning of text on line
$ - select all from current position to end of line
I'm sure others here could add to this list as well. Oh and don't forget Visual Block mode C-v try it out in vim with the above commands it works in two dimensions :-)
If you're talking about Vim (and you should be :-), you can start marking text with the v command, then you have all the standard cursor movement commands (and, as you know, there are a lot of them) which will extend the selection, as well as moving the cursor.
Then you just do whatever you want with the selected text.
See here for the gory details.
One would need to write a function that would save the current selection, then try increasingly wide selections, until the new selection exceeds the saved one or selects all text. Some possible selections are:
viW - select word
vis - select sentence
vip - select paragraph
viB - select text within the innermost brackets
v2iB - select text within the next most innermost brackets
ggVG - select all text
I think Jeremy Wall's heading in the right direction. And to get a little further in that direction, you might look at the "surround.vim" script from Tim Pope. A good description is available on github. Or, if you'd rather, get it from vim.org. It'll probably help you do some of the things you'd like to do, though it doesn't seem to have a feature for say, simply selecting within a tag. Let me know if I'm wrong.
Ultimately, what you'd really like is a hierarchy of enclosing text-objects. You should read up on text-objects if you haven't. A nice overview is here. Note that you can grab multiple objects in one go using counts, or do this iteratively (try vawasap}}} from normal mode).
You can also get scripts which define other text-objects, like this one that uses indentation to define a text-object. It'll work for many languages if you're formatting according to common standards, and guaranteed for python.
One annoyance is that the cursor ends up at the end of the visual block, so, for example, you can't easily select everything between some ()'s, then get the function name that precedes them...
...BUT, I just found in this post that you can change this behavior with o. Cool!
I suspect you'll find yourself more efficient being able to skip over intermediate selections in the long run.
Anyway, I'll be curious to see if anyone else comes up with a more general solution as well!
In Rider [on a Mac with VS Mac bindings with IdeaVim], I bind:
Ctrl+= to Extend Selection
Ctrl+- to Shrink Selection
Doesn't clash with any other bindings of consequence and doesn't require a v for mode switching, and easier than Cmd+Option+-> and Cmd+Option+<-
Putting it here as I always hit this question with any Rider Vim selection searches. If I get enough harassment, I'll create a self-answered "How to use Extend Selection with Rider Vim mode".

Resources