Questions tagged [vimrc]
Vim reads initialization commands from a file called vimrc on startup. This can be used to set settings, define functions, execute autocommands, and more.
1,371
questions
0
votes
1answer
29 views
Filetype events in autocmd
To run an autocommand on a python file I can do:
:autocmd FileType python nnoremap ...
However, what 'event' does this run on? Is the event FileType or is Filetype python basically doing a ...
0
votes
0answers
12 views
Paste into search instead to buffer with vim-fuzzyseach?
I’m using this plugin and find it useful with its regrex search and as it’s not updated recently, I find that when I map it to / to replace default function search of vim and then try to paste text ...
0
votes
1answer
16 views
How to ignore helpfiles in a *.txt autocmd
In the following autocmd:
" Default filetype, color if unrecognized (like a text file to write notes)
augroup DefaultFiletype
autocmd!
autocmd BufRead, BufNewFile *.txt set ft=markdown
...
0
votes
1answer
43 views
Two types of method call
What is the difference between the following two ways of calling a function/method in vimscript?
" This seems to always work
call add (events, e)
" This seems to occasionally work
events-&...
0
votes
1answer
23 views
truthiness / boolean comparison in vim
I'm having a hard time understanding why the following equivalence produces two different results:
echom a:events == '*'
echom string(a:events) == '*'
The first one returns 1 while the second one ...
0
votes
0answers
18 views
Understanding some autocmd events
When logging autocommand events, I came across a few ones that seem a bit strange:
User -- seems to be logged very frequently, though the vim help really only mentions "it's not a real event and ...
1
vote
1answer
43 views
How to grab event type
I have the following script to log various events:
augroup EventLogger
autocmd!
autocmd! BufWrite,BufEnter,User * call LogOutput(" getEventType() ")
augroup END
How would I ...
1
vote
1answer
17 views
Suppress output of expression register?
Is it possible to suppress the output of a register? For example, I am using getchar() to 'consume' a character, but I don't need it to return anything. I suppose I could add in a hackish ternary ...
3
votes
1answer
57 views
Understanding EatChar function
In using an iabbrev, vim help gives the following example of how it can be used to ignore the character after typing in the keyword:
Towards the bottom of Abbreviations:
You can even do more ...
0
votes
1answer
43 views
How to get autocmd/iabbrev command to update?
I have the following command which defines an iabbrev:
if !snips_installed
augroup VimLogger
autocmd!
autocmd Filetype vim iabbrev <buffer> log hello!!
augroup END
endif
...
0
votes
0answers
15 views
How to view when events fire? [duplicate]
Is there a verbose mode that shows when each of the various events fire? For example, I'm looking for something where I can use vim in the normal course of operations and see which events are being ...
0
votes
1answer
52 views
How to get last *executed* command
To get the most recent command I can do:
:<ctrl-p>
Or:
:<up>
However, this will also show commands that might have been typed in, but weren't run, for example, I may recently typed in:
:...
0
votes
1answer
37 views
Writing an autocomplete function
I am trying to use the omnicomplete. It is quite simple to use in insert mode, but I'm having a hard time using it from a function. Here is what I have so far:
" Cmd-. to autocomplete tags, ...
0
votes
0answers
27 views
Understanding a filetype regex
How does the following regex (or is it a regex?) work:
au BufWinEnter,BufRead ?* loadview
I believe that ?* makes sure that the filepath has at least one character, but why isn't this then just .. ...
1
vote
1answer
104 views
Scoping an autocommand
Is the following a properly scoped autocommand to work on HTML files?
" Option-space as in html
augroup HTML
autocmd!
autocmd FileType html,htmldjango inoremap <buffer> &...
0
votes
1answer
63 views
Vim regex match between asterisks
What would be the following vim regex to get the word term in:
hello my*term*here
My thought was:
*\zs[^*]\ze*
But it seems like there are some things I need to escape here that aren't working. The ...
1
vote
1answer
179 views
How to 'reset' an option to default
I have set foldtext like this:
set foldtext=NeatFoldText()
Is there a way to:
view what the default value is for a option?
reset option to its default value (without having to exit/re-enter vim)
1
vote
0answers
31 views
Vim folding very slow on large file
I have a large python file (~ 4k loc) and even if I do one manual fold in the code, it seems like all actions take about 3x longer to do, regardless of whether it's in or out of the fold, close or far ...
1
vote
1answer
50 views
Formatting of folds
Is it possible to 'fold at the proper indentation' ? For example, the point in the below is to see conditional flow:
However, with how the above is formatted, it's almost impossible to see visually ...
1
vote
2answers
64 views
Vi: how to use bash from the vi command line?
Suppose I have mapped the following function:
noremap <C-F12> :! bash -c "\
git rev-parse --show-toplevel \
| xargs -I {} \
ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q {}...
1
vote
0answers
22 views
Make nerdtree use the same nerdtree buffer when entering many directories [closed]
In nerdtree, if I enter many directories and then open the file I want, my screen would look like this:
| nerdTree window | Tab1:directory1 | Tab2:directory2 | Tab3: file1 |
Tab1 and Tab2 are not ...
0
votes
1answer
74 views
Organize plugins and .vimrc settings for different filetypes using ftplugins?
I'm new to vim (8.2) and have been learning how to set it up on my computer (Ubuntu 18) for the past few days.
I'd like to configure VIM so that when I open code in different programming languages, ...
0
votes
0answers
27 views
How to 'save' manual folds in vim [duplicate]
Often I will have very long static variables at the top of a file, for example a mapping COUNTRY_TO_ISO. I usually fold those mappings with foldemethod=manual. For example:
However, when I save the ...
0
votes
1answer
71 views
Understanding various ctrl-r variants in vim
I will use ctrl-r quite frequently in insert mode to insert contents of a register, for example, ", %, or any of the [a-z] registers. I've also come across the following in the help:
tag ...
0
votes
1answer
28 views
Trouble with nerdcomment mapping (mapping leader, which maps to itself)
I tried doing the following mapping in NERDCommenter:
nnoremap <leader>/ <leader>c<space>
However this was not consistently working. I verified the ttimeout was a high value, and ...
0
votes
0answers
24 views
Where is vim case-sensitive
Is there a good guide to in which places vim is case-sensitive, which places it isn't, and which places it depends? For example, three examples would be:
Functions, variables seem to be case-...
0
votes
1answer
19 views
Moving and deleting one word at a time using Ctrl + Arrow keys or Ctrl + Del
I want to know if it's possible to delete a whole word or move around one word at a time when in INSERT mode, like in "regular" applications when pressing Ctrl and using the arrow keys jump ...
0
votes
0answers
17 views
Nerdcommenter function to check if line has comment
Without executing an actual editing command, is it possible in NERDCommenter to check to see if a line has a comment or not? I'm sure this is used internally, but I'm thinking about hopefully using ...
2
votes
3answers
78 views
How to determine where formatoptions being overwritten
I have the following in my vimrc file:
:set formatoptions-=cro
However, when I load the vimrc from scratch (i.e., open a new terminal session and start vim with it), it seems to be overwritten ...
0
votes
0answers
30 views
EasyMotion — one OR two chars
It seems that EasyMotion suggestions using two different mapping to find a one- or two-char match. For example, I've mapped a two-char find and it prompts me with:
Search for 2 characters:
However, ...
1
vote
2answers
84 views
Disable search highlighting after running a substitute command
Is it possible to enable hlsearch when running a search (/) but not on : commands? For example, sometimes when doing a replace (on a very narrow range of text) it get distracting when I have a bunch ...
0
votes
1answer
37 views
List of all escape characters as they are displayed in vim
Is there a listing of the various escape codes and how they are represented in vim (and outside I suppose to)? For example:
^M -- newline
^@ -- NIL
etc.
It seems I always have trouble googling ...
2
votes
1answer
41 views
How to receive a python variable from vim [duplicate]
How would I do the following in vim using pyx ?
let abc = 123
pythonx print (abc)
# >>> NameError: name 'abc' is not defined
From above, it looks like python doesn't have access to the vim ...
1
vote
1answer
169 views
python vs pyx in vim
I'm a bit confused as to what the difference is between python and pyx in vim, other than one seems to work and the other does not. For example:
pyx print ("OK")
This works, however, this ...
1
vote
2answers
59 views
Difference between % and g command
What is the difference between doing :% [...] and :g [...]. Does g require a regex to filter out what lines to apply to, or does it apply to all lines if no regex is given? For example:
To insert a &...
4
votes
2answers
119 views
Re-source a file whenever I save a vim file
I would like to set an autocommand that automatically resources the file whenever I save it, as now I am doing something like:
:w | so %
Whenever I save something.
What would be the correct 'event' ...
0
votes
0answers
64 views
Vim syntax highlighting becomes crazy
Some overview and history.
Environment:
OS: Windows 8.1
Emulator: cygwin (mintty)
Terminal: xterm-256
Vim: v8.0 (Cygwin edition)
Vim setup:
Plugin manager: VimPlug
Enabled plugins:
Plug 'scrooloose/...
1
vote
1answer
27 views
When to use set vs let vs & to view variable value
I get a bit confused as to when we access a variable value like this:
:echom &textwidth
" 120
And when it's done like this:
:let a
" a #4
And when it's done like ...
1
vote
2answers
37 views
Why does cursor position on >> and << go to start of line?
Whenever I press << or >> in insert or normal mode, I lose the cursor position, as it always goes back to the start of the line. Is there a setting to fix this?
Here is where I am right ...
0
votes
1answer
53 views
Vim how to print the mode I am in
Let's say I have a visual selection:
How would I print the mode from the commandline? I've tried doing:
:'<,'><C-U>echom mode()
And a few variations of that, but haven't been able to ...
2
votes
1answer
24 views
Mappings for three different visual modes
Is it possible so that each of the different visual modes have different mappings? For example:
visual-block-noremap A BB
visual-line-noremap A CC
visual-normal-noremap A DD
...
0
votes
0answers
14 views
Evaluate function: scoping of variables
I've tried initializing fzf in vim to only take into account a few directories, depending on which machine it is. This is in the vimrc: I've used global variables and then 'unlet' them at the bottom. ...
0
votes
1answer
20 views
Show Dimensions of Current Visual Selection in the Status Bar
After freshly installing vim on a new operating system I noticed that the status bar shows the dimensions of the current selection (2x20).
I have never seen this before and thought it would be a good ...
0
votes
2answers
33 views
Equivalent of visual-block-mode “I” in visual, visual-line mode
In visual-block mode, it's very convenient to press I to be able to modify text at the beginning of the selection(s). What is the equivalent way to do this in normal Visual mode? For example, the ...
0
votes
1answer
69 views
Add a tab before a visual selection
I commonly find myself inserting a tab before some text. This is easy in insert mode, I'll just type a tab, but I would also like to be able to do it in visual mode. The issue is, if I press > in ...
1
vote
2answers
35 views
Open the file from :find in a :tabnew
I have my fuzzy file finder in Vim and it does a pretty good job. But it always opens the file in the current tab. I want my :find to open the resulting file in a new tab.
I know I can :tabnew <...
1
vote
2answers
70 views
Check pending command state
Is it possible to check if a normal mapping/command is being typed?
That's also when the showcmd setting takes effect.
I can't seem to find anything about this in the doc, no autocmd-event nor related ...
0
votes
1answer
118 views
Highlight Particular Words Within Comments
I'm on Ubuntu 18.04, vim-gtk3 8.0.
I'm trying to get gvim to highlight particular words within a comment. For example, take the word 'NOTE'. In a '.c' file: // NOTE(Ryan): ... and a '.sh' file: # ...
0
votes
1answer
50 views
K not working in command in visual mode
I am trying to do the following mapping to open the correct help topic underneath my cursor:
nnoremap K viWlF=hK
This works for the first term:
belloff=all
But not for the second:
splitbelow
For ...
1
vote
1answer
37 views
Silent mapping that automatically redraws — no messages or blank screen
I would like to open a url in vim. Using gx from netrw has been problematic, so I created the following simple mapping:
nnoremap <leader>k !open <C-R><C-F><CR>
This gets the ...