149

You can press {count}Ctrl-G: {count}CTRL-G Like CTRL-G, but prints the current file name with full path. If the count is higher than 1 the current buffer number is also given. Pressing 1 followed by Ctrl+G shows the full path of the current file. If {count} is higher than 1, the buffer name will also be shown. ...


56

Register % contains the name of the current file. The following commands could be entered to display the information shown: :echo @% |" directory/name of file :echo expand('%:t') |" name of file ('tail') :echo expand('%:p') |" full path :echo expand('%:p:h') |" directory containing file ('head') If all that is wanted is to display ...


45

You can use %b or %B in statusline or rulerformat. From :help statusline: b N Value of character under cursor. B N As above, in hexadecimal. For example: set statusline=%b\ %B Gives you: 8984 2318 Another way is to use ga or the :ascii command. From :help ga: :as[cii] or ga :as :ascii ga ...


22

You can use :!ls %:p to get the full path to the current file. Depending on the ex context, % will either mean the contents of the file or the filename. When shelling out, it represents the file path relative to the current directory. The command '%:p' will add the full path filename modifier to %. There are a few other interesting filename modifiers such ...


21

You can change it in your vimrc. The currently focused window is highlight group Statusline, other windows are StatuslineNC. Example for terminal Vim: hi StatusLine ctermfg=8 ctermbg=2 cterm=NONE hi StatusLineNC ctermfg=2 ctermbg=8 cterm=NONE For the GUI, use guifg and guibg.


15

:goto 2356 jumps to the 2356th byte in the buffer. Use the %o field in 'statusline' or 'rulerformat' to display the byte number of the character under your cursor. Use %O to display the value in hexadecimal format. Reference: :help :goto :help 'statusline' :help 'rulerformat'


12

The problem is that many (all?) colorschemes will clear all highlights with highlight clear before setting their own colours. For example from /usr/share/vim/vim74/colors/peachpuff.vim: " First remove all existing highlighting. set background=light hi clear if exists("syntax_on") syntax reset endif let colors_name = "peachpuff" hi Normal guibg=PeachPuff ...


8

Values used in :set are strings. See :h set-args: :set-args E487 E521 :se[t] {option}={value} or :se[t] {option}:{value} Set string or number option to {value}. ... White space between {option} and '=' is allowed and ...


8

This is not currently possible in Vim. Internally, :echomsg is implemented as :execute, except that when invoked as :echomsg the result of execution is displayed with the attribute of the last :echohl and saved to the message list (reference src/eval.c functions ex_echohl and ex_execute), which is how you get any color on a saved message. The actual ...


7

One can see the current working directory with :pwd. Of course, this is only the directory, and not the filename. To get the working directory and filename, we can use the special register %, which contains information about the current file. If you use :echo @%, you'll get the directory and filename of the current file. If you use :echo expand('%:p'), you'...


7

No, it's impossible to hide the command-line. -- EDIT -- You can prevent Vim from echoing "filename" XXXL, XXXC when editing a file by prepending silent to e: :silent e foo


7

From the airline-FAQ: How do i get rid of the default mode indicator? Add set noshowmode to your vimrc.


6

From :help 'statusline': The result can contain %{} items that will be evaluated too. So if you write an expression inside %{} and add it to your 'statusline' option, it should be evaluated and the result displayed. Here, your expression would be: &iminsert==1?'GREEK':'LATIN' The syntax of this expression is described in :help expr1; if the test ...


6

You could try the following code: function! SubName() abort let prev_sub_line_num = search('subroutine ', 'bcnW') return matchstr(getline(prev_sub_line_num), 'subroutine \zs\w\+') endfunction set stl+=%{SubName()} let prev_sub_line_num = search('subroutine ', 'bcnW') Call the search() function to look for the pattern subroutine. In the 2nd ...


6

