Is it possible with Vim itself or a plugin to display the autocomplete option inline?
If not is there a way to display text in vim without inserting it into the buffer?
You can disable the popup menu (:help popupmenu-completion; it usually displays [a subset of] the available choices) by removing menu[one] from the 'completeopt' option. Then, the first candidate (or longest common part) is directly inserted into the buffer, and <C-n> cycles through candidates at that location. To remove the current suggested completion and return to the original state before the completion, press <C-e>.
That technically still (if only temporarily) inserts the candidate into the buffer, but I think it closely fits what you're asking for, and is built-in. To display text without inserting, there's currently only a (rather crude) workaround of using the :help conceal feature to change the appearance of individual characters (for a static text, matching the exact location in the buffer via \%l and \%c) into something else via matchadd(). However, this only works if there's existing text; it wouldn't work at the end of a line. Currently, a generic overlay feature is being discussed on the the vim_dev mailing list, but it is in very early stages.
Related
Is there a weak visual indicator of all the texts that match the current selection? Similar to most text editors.
How I can achieve the same behavior?
You can certainly build something like that, using an :autocmd that obtains the current selection, and then either using default search highlighting (by modifying register /), or using matchadd() to add separate highlighting (but in contrast to search, that would be window-local by default). To make this robust and non-interfering with common tasks in Vim, that would be much more than a simple one-liner I could post here, though.
I must know, because I've implemented such as part of my SearchHighlighting plugin. With that plugin, this can be enabled via
:SearchAutoHighlighting selection
Because my plugin contains that functionality only as a small part (of more comprehensive search tweaks and additions), also have a look at the following alternatives, which are more targeted to what you're asking for, taken from the alternatives list of my plugin:
highlight_word_under_cursor.vim implements the search
auto-highlighting of the whole and optionally current word.
HiCursorWords highlights the word under the cursor, with
optional delay and limited to certain syntax groups.
Matchmaker highlights the word
under the cursor with matchadd(), not the current search pattern.
vim-cursorword automatically underlines the current word
in the current window (like :SearchAutoHighlighting), but uses :match
instead of search
By default, supertab is inserting a regular tab when the previous character is a space.
I would like to keep this behaviour but with the following exception: if the previous character is a space but the preceding word is import, autocomplete.
For instance (| denotes the cursor position)
from numpy import |<tab> should display completions,
for |<tab> should insert a tab.
I'm aware of g:SuperTabNoCompleteAfter but I'm not sure how to obtain the desired result.
supertab has the ability to consider the preceding text to choose a completion type. You need to teach the plugin about the import context, and configure it to use a custom completion, e.g. user completion (<C-x><C-u>). Then implement the corresponding completion (or find another plugin that already does this), and you should be good.
References
context completion at :help supertab-defaultcompletion
completion contexts at :help supertab-completioncontexts
Writing a custom completion at :help complete-functions.
Vim newbie here.
I would like to be able to create tabs in Vim such that, for example, the tabs are at 4" left and 1.5" right for one type of section, 1.5"/1.5" for another, etc.
I know how to set tab stops, etc. but the trick here is I would like vim to recognize key combinations like shift-enter to go to one kind of formatting, plain enter to go to another kind, etc.
Is this even possible with vim?
TIA
I think you're confusing Vim with a word processor (like Word or Writer). There's no measurement in inches, no left / right margins, etc.
Vim's 'tabstop' option is a multiple of the width of a single space character that a <Tab> character (ASCII 0x09) expands to. This is fixed for the entire buffer (though you could use a set of :autocmds to change it in different parts of a buffer). Vim has no notion of paragraph text styles like a word processor, where you can define different styles. Vim only has a rather primitive :hardcopy command for printing.
If you need elaborate text formatting capabilities, Vim probably is the wrong tool, except if you choose to edit a source code document (like Latex, HTML, or Markdown), which is only compiled into a document (for those, like editing programming languages, it's actually well suited and powerful).
The vimtutor command (see :help vimtutor inside Vim) provides a good introduction to Vim's capabilities.
Check out these screenplay scripts. At least the first one contains custom tab widths as required in the traditional play formats. Perhaps they provide you the right idea on what's possible with Vim:
http://www.vim.org/scripts/script.php?script_id=2447 by Mike Zazaian
http://www.vim.org/scripts/script.php?script_id=1842 by Alex Lance
I wanted to prevent jumping to the first result without user intervention upon ctrl +] (or left click) in vim. In effect, when I click (ctrl +]) on an identifier, it should list all the occurance (like tag search) and should jump to the selection (1,2..) when user input 1,2 etc. I remember using it by setting an option in .vimrc (something like cscope mode), but couldn't recollect now.
Are you looking for tag-matchlist?
Sounds like you want g]. It shows the matching tags.
While I don't think there's an option to make Ctrl+] show a list if there's only one result, if you set cscopetag and set cscopetagorder=0, then you'll search your cscope database which will likely show more results than your tags. (Especially if you're using C++ and have --c++-kinds=+p which will include function prototypes and the implementations -- you almost always have two of the same thing. I use that setting because it's required by omnicppcomplete.)
You still won't get a list if you only have one result. For that, you'd have to make maps to swap Ctrl+] and g].
You can add the following line in .vimrc
map <C-]> g]
One of the nice things about Vim is that one can insert a page feed symbol (Ctrl-L in Insert mode), which delegates the printer to start printing the following on a new page. It shows as ^L in text.
Is it possible to make this symbol show as something else, for example as
----------------- new page here -----------------
so it is somewhat more visible while scrolling through pages of text?
That is, without rebuilding Vim from source.
If you do not use folding extensively when editing those files
containing page feed symbols, you can use one-line folds to mark
them out.
Using the foldexpr option, it is possible to increase the fold level
of the lines that contain page feed symbol. (Herein, for the sake of
efficiency of evaluating foldexpr, I assume that page feed symbols
are always the first characters on their lines.) To achieve the
desired effect of a screen-wide separator, these folds can be made
auto-closable.
The following function configures folding according to the idea
described above. Call it (manually or by means of an autocommand)
to enable page feed symbol folding in the current buffer.
function! FoldPageFeed()
setl foldmethod=expr
setl foldexpr=getline(v:lnum)[0]==\"\\<c-l>\"
setl foldminlines=0
setl foldtext='---\ new\ page\ '
setl foldlevel=0
set foldclose=all
endfunction
Resulting separators appear as the text --- new page followed by
a continuing string of filling characters to the right of the window
(see :help fillchars, under the fold: item).
I don't think you can. There is a non-text highlight group which could help.
Another way (a bit ugly) would be to write some autocommand to expand ^L to ---- new page ---- and vice versa when on InsertLeave, BufRead and BufSave.
Anyway, the answer of your question is no, if you just want to change the display, and probably yes with a nasty plugin.
If it could, I would be uncomfortable knowing that Vim, my heavily trusted tool and friend, could misrepresent a text file.
Of course, you could always execute this command (perhaps as a macro) to do the same thing:
:%s/^L/----------------- new page here -----------------/
If you defined your own highlight group in Vim to be just the ^L symbol, then you could have a custom highlighted background for all lines that contain that character.
It’s not quite a ---- new page here ----, but it would make page breaks easily visible when scrolling through large amounts of text.
I don’t know enough Vim to actually tell you how to set the highlight group though…