So following the idea I suggested in comments here is what I've come up with: First let's demonstrate it with a gif (I'm not sure why the cursor leaves this ugly mark): The idea is to: Set the foldmethod to indent because it works well with python. (But I guess using marker or manual would work too) Open a split which will contain the "context information"...


6

You got an answer already. However, for your specific case, you don't need the system() call, since you want an environment variable to be expanded. In that case you could simply use echo $EDITOR or in case of a function call do: function! GetEditor() return $EDITOR endfunction Now, suppose you still need a system() function call, because you need to ...


6

When you use the += operator, you actually ask vim to append some new values to the statusline variable. When you first open Vim statusline is set to an emtpy value so adding %.35f to it give you the expected behavior. However when you source your config again, nothing empties the variable so you keep adding duplicate values to it. Thus you probably want to ...


5

What you call the "mode line" is actually called "command line". You can't move it around. You can't disable it.


5

%c -- column number, i.e. byte number. %v and %V -- virtual column number, i.e. column number on your screen. So what is the difference between the actual and virtual column number? The answer is, that when using tabs, the virtual column number is an approximation of your current column number as if you were using spaces instead of tabs. *This answer is an ...


5

There are 2 ways to change the value of an option, with the :set or :let command. :set myoption=myvalue :setlocal mylocaloption=mylocalvalue Or: :let &myoption = 'myvalue' :let &l:mylocaloption = 'mylocalvalue' When you use the :set command, the value you assign to the option can contain characters which have a special meaning on the command-line....


5

Your statusline depends on statusline for "what" to display on the status line. See :h statusline But you also have an option to control "when" to display the status line: From :h laststatus: The value of this option influences when the last window will have a status line: 0: never 1: only if there are at least two windows 2: always So in ...


5

If you use the vim-airline Plugin together with the vim-anzu Plugin, the search statistics are already displayed in the statusline. See the below screenshot (and note the [1/3])


5

The most general improvements I can give are to avoid the long ?: and to make use of the get function on dictionaries. For example, I would write return get(g:, 'git_branch', '') For the if, use a plain if let l:is_git_dir = trim(system('git rev-parse --in-inside-work-tree')) if l:is_git_dir is# 'true' let g:git_branch = trim(system('git rev-parse --...


4

This is controlled with the shortmess option. In particular, you probably want to set the O (upper-case o) flag with set shortmess+=O. O message for reading a file overwrites any previous message. Also for quickfix message (e.g., ":cn"). Note that this is included in the Vim default, which is filnxtToO. So I think you either added this to your ...


4

There are aleady better answers, but if (for some reason) you wanted to use the shell to get the full path of the file (this is more useful if you're going to perform some other operation on the file with the shell), on a Unix-like system you could run: :!realpath % or: :'<,'>!realpath % to insert the path into the document over the current ...


4

If you're really determined to do it, it can be done. A mostly accurate translation of the source function might look like this: function! Stl_P() let above = line('w0') - 1 let below = line('$') - line('w$') if below <= 0 return above ? 'Bot' : 'All' elseif above <= 0 return 'Top' else return printf('%2d%%'...


4

The problem is that there are various scenarios in which Vim will reload the colour scheme such as using :colorscheme or :syntax enable. Colour schemes should always start with :highlight clear to clear all existing highlight groups. Why? See what happens when you do: :highlight Test ctermfg=red :highlight Test ctermbg=blue What is Test now set to? To ...


4

The ^@ is a NUL character, 0x00, which Vim uses in certain cases to store a newline, 0x0a. Unix commands usually terminate their output with a newline, and the system() function captures that newline in the output of your echo command. To get rid of that terminating newline, use substitute(): let s:name = substitute(system("echo $EDITOR"), '\n', '', 'g') ...


4

This information comes from the function get_rel_pos from the buffer.c of the Vim source file. What it does, it calculates the window position of the current view with respect to the complete buffer content. The function itself is rather short, as you can see: What it does, it checks the line above the current top window line and below the current bottom ...


4

0- +1 to D. Ben Knoble suggestions. Regarding pure vim-scripting 1- Never define autocommands globally. Prefer to define them in their own group, and when filling the group, start by clearing it. This way, the related snippet of code can be re-executed, which you'll will want when you'll be working on your script aug MyGitBranch au! au BufEnter * call ...


